Hide product attributes from additional information tab in WooCommerce
Asked Answered
T

3

7

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' );
Tideway answered 24/12, 2017 at 12:0 Comment(0)
B
8

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:

enter image description here

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

Buenrostro answered 24/12, 2017 at 12:29 Comment(5)
Hi, thanks for the quick response. But here i have to hand pick products and deselect the attributes one by one? I have like 80.000+ products :) Would be great to filter them out in functions.php so new added products will get affected as well by default. Also i don´t want product attributes to be disabled at all, just hiding from the front-end table under additional informations tab. Something like add_filter( 'woocommerce_product_"what_ever_attribute", '__return_false' );Tideway
Please see: s14.postimg.org/mnhg2xyc1/… Product attributes here are not identifiable in html otherwise i could add some css to simply hide them here like .pa_size {display:none;}Tideway
@Tideway Why instead you don't remove this product tab? This is easy and will solve this problemBuenrostro
Because i want to show some of the information. Otherwise i would not ask or? :)Tideway
You mean overwrite the /product-attributes.php ? No, not tested yet. But sounds good. I will look at this today. Thanks for your kind help.Tideway
C
1

I was looking for an answer for the same/similar issue, wanting to remove the additional information tab. I came across this post using the woocommerce_product_tabs filter

I added it to functions.php and the additional information tab is no longer added to the page.

Courbet answered 30/5, 2018 at 17:52 Comment(0)
M
1

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>
Mirepoix answered 22/9, 2020 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.