简体   繁体   English

如何在 WooCommerce 添加到购物车按钮下方添加文本

[英]How to add text underneath WooCommerce Add To Cart Button

I try to add a div underneath the WooCommerce Add To Cart button on product pages within certain categories.我尝试在某些类别的产品页面上的 WooCommerce 添加到购物车按钮下方添加一个 div。

I'm a bit at a loss here.我在这里有点不知所措。 This code is not breaking anything, but the text is not showing.这段代码没有破坏任何东西,但没有显示文本。

I've tried: .woocommerce div.product form.cart::after , but that applies to all products.我试过: .woocommerce div.product form.cart::after ,但这适用于所有产品。

Here's the PHP snippet:这是 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() );

Can someone point out the problem with my code?有人可以指出我的代码的问题吗?

Your code contains some small errors您的代码包含一些小错误

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM