How to add text underneath WooCommerce add to cart button based on product category(如何根据产品类别在WooCommerce添加到购物车按钮下添加文本)
本文介绍了如何根据产品类别在WooCommerce添加到购物车按钮下添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在某些类别的产品页面上的WooCommerce添加到购物车按钮下添加一个div。
我现在有点不知所措。此代码没有破坏任何内容,但文本未显示。
我已尝试:.woocommerce div.product form.cart::after
,但这适用于所有产品。
以下是PHP代码片段:
function add_polarity_info() {
global $product;
if( is_product() && has_term( ['telecaster-pickups', 'strat-pickups', 'bass-pickups', 'p90-pickups', 'humbuckers', 'dynasonic-pickups', 'mini-humbuckers'], 'product_cat' )) {
echo 'If you are pairing with pickups from another manufacturer and are concerned about polarity and phasing, please let us know in the NOTES field on the checkout screen';
}};
add_action( 'woocommerce_after_add_to_cart_button', add_polarity_info() );
有人能指出我的代码有问题吗?
推荐答案
您的代码包含一些小错误
function add_polarity_info() {
global $product;
// Get product id
$product_id = $product->get_id();
// Set categories
$cats = array( 'telecaster-pickups', 'strat-pickups', 'bass-pickups', 'p90-pickups', 'humbuckers', 'dynasonic-pickups', 'mini-humbuckers' );
// Condition
if ( has_term( $cats , 'product_cat', $product_id ) ) {
echo '<div>If you are pairing with pickups from another manufacturer and are concerned about polarity and phasing, please let us know in the NOTES field on the checkout screen</div>';
}
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_polarity_info' );
这篇关于如何根据产品类别在WooCommerce添加到购物车按钮下添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何根据产品类别在WooCommerce添加到购物车按钮下添加文本
基础教程推荐
猜你喜欢
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01