How to Modify WooCommerce Variable Product Price Range

Author: 

Shamina Roshni


Description: 

Suppose, you are surfing different online stores for buying a new hoody. Luckily, you have found the one you have been looking for. So, what’s the next thing you will notice? The PRICE!

Now, if you see a price range higher than your budget, you will hesitate to buy that product. The seller provided a range because the product has variations. For example, the hoody you liked has 2 colors red and black. The seller is charging more for the red one. Some buyers like you might want to buy the black one, but they would be confused because of the price range. Unless you select the color, you will never know the actual price!

When you are a store owner, you can guess a similar scenario using reverse psychology. So, when you place a higher range, customers will surely bounce from your product page and you lose your potential sales.

 




Kind:

PHP, woocommerce


PHP:

function wc_varb_price_range( $wcv_price, $product ) {

$prefix = sprintf('%s : ', __('Vanaf', 'wcvp_range'));

$wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
$wcv_min_sale_price = $product->get_variation_sale_price( 'min', true );
$wcv_max_price = $product->get_variation_price( 'max', true );
$wcv_min_price = $product->get_variation_price( 'min', true );

$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
wc_price( $wcv_reg_min_price ) :
'' . wc_price( $wcv_reg_min_price ) . '' . '' . wc_price( $wcv_min_sale_price ) . '';

return ( $wcv_min_price == $wcv_max_price ) ?
$wcv_price:
sprintf('%s%s', $prefix, $wcv_price);
}

add_filter( 'woocommerce_variable_sale_price_html', 'wc_varb_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_varb_price_range', 10, 2 );


URL: