【问题标题】:Hide quantity field for variable product on Woocommerce single product page在 Woocommerce 单品页面上隐藏可变产品的数量字段
【发布时间】:2018-09-26 16:31:23
【问题描述】:

我需要隐藏特定产品的产品页面中的数量字段。我知道 woocommerce 3.0 发生了很多变化。谁能帮忙

这是我没有运气的尝试

function wc_remove_all_quantity_fields( $return, $product ) {
    switch ( $product->product_type ) :
        case "variable":
            return true;
            break;
        default:    // simple product type
            return false;
        break;
    endswitch;
    }
add_filter( 'woocommerce_is_sold_individually', 'wc_remove_all_quantity_fields', 10, 2 );

我正在寻找类似的东西

function vpm_remove_quantity_fields( $return, $product ) {
   global $product ;
     if ( $product->is_type('variable') && is_product() ) {
        return true;     
      }
}
add_filter( 'woocommerce_is_sold_individually', 'vpm_remove_quantity_fields', 10, 2 );

【问题讨论】:

    标签: php wordpress woocommerce product product-quantity


    【解决方案1】:

    以下内容应隐藏单个产品页面中可变产品的数量字段:

    add_filter( 'woocommerce_quantity_input_args', 'hide_quantity_input_field', 20, 2 );
    function hide_quantity_input_field( $args, $product ) {
        if( is_product() && $product->is_type('variable') ){
            $args['min_value'] = $args['max_value'] = 1;
        }
        return $args;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试和工作。

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 2021-11-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 2014-05-05
      • 2018-04-23
      • 1970-01-01
      • 2019-09-27
      相关资源
      最近更新 更多