如何在 WooCommerce 购物车和结帐页面中添加后缀文本到价格?

问题描述 投票:0回答:4

我需要在购物车页面和结帐页面中显示的价格(小计、总计...)后添加文字提及。

我知道如何在单页和商店页面上执行此操作,但不知道如何在其他页面上执行此操作。我唯一找到的是这段代码,但它不起作用。

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
  $text = 'lorem';
  return $price . $text;
}
woocommerce suffix
4个回答
5
投票

我找到了答案,但它不会增加运费:

add_filter( 'woocommerce_cart_item_price', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_item_subtotal', 'kd_custom_price_message' );  
add_filter( 'woocommerce_cart_subtotal', 'kd_custom_price_message' );  
add_filter( 'woocommerce_cart_total', 'kd_custom_price_message' ); 

function kd_custom_price_message( $price ) {
    $afterPriceSymbol = ' TTC';
    return $price . $afterPriceSymbol;
}

1
投票

运费价格:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'kd_custom_price_message' );

0
投票
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
function cw_change_product_price_display( $price ) {
    $text = __(' X ');
    return $price . ' ' . $text;
}

对于购物车页面,您可以尝试此代码。


0
投票

很棒的代码。谢谢。我只需要一点帮助。是否可以只为某个产品设置这个后缀?

© www.soinside.com 2019 - 2024. All rights reserved.