在 WooCommerce 中的价格显示之前添加自定义文本 [英] Add a custom text before the price display in WooCommerce

查看:53
本文介绍了在 WooCommerce 中的价格显示之前添加自定义文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In WooCommerce, I'm using this code to put a text in the price display:

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' );

页面显示为 "$99,99 TEXT"

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

感谢您的帮助.

推荐答案

你只需要把价格和文字倒过来:

You have just to inverted the price and the text:

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;
}

这应该如您所愿……

这篇关于在 WooCommerce 中的价格显示之前添加自定义文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆