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