在Woocommerce中将自定义文本添加到变动价格 [英] Adding custom text to the variation price in Woocommerce

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

问题描述

我以为这会很容易,但是我被困住了.我要做的就是在产品页面上的变化价格之后分别添加一个词.我找到的解决方案将其添加到类别页面和产品页面的两个位置.

I thought this would have been easy, but I am stuck. All I am trying to do is add the word each after the variation price on a product page. The solution I have found adds it on the category page and in two places on the product page.

代码是:

 /*  Adds a text Each - after price */
function change_product_price( $price ) {
    $price .= ' each';
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'change_product_price' );

从上面的图片中,我只需要将每个添加到价格上的添加到购物车按钮上方,而不需要其他的价格,如上面的照片中的划线部分.

From the picture above, I only need the each added to the price above the add to cart button, but not the other pacles like the crossed out section in the photo above.

感谢您提供的任何指导.

Thank you for any guidance you can provide.

推荐答案

以下代码将在产品变化价格后添加后缀:

The following code will add a suffix to the product variations price:

add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3 );
function variation_price_custom_suffix( $variation_data, $product, $variation ) {
    $variation_data['price_html'] .= ' <span class="price-suffix">' . __("each", "woocommerce") . '</span>';

    return $variation_data;
}

代码进入您的活动子主题(活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (active theme). Tested and works.

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

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