This topic is: resolved
-
Hi,
I have a piece of code that I added with Code Snippet that changes the standard price range (eg. $10-$30) of variable products to just the price of the variant itself (eg. $15 for red colour). The code is as follows:
add_action( 'woocommerce_before_single_product', 'check_if_variable_first' ); function check_if_variable_first(){ if ( is_product() ) { global $post; $product = wc_get_product( $post->ID ); if ( $product->is_type( 'variable' ) ) { // removing the price of variable products remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); // Change location of add_action( 'woocommerce_single_product_summary', 'custom_wc_template_single_price', 10 ); function custom_wc_template_single_price(){ global $product; // Variable product only if($product->is_type('variable')): // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); // Sale Price $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); sort( $prices ); $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice && $product->is_on_sale() ) { $price = '
' . $saleprice . $product->get_price_suffix() . '<ins>' . $price . $product->get_price_suffix() . '</ins>'; } ?> <style> div.woocommerce-variation-price, div.woocommerce-variation-availability, div.hidden-variable-price { height: 0px !important; overflow:hidden; position:relative; line-height: 0px !important; font-size: 0% !important; } </style> <script> jQuery(document).ready(function($) { $('input.variation_id').change( function(){ //Correct bug, I put 0 if( 0 != $('input.variation_id').val()){ $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append(''+$('div.woocommerce-variation-availability').html()+'
'); console.log($('input.variation_id').val()); } else { $('p.price').html($('div.hidden-variable-price').html()); if($('p.availability')) $('p.availability').remove(); console.log('NULL'); } }); }); </script> <?php echo ''.$price.'
'.$price.''; endif; } } } } //En caso de no diponer stock de una de las variaciones, la desactivamos add_filter( 'woocommerce_variation_is_active', 'desactivar_variaciones_sin_stock', 10, 2 ); function desactivar_variaciones_sin_stock( $is_active, $variation ) { if ( ! $variation->is_in_stock() ) return false; return $is_active; }It works on normal WooCommerce but after I bought and installed the Page Builder plugin, it does not work anymore. How can I fix this?
Thanks!