skip to Main Content

What I am trying to achieve: Enable ‘Simple Product’ pages to display ‘Attributes’ (exactly as Variable Product Attributes are shown)

What I already know:
I know that it can be done by creating a Variable Product with just one variation instead of a Single Product. I have used Variable Products before and I don’t want to create 1 additional ID for every single simple product.

Why am I trying this: Weights shown on any product page is the shipping weight. I want to show the product actual weight and actual volume (eg 100ml). Volumes are not supported by default and I want a consistent/elegant way to show it to customers. Since I am already using attributes for Variable products, I can quickly reuse the same attribute values for Simple Products.

What I don’t want to do:
– Write volume in the Product header
– Create variable products with 1 variation

I am sure there are lots of people facing this issue and would like a good solution. I just need the Attribute values to be shown for Simple Products in the exact place as Variable Products. I can customize the css part.

I am comfortable editing functions.php

Can anyone help me please?

2

Answers


  1. To add the attributes after title we need to hook to woocommerce_single_product_summary action.

    By default title is with priority of 5

    add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
    

    In your child theme functions.php file add the following.

    add_action( 'woocommerce_single_product_summary', 'show_attributes_after_title', 6 );
    function show_attributes_after_title() {
        global $product; 
        $pa_weight = $product->get_attribute( 'pa_weight' ); //Make sure this is your attribute
        $pa_volume = $product->get_attribute( 'pa_volume' ); //Make sure this is your attribute
        if($pa_weight): 
            echo $pa_weight; 
        endif;
        if($pa_volume): 
            echo $pa_volume; 
        endif;
    }
    
    Login or Signup to reply.
  2. Have you found a precise solution to this problem, please?
    Because I would like to have the same thing.

    Thank you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search