0

I need to change the variation of a woocommerce product in jQuery.

i have this function changeColorVar(selectbox,color)

this function should change the color of the current selectbox and update the woocommerce variable price, but it doesn't update the price, here is the function body

 function changeColVar(selectbox,color){

    $form = $(".variations_form"); //GETTING THE FORM

    $form.trigger( 'woocommerce_variation_select_focusin' ); //that we've focused in 
    $(selectbox).find( 'option' ).each(function() {
      $(this)
        .prop('selected', $(this).val() == color); //Setting the selectbox value
    });
    $(selectbox).trigger('change'); //Trying to call woocommerce "check_variations" to update price


}      

aprec any help!

I'm editing the content-product page in woocommerce, I'm showing the variations and add to cart button using this

 if( $product->is_type( 'variable' ) ) {
                              do_action('woocommerce_variable_add_to_cart');
                             }
                             else {
                                 do_action('woocommerce_add_to_cart');
                             }

I'm also displaying a button in the single product page that does changeColVar function. when I click on this button i want to change one attributes ("#pa_color") to "Red" value automatically, and updating the price.

I found last this answer but I haven't solved my problem. WooCommerce: trigger event after change of variation

Andrea Loda
  • 71
  • 11
  • Your question code is incomplete (so unclear) and then not answerable. Please note that *"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error **and the shortest code necessary to reproduce it in the question itself**"*. – LoicTheAztec Oct 10 '18 at 17:15
  • @LoicTheAztec i edited my question – Andrea Loda Oct 10 '18 at 22:56
  • Sorry but it still not testable… How can we reproduce your issue with the provided code and explanations? Nobody can guess things by magic. – LoicTheAztec Oct 10 '18 at 23:07

0 Answers0