Hide option select item in woocommerce product type

两盒软妹~` 提交于 2020-05-29 04:29:33

问题


I am planning to deliver a woocommerce shop to someone and I want to hide none essential options in order not to confuse non advance users. Particularly Product type.

In WooCommerce Product Editor, there is an option to select product type. I only want to show Simple and variable product.

Normally this could be done using css display:hide attributes but when I inspect woocommerce product option select, the options does not have id nor class selector.

Here is the code I saw on product options

<select id="product-type" name="product-type">
<optgroup label="Product Type"><option value="simple" selected="selected">Simple product</option>
<option value="grouped">Grouped product</option><option value="external">External/Affiliate product</option>
<option value="variable">Variable product</option></optgroup>
</select>

My question. Is there a way to hide grouped product and affiliate product type on that option select box in a way that it wont be affected during woocommerce or wp update?

Thanks


回答1:


You can use named selectors:

#product-type option[value="grouped"] {
    ... your css here ...
}

See this post: CSS to select another Element based on a HTML Select Option Value




回答2:


You can filter product_type_selector

add_filter( 'product_type_selector', 'remove_product_types' );

function remove_product_types( $types ){
    unset( $types['grouped'] );
    unset( $types['external'] );

    return $types;
}



回答3:


Try this. This code should work and it work best with woocommerce 3.4.4 and above. Refrence: https://gist.github.com/tanmay27vats/89f9d67db78c33a6ffa1d844235a5db1

add_filter( 'product_type_selector', 'remove_product_types' );

function remove_product_types( $types ){
    unset( $types['grouped'] );
    unset( $types['external'] );
    unset( $types['variable'] );

    return $types;
}


来源:https://stackoverflow.com/questions/20746778/hide-option-select-item-in-woocommerce-product-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!