删除或隐藏添加到购物车以获取没有特定类别库存的产品

时间:2018-06-25 10:34:18

标签: woocommerce preorder

如果仅在产品缺货的情况下为TEST类别启用了延期交货,是否可以隐藏 ADD TO CART或PREORDER按钮

但是对于其他类别,他们可以补货或预购产品。

 function test_remove_cart() {
           $product = get_product();
           if ( has_term ( 'test', 'product_cat') ) {
            global $product;
                $product->get_stock_quantity() == 0 ;

                if($product == 0){
                   remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
                   remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
                   remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
                   remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
                   remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
                   remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
                }
           }
        }
        add_action( 'wp', 'test_remove_cart' );

谢谢

0 个答案:

没有答案