首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在WooCommerce中添加“添加到购物车”按钮

在WooCommerce中添加“添加到购物车”按钮
EN

WordPress Development用户
提问于 2013-11-24 13:28:52
回答 1查看 15.5K关注 0票数 0

我使用Mystile WooCommerce主题,其中“添加到购物车”按钮由以下代码删除:

代码语言:javascript
复制
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);

放置在此文件wp-content/themes/mystile/includes/theme-woocommerce.php中的

我知道我可以删除这段代码,但是在下一次更新后更改theme-woocommerce.php文件之后,是否有一个选项,所以按钮仍然会出现呢?

我已经尝试在子主题中将此代码添加到我的functions.php中。

代码语言:javascript
复制
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10); 
EN

回答 1

WordPress Development用户

发布于 2013-11-24 13:58:39

您没有在主题文件中这样做是正确的,您也有正确的想法将其放入您的functions.php中。尝试下面所示的方法,这是您实际需要的更多,所以选择适合您的情况。

代码:

代码语言:javascript
复制
    //remove add to cart buttons
    add_action( 'init', 'wpse124288_wc_remove_add_to_cart_buttons' );
    function wpse124288_wc_remove_add_to_cart_buttons() {
        //add to cart button loop
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        //add to cart button single product
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }

    //(re)add add to cart buttons
    add_action( 'init', 'wpse124288_wc_readd_add_to_cart_buttons' );
    function wpse124288_wc_readd_add_to_cart_buttons() {
        //add to cart button loop
        add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        //add to cart button single product
        add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
票数 3
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/124288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档