我希望仅显示一种特定产品的订购单,并隐藏所有其他产品的订购单。看起来很简单,但我一直努力将代码拼凑在一起才能使它起作用。
您可以尝试将此代码添加到主题文件的functions.php
中并替换为您的$product_id = 282;
。
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
add_action( 'woocommerce_before_cart', 'bbloomer_find_product_in_cart' );
function bbloomer_find_product_in_cart() {
$product_id = 282;
$product_cart_id = WC()->cart->generate_cart_id( $product_id );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
if ( $in_cart ) {
add_filter( 'woocommerce_enable_order_notes_field', '__return_true' );
}
}