Hide Price Range for Variable Products in WooCommerce

cách ẩn phạm vi giá sản phẩm biến thể

This content explains how to hide price ranges for variation products in WooCommerce, as by default, the prices for variant products are displayed in ranges. The tutorial provides a simple code snippet to achieve this customization, allowing the display of the product prices when only the respective variant is selected. By adding the code snippet provided in the tutorial, your variant products will only display the lowest price, with the exact price for each variant appearing above the Add to Cart button when selected. This customization can make your store operate more effectively. You can follow the basic WordPress section for more knowledge.

Are you struggling to hide price ranges for variant products in WooCommerce? By default, WooCommerce displays prices for variant products in ranges, but some users prefer to show the exact price for each variant. Unfortunately, WooCommerce doesn’t offer a built-in solution for this issue. But don’t worry, we’ve got you covered! In this tutorial, we will guide you on how to hide price ranges in WooCommerce variation products with a simple code snippet.

To achieve this, you can use the following code snippet:

function wc_varb_price_range( $wcv_price, $product ) {
    $wcv_min_price = $product->get_variation_regular_price( 'min', true );
    $wcv_max_price = $product->get_variation_regular_price( 'max', true );
    $prefix = sprintf( '%s', wc_price( $wcv_min_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 );

With this code snippet, your variant products will only display the lowest price, and the exact price for each variant will appear above the "Add to Cart" button when selected.

We hope that by implementing this change, your store will operate more effectively. If you found this tutorial helpful, consider following the basic WordPress section for more informative content. Stay up to date with the latest articles by following our fan page: Hocwordpress Group.

See also  Admin bar outside Front-end in WordPress.

Have any questions or feedback? Feel free to drop them in the comments below. Happy coding!

Rate this post

Related posts