Replace WooCommerce variable products price range with the min price

女生的网名这么多〃 提交于 2019-12-04 05:30:40

问题


With my Woocommerce webshop, I sell services using variable products and I would like to replace the price range by "Prices starting at" ++ the lowest price.

I have tried changing the code in many ways but I didn't get it working.

How can I hide price range in Woocommerce and show only the lowest one on variable products?


回答1:


The following will replace the variable price range by "Prices starting at" with the lowest price:

add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_range', 10, 2 );
function custom_variable_price_range( $price_html, $product ) {

    $prefix     = __('Prices starting at', 'woocommerce');
    $min_price  = $product->get_variation_price( 'min', true );

    return $prefix . ' ' . wc_price( $min_price );
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Related: Replace WooCommerce variable products price range with 'Up to' and the max price



来源:https://stackoverflow.com/questions/54698434/replace-woocommerce-variable-products-price-range-with-the-min-price

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!