首页 > 解决方案 > (Woocommerce)在除购物车和结帐页面之外的所有地方都显示价格

问题描述

我想在价格产品类别/单品页面之前添加一些内容。我以这段代码为例:

function cw_change_product_price_display( $price ) {
    $price .= ' Starts At';
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );

但它显示为“RM49.00 Starts At”,我需要在价格之前显示这些词。我如何实现这一目标?我真的需要这方面的帮助。

标签: phphtmlwordpresswoocommerce

解决方案


您只需要在价格 html 之前附加它。您可以检查单个产品页面使用is_product()和类别页面使用is_product_category()

    function cw_change_product_price_display( $price ) {

        if ( is_product() || is_product_category() ) {
           return 'Starts At ' . $price;
        }

    return $price;
   }

推荐阅读