在Woocommerce中将自定义文本添加到变动价格

编程入门 行业动态 更新时间:2024-10-07 20:25:04
本文介绍了在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中将自定义文本添加到变动价格

本文发布于:2023-11-11 08:38:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   中将   变动   文本   价格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!