【问题标题】:WooCommerce - Checkout Fields for Specific ProductWooCommerce - 特定产品的结帐字段
【发布时间】:2020-01-29 13:01:31
【问题描述】:

我希望仅显示一种特定产品的订单备注,而隐藏所有其他产品的订单备注。看起来很简单,但我一直在努力拼凑代码以使其工作。

【问题讨论】:

    标签: woocommerce checkout


    【解决方案1】:

    您可以尝试将此代码添加到您的主题文件的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' );
    
    }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多