我计划提供一个woocommerce商店给某人,我想隐藏任何必要的选项,以避免混淆非高级用户。特别是产品类型。
在WooCommerce产品编辑器中,有一个选择产品类型的选项。我只想展示简单和可变的产品。
通常这可以使用css display:hide attributes来完成,但是当我检查woocommerce产品选项选择时,这些选项既没有id也没有类选择器。
下面是我在产品选项上看到的代码
<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>
我的问题。有没有办法在选项选择框中隐藏分组产品和代销商产品类型,使其在woocommerce或wp更新期间不受影响?
谢谢
发布于 2013-12-23 15:53:32
您可以使用命名选择器:
#product-type option[value="grouped"] {
... your css here ...
}
请看这篇文章:CSS to select another Element based on a HTML Select Option Value
发布于 2015-09-14 19:29:33
您可以过滤product_type_selector
add_filter( 'product_type_selector', 'remove_product_types' );
function remove_product_types( $types ){
unset( $types['grouped'] );
unset( $types['external'] );
return $types;
}
发布于 2019-08-02 13:49:02
尝尝这个。这段代码应该可以工作,并且它在woocommerce 3.4.4和更高版本上工作得最好。参考: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
复制相似问题