【问题标题】:Hide option select item in woocommerce product type在 woocommerce 产品类型中隐藏选项选择项目
【发布时间】:2013-12-23 15:47:47
【问题描述】:

我计划向某人提供一个 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>

我的问题。有没有办法在该选项选择框中隐藏分组产品和附属产品类型,使其在 woocommerce 或 wp 更新期间不会受到影响?

谢谢

【问题讨论】:

    标签: wordpress drop-down-menu woocommerce


    【解决方案1】:

    试试这个。此代码应该可以工作,并且最适合 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;
    }
    

    【讨论】:

      【解决方案2】:

      你可以过滤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】:

        你可以使用命名选择器:

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

        看到这个帖子:CSS to select another Element based on a HTML Select Option Value

        【讨论】:

        • 成功了!谢谢@cale_b
        猜你喜欢
        • 2021-07-24
        • 1970-01-01
        • 2018-02-26
        • 2018-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多