我想隐藏一个具有所有值的属性。请查看链接。 https://csepromos.nl/product/oregon-400-ml-drinkfles-met-karabijnhaak/
我想在产品页面上隐藏以下属性和以下值:
Filter kleur:Grijs Groen Oranje Paars Rood Wit Zwart
可以用代码完成吗?
我发现以下代码会有所帮助,但是我没有下拉菜单,并且如何一次隐藏所有值?
https://stackoverflow.com/a/54987217/13407118
谢谢!
您可以使用基于“ Color”产品属性的以下示例,该示例具有从可变产品的属性下拉列表中删除的2个值。
您将需要设置产品属性分类法,该分类法始终以pa_
开头,后跟产品属性段。因此,对于“ Color”产品属性,分类法为pa_color
。
然后,您将在所需的产品属性术语名称数组中设置(您要从下拉菜单中隐藏的名称。)>
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'filter_dropdown_variation_args', 10, 1 ); function filter_dropdown_variation_args( $args ) { // HERE set your product attribute taxonomy (always start with "pa_" + the slug $taxonomy = 'pa_color'; // HERE set the product attribute terms names that you want to hide $targeted_terms_names = array( "Blue", "Red" ); // Convert term names to term slugs $terms_slugs = array_filter( array_map( 'sanitize_title', $targeted_terms_names ) ); // Targeting a product attribute only if( $args['attribute'] === $taxonomy ) { // Loop through the product attribute option values foreach( $args['options'] as $key => $option ){ if( in_array( $option , $terms_slugs ) ) { unset($args['options'][$key]); } } } return $args; }
代码进入您的活动子主题(或活动主题)的functions.php文件中。经过测试和工作。