How to hide certain custom product attributes on single product pages additional informations tab?
Note: I don´t want to hide everything, just specific attributes.
For e.g i would like to hide "pa_size"
to name one it it.
Only found this one, but its for a products weight.
add_filter( 'woocommerce_product_get_weight' , '__return_false' );
If you want to remove the additional information tab from the WooCommerce product page you can insert a PHP code snippet that will modify the code of the product page – or you can use a page builder, such as Divi or Elementor to completely redesign the product page to your aesthetic requirements.
You can replace it with the title you wish by changing the text “Product Data” to the text you want. To access the theme Functions. php file, from the WordPress dashboard, go to Appearance > Theme Editor, then paste the code you have copied before at the end of the file.
For all custom product attributes you can hide them from additional information tab just deselecting the option "Visible on the product page" under product settings > Attributes tab:
1) To remove the product dimensions, you can disable that with the following code:
add_filter( 'woocommerce_product_get_dimensions', '__return_false' );
2) To remove everything from the tab ( weight, dimensions and custom attributes) use this:
remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 );
3) To fine tune what you want to display:
You can override single-product/product-attributes.php
template via your active child theme (or active theme) that displays everything in this product tab.
So you can remove any html block, that displays those details, or customize it…
Official documentation: Template structure & Overriding templates via a theme
Using the functions.php
can cause problems with shipping, see here: https://github.com/woocommerce/woocommerce/issues/5985#issuecomment-322541850
Simply copy the wp-content/plugins/woocommerce/templates/single-product/product-attributes.php
to wp-content/themes/YOUR_CHILD_THEME/woocommerce/single-product/product-attributes.php
and add an if
to check for the attribute. (As LoicTheAztec mentioned in #3)
This is from WooCommerce 4.4.1:
<?php
/**
* Product attributes
*
* Used by list_attributes() in the products class.
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/product-attributes.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 3.6.0
*/
defined( 'ABSPATH' ) || exit;
if ( ! $product_attributes ) {
return;
}
?>
<table class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<?php // Hide weight attribute in frontend ?>
<?php if ( esc_attr( $product_attribute_key ) !== 'weight' ): ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With