【问题标题】:Customize Add to Cart button on specific WooCommerce product categories自定义特定 WooCommerce 产品类别上的“添加到购物车”按钮
【发布时间】:2019-12-13 13:05:20
【问题描述】:

我正在尝试将我的 WooCommerce 档案页面上特定产品类别的添加到购物车按钮更改为“阅读更多”按钮,该按钮将链接到产品页面但不是 在单个产品页面本身上).

(Woocommerce,在 Wordpress 上使用 Elementor)

使用Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3应答码,如何将其限制为只有一个产品类别(本例中术语名称为“类”)? p>

感谢任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce product taxonomy-terms


    【解决方案1】:

    您可以使用has_term() 条件函数来定位产品类别,这样:

    add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
    function replacing_add_to_cart_button( $button, $product ) {
        if ( has_term( 'Classes', 'product_cat', $product->get_id() ) ) {
            $button_text = __("Read more", "woocommerce");
            $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
        }
    
        return $button;
    }
    

    代码进入您的活动子主题(或活动主题)的 functions.php 文件或任何插件文件中。

    【讨论】:

    • 1+ 为你我的朋友 :) 你应得的。谢谢
    • 有没有针对特定产品的方法?谢谢。
    • @DiegoM。 if ( in_array($product-&gt;get_id(), array(58,63,89,145,147,231) ) ) { 带有一系列产品 ID
    猜你喜欢
    • 2018-02-10
    • 2020-09-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2015-12-04
    • 2022-01-03
    • 1970-01-01
    • 2019-07-16
    相关资源
    最近更新 更多