Woocommerce阻止购物车页面在购物车中隐藏特定产品ID的数量字段

时间:2020-10-27 16:54:37

标签: woocommerce field block cart

我一直在购物车页面上使用WooCommerce Blocks插件,并且尝试使用代码片段对其进行一些修改。 https://developer.woocommerce.com/2020/05/27/available-for-testing-a-block-based-woocommerce-cart-and-checkout/

我发现此代码段在常规的woo购物车页面上可以正常使用,但我真的很希望它可以在woocommerce块购物车页面上使用:

add_filter( 'woocommerce_quantity_input_args', 'hide_quantity_input_field', 20, 2 );
function hide_quantity_input_field( $args, $product ) {
    // Here set your product IDs in the array
    $product_ids = array(46);

    // Handling product variation
    $the_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id();

    // Only on cart page for a specific product category
    if( is_cart() && in_array( $the_id, $product_ids ) ){
        $input_value = $args['input_value'];
        $args['min_value'] = $args['max_value'] = $input_value;
    }
    return $args;
}

我已经尝试过更改优先级。有什么建议吗?

0 个答案:

没有答案