首页 文章

woocommerce hide基于自定义字段添加到购物车

提问于
浏览
-1

我想在Woocommerce产品页面(单页)上隐藏“添加到购物车”按钮 . 我尝试了一切,但我还没想到它 .

所以,我有一个名为 Available 的自定义字段,我在其中输入"1"或"0" . 现在,对于我将此自定义字段设置为0的产品 - 我希望禁用ADD TO CART按钮 .

在我使用的产品列表页面中: get_post_meta($post->ID, 'available', true); 它正在工作,但在单页面(产品页面)中 get_post_meta 无效 .

我想我应该通过使用函数来完成这项工作?或者 variation-add-to-cart.php 中的一些代码 .

能否请你帮忙?

谢谢!!!

1 回答

  • 0

    编写此代码为your-theme / functions.php

    if(get_post_meta(get_the_ID(), 'available', true)) {
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        }
    

相关问题