【发布时间】:2020-01-29 13:01:31
【问题描述】:
我希望仅显示一种特定产品的订单备注,而隐藏所有其他产品的订单备注。看起来很简单,但我一直在努力拼凑代码以使其工作。
【问题讨论】:
标签: woocommerce checkout
我希望仅显示一种特定产品的订单备注,而隐藏所有其他产品的订单备注。看起来很简单,但我一直在努力拼凑代码以使其工作。
【问题讨论】:
标签: woocommerce checkout
您可以尝试将此代码添加到您的主题文件的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' );
}
}
【讨论】: