【问题标题】:WooCommerce: Show price suffix only on single product Page - Not for related productsWooCommerce:仅在单个产品页面上显示价格后缀 - 不适用于相关产品
【发布时间】:2020-06-12 19:07:07
【问题描述】:

我试图在产品页面上仅显示价格后的后缀。我不想在其他任何地方显示这个后缀。

我没有使用税费设置,因为我的价格包含所有费用,并且我不想使用税费选项使设置复杂化。

在此答案https://stackoverflow.com/a/57218980/8044005

上使用代码 sn-p 中的 first route

我的代码是:

## Add suffix to price on Product Page
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ) {
    if(is_singular('product')) {
        $price = $price . ' <span class="make-me-small"> Inclusive of all taxes</span>';
    }
    return apply_filters( 'woocommerce_get_price', $price );
}
##-End of above code - Start new code below

但是,此代码 sn-p 显示了相关产品中的后缀。

我应该做哪些更改来防止在相关产品中显示后缀

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce


    【解决方案1】:

    https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/

    相关产品由“循环”生成。有时您可能只想在单个产品页面(不包括相关页面)上使用 PHP,反之亦然。

    function custom_price_suffix( $price, $product ) {
        global $woocommerce_loop;
    
        if( is_product() && !$woocommerce_loop['name'] == 'related' ) {
            $price = $price . ' <span class="make-me-small"> Inclusive of all taxes</span>';
        }
        //return $price;
        return apply_filters( 'woocommerce_get_price', $price );
    }
    add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
    

    【讨论】:

      猜你喜欢
      • 2019-12-04
      • 2021-02-09
      • 2015-12-30
      • 1970-01-01
      • 2020-11-05
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多