在woocommerce产品类型中隐藏选项选择项目

Way*_*yne 4 wordpress woocommerce drop-down-menu

我打算向某人提供一个woocommerce商店,我想隐藏所有必要的选项,以免混淆非高级用户.特别是产品类型.

在WooCommerce产品编辑器中,可以选择产品类型.我只想展示简单和可变的产品.

通常这可以使用css display:hide属性来完成,但是当我检查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>
Run Code Online (Sandbox Code Playgroud)

我的问题.有没有办法在一个选项框中隐藏分组产品和联盟产品类型,以便在woocommerce或wp更新期间不会受到影响?

谢谢

Lax*_*ana 18

你可以过滤 product_type_selector

add_filter( 'product_type_selector', 'remove_product_types' );

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

    return $types;
}
Run Code Online (Sandbox Code Playgroud)


Mah*_*ous 5

尝试这个。此代码应该可以工作,并且在 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;
}
Run Code Online (Sandbox Code Playgroud)


ran*_*ame 3

您可以使用命名选择器:

#product-type option[value="grouped"] {
    ... your css here ...
}
Run Code Online (Sandbox Code Playgroud)

请参阅这篇文章:CSS to select another Element based on a HTML Select Option Value