在woocommerce产品页面中添加价格后的客户文字

时间:2017-11-14 16:01:50

标签: php wordpress

我正在研究电子商务网站的主题。我想展示" B"在woocommerce产品页面的价格之后。 该页面显示为"$99,99"
我想让它显示如下:"$99,99 TEXT"

我有它的代码:

function change_product_price( $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' );

现在我想知道在woo-commerce目录中添加代码的位置。任何帮助,将不胜感激。

感谢

2 个答案:

答案 0 :(得分:2)

您在add_filter中调用的函数的名称与实际函数的名称不同。看来您忘记了函数名中的_display

在下面的代码中,该函数的名称为cw_change_product_price_display,在cw_change_product_price_display中调用了add_filter

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

答案 1 :(得分:1)

将此代码添加到主题的functions.php,最后

function change_product_price( $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' );