Search code examples
wordpresswoocommercecode-snippetselementor

How do I add product attributes to the product page in WooCommerce?


I'm using WooCommerce and Elementor Pro. Is there any way to add specific product attributes (e.g. gross and net weight) below the Add to cart button?

It seems like an obvious thing but I haven't found options or snippets for it.

example


Solution

  • First you add attributes to product. Then you use this snippet in functions.php:

    // maybe remove tab with attributes
    add_filter( 'woocommerce_product_tabs', 'remove_info', 100, 1 );
    function remove_info( $tabs ) {
        unset($tabs['additional_information']);
        return $tabs;
    }
    
    // show attributes
    add_action( 'woocommerce_single_product_summary', 'summary_attributes', 35 );
    function summary_attributes() {
        global $product;
        if ( $product->has_attributes() ) {
            wc_display_product_attributes( $product );
        }
    }