简体   繁体   English

隐藏 WooCommerce 可变产品上的特定产品属性下拉列表

[英]Hide specific product attribute dropdown on WooCommerce variable products

On WooCommerce I have added a 'Brand' product attribute that I use for the variations of some variable products.在 WooCommerce 上,我添加了一个“品牌”产品属性,用于一些可变产品的变体。

This field is displayed on the website product page which isn't really necessary as I can set a default value for the brand.此字段显示在网站产品页面上,这并不是必需的,因为我可以为品牌设置默认值。 Does anyone know a way to hide this by amending one of the.PHP files.有谁知道通过修改一个.PHP 文件来隐藏它的方法。 The functions.php for example?例如,functions.php?

品牌变量字段

Important: A default value (term) need to be set for the product attribute you want to hide in all variations for the related variable products.重要提示:需要为要隐藏在相关变量产品的所有变体中的产品属性设置默认值(术语)。

You can use the following hooked function that will check if "Brand" attribute is set on your variable product.您可以使用以下挂钩 function 来检查您的变量产品是否设置了“品牌”属性。

The code will hide the first attribute dropdown from this variable product, using an injected inline CSS style rule (so it's important that "brand" dropdown is the first one above the others) :该代码将使用注入的内联 CSS 样式规则隐藏此变量产品的第一个属性下拉列表(因此,重要的是“品牌”下拉列表是其他下拉列表中的第一个)

add_action( 'woocommerce_single_product_summary', 'hide_brands_attribute_dropdown', 1 );
function hide_brands_attribute_dropdown() {
    global $product;

    if( $product->is_type('variable') && $product->get_attribute('Brand') ){
        ?>
        <style>
        table.variations tbody tr:first-of-type {display:none;}
        </style>
        <?php
    }
}

Code goes in functions.php file of your active child theme (or active theme).代码进入您的活动子主题(或活动主题)的functions.php 文件。 Tested and works.测试和工作。

Related:有关的:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Woocommerce 变量产品下拉菜单中隐藏变体属性值 - Hide a variation attribute value in Woocommerce variable product dropdown 隐藏Woocommerce中特定产品的相关产品选项卡 - Hide related product tab for specific products in Woocommerce WooCommerce:按属性过滤产品并在变体缺货时隐藏产品 - WooCommerce: filter products by attribute and hide product if variation is out of stock Woocommerce可变产品下拉列表 - Woocommerce Variable products dropdown 从Woocommerce可变价格下拉菜单中排除产品 - Exclude products from Woocommerce variable product dropdown with variations prices 在 Woocommerce 单个产品的标题前添加链接的特定产品属性 - Add linked specific product attribute before title on Woocommerce single products 根据特定产品属性值显示 WooCommerce 相关产品 - Display WooCommerce related products based on specific product attribute value 在 Woocommerce 单个产品的标题后添加特定的产品属性 - Add specific product attribute after title on Woocommerce single products 在 WooCommerce 可变产品属性下拉选项中添加最小差价 - Add the min price difference in WooCommerce variable products attribute dropdown options Woocommerce 单变量产品中的重新排序属性下拉项 - Reorder attribute dropdown terms in Woocommerce single variable products
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM