Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EricBusch/6fbedaa152fee7a5fe180ad70e65334e to your computer and use it in GitHub Desktop.
Save EricBusch/6fbedaa152fee7a5fe180ad70e65334e to your computer and use it in GitHub Desktop.
Hide specific attributes from the Additional Information tab on single WooCommerce product pages. [datafeedr][woocommerce]
<?php
/**
* Hide specific attributes from the Additional Information tab on single
* WooCommerce product pages.
*
* @param WC_Product_Attribute[] $attributes Array of WC_Product_Attribute objects keyed with attribute slugs.
* @param WC_Product $product
*
* @return WC_Product_Attribute[]
*/
function mycode_hide_attributes_from_additional_info_tabs( $attributes, $product ) {
/**
* Array of attributes to hide from the Additional Information
* tab on single WooCommerce product pages.
*/
$hidden_attributes = [
'pa_network',
'pa_merchant',
'pa_brand',
];
foreach ( $hidden_attributes as $hidden_attribute ) {
if ( ! isset( $attributes[ $hidden_attribute ] ) ) {
continue;
}
$attribute = $attributes[ $hidden_attribute ];
$attribute->set_visible( false );
}
return $attributes;
}
add_filter( 'woocommerce_product_get_attributes', 'mycode_hide_attributes_from_additional_info_tabs', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment