Get selected variation price in jQuery on Woocommerce Variable products

后端 未结 2 1813
时光取名叫无心
时光取名叫无心 2020-12-10 08:37

How do I use the variation id to find the variations price using javascript? This is what I\'ve got so far. I\'ve got the variations ID, but i can\'t figure it out. I\'ve be

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 09:16

    Updated code to update the class showing the select var price..

    add_action( 'woocommerce_before_add_to_cart_quantity', 'func_option_valgt' );
    function func_option_valgt() {
        global $product;
    
        if ( $product->is_type('variable') ) {
            $variations_data =[]; // Initializing
    
            // Loop through variations data
            foreach($product->get_available_variations() as $variation ) {
                // Set for each variation ID the corresponding price in the data array (to be used in jQuery)
                $variations_data[$variation['variation_id']] = $variation['display_price'];
            }
            ?>
            
            

提交回复
热议问题