[英]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.