在 WooCommerce 中的价格显示之前添加自定义文本

Ema*_*ira 2 php wordpress product woocommerce price

在 WooCommerce 中,我使用此代码在价格显示中放置文本:

function cw_change_product_price_display( $price ) {
    $price .= ' TEXT';
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
Run Code Online (Sandbox Code Playgroud)

页面显示如下 "$99,99 TEXT"

我想让它显示如下: "TEXT $99,99"

感谢您的帮助。

Loi*_*tec 5

您只需反转价格和文本:

add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
function cw_change_product_price_display( $price ) {
    // Your additional text in a translatable string
    $text = __('TEXT');

    // returning the text before the price
    return $text . ' ' . $price;
}
Run Code Online (Sandbox Code Playgroud)

这应该像你期望的那样工作......

  • **谢谢,我问了一个新问题** /sf/ask/5392223161/ Different-sections (2认同)