我不想显示此属性的数量字段。
如何隐藏"数量"单个产品页面上特定变量产品的字段?
add_filter( 'woocommerce_before_single_variation', 'remove_qty_field', 10, 2 );
function remove_qty_field() {
global $product;
//get_product id
$product = get_product( $product->ID );
//get attributes
$attributes = $product->get_attributes();
//product type
$product_type = $product->is_type( 'variable' );
//if Product is variable
if( $product_type && array_key_exists( 'select-quantity', $attributes ) ){
echo '<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>';
}
else{
//leave as it is
}
}
答案 0 :(得分:0)
我刚才解决了我的问题,希望能帮助别人
add_filter( 'woocommerce_before_single_variation', 'remove_qty_field', 10, 2 );
function remove_qty_field() {
global $post;
//get_product id
$product = get_product( $post->ID );
//get attributes
$attributes = $product->get_attributes();
//product type
$product_type = $product->is_type( 'variable' );
//if Product is variable
if( $product_type && array_key_exists( 'select-quantity', $attributes ) ){
echo '<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>';
}
else{
echo '<style type="text/css">.quantity, .buttons_added { margin-bottom:15px;}</style>';
}
}