Range prices in varible products
-
Hi!
I want to disable range prices for variable products, but after install the plugin my shortocde for this doesn′t work.
This plugin changes something???
Thanks
-
Hello there,
yes, the price is modified by the plugin in order to show the /days or /months suffix.
You could try to modify your shortcode in order to use a different priority.I used to use this code and I don’t know what variable change to make works.
//Hide Price Range for WooCommerce Variable Products
add_filter( ‘woocommerce_variable_sale_price_html’,
‘lw_variable_product_price’, 10, 2 );
add_filter( ‘woocommerce_variable_price_html’,
‘lw_variable_product_price’, 10, 2 );function lw_variable_product_price( $v_price, $v_product ) {
// Product Price
$prod_prices = array( $v_product->get_variation_price( ‘min’, true ),
$v_product->get_variation_price( ‘max’, true ) );
$prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__(‘%1$s’, ‘woocommerce’),
wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] );// Regular Price
$regular_prices = array( $v_product->get_variation_regular_price( ‘min’, true ),
$v_product->get_variation_regular_price( ‘max’, true ) );
sort( $regular_prices );
$regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__(‘%1$s’,’woocommerce’)
, wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] );if ( $prod_price !== $regular_price ) {
$prod_price = ‘‘.$regular_price.$v_product->get_price_suffix() . ‘‘ .
$prod_price . $v_product->get_price_suffix() . ‘‘;
}
return $prod_price;
}Hi @davidmtz ,
Could you try modifying your code for the following?
//Hide Price Range for WooCommerce Variable Products add_filter( 'woocommerce_variable_sale_price_html', 'lw_variable_product_price', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'lw_variable_product_price', 10, 2 ); function lw_variable_product_price( $v_price, $v_product ) { // Product Price $prod_prices = array( $v_product->get_variation_price( 'min', true ), $v_product->get_variation_price( 'max', true ) ); $prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(('%1$s', 'woocommerce'), wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] ); // Regular Price $regular_prices = array( $v_product->get_variation_regular_price( 'min', true ), $v_product->get_variation_regular_price( 'max', true ) ); sort( $regular_prices ); $regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(('%1$s','woocommerce'), wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] ); if ( $prod_price !== $regular_price ) { $prod_price = ''.$regular_price.$v_product->get_price_suffix() . ' ' . $prod_price . $v_product->get_price_suffix() . ''; } return $prod_price; }
Sadly this code send me next error in line 1:
syntax error, unexpected ‘/’, expecting end of file
Hi @davidmtz,
I tried this code and it works without errors, maybe the problem is in another area of ??your functions.php file where you are adding the code.
I send you the code again in case there was an error
//Hide Price Range for WooCommerce Variable Products add_filter( 'woocommerce_variable_sale_price_html', 'lw_variable_product_price', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'lw_variable_product_price', 10, 2 ); function lw_variable_product_price( $v_price, $v_product ) { // Product Price $prod_prices = array( $v_product->get_variation_price( 'min', true ), $v_product->get_variation_price( 'max', true ) ); $prod_price = $prod_prices[0]!==$prod_prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price( $prod_prices[0] ) ) : wc_price( $prod_prices[0] ); // Regular Price $regular_prices = array( $v_product->get_variation_regular_price( 'min', true ), $v_product->get_variation_regular_price( 'max', true ) ); sort( $regular_prices ); $regular_price = $regular_prices[0]!==$regular_prices[1] ? sprintf(__('%1$s','woocommerce'), wc_price( $regular_prices[0] ) ) : wc_price( $regular_prices[0] ); if ( $prod_price !== $regular_price ) { $prod_price = ''.$regular_price.$v_product->get_price_suffix() . ' ' . $prod_price . $v_product->get_price_suffix() . ''; } return $prod_price; }
- The topic ‘Range prices in varible products’ is closed to new replies.