Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #805534

    I have 2 product attributes:
    first attribute is ‘unit weight’ (which is 100gr/150gr/250gr usually)
    second attribute is ‘price per 100gr’

    for some reason the first attribute shows up under the quantities button in the main shop page and other categories – which is great!
    but I want the second attribute to be shown too!
    and I can’t find any setting to tweak to make that happen
    ..is there any way to do that?

    i pasted screen shot and a link the in private content

    • This topic was modified 6 years, 9 months ago by Sarah.
    #806873

    UPDATE:
    o.k.. i think that the flowing code snippet in my child theme function.php is the one responsible for displaying the weight attribute

    add_action( 'woocommerce_after_shop_loop_item', 'rs_show_weights', 9 );
    
    function rs_show_weights() {
    
        global $product;
        $weight = $product->get_weight();
    
        if ( $product->has_weight() ) {
            echo '<div class="product-meta"><span class="product-meta-label">משקל ליחידה: </span>' . $weight . get_option('woocommerce_weight_unit') . '</div></br>';
                }
            }

    my question is: is it possible to display other attributes in archive pages in the same way?
    Any help would be very appreciated

    #807020

    Hi Doron,

    You can add the other attribute to this snippet, you just have to know the name of the attribute.

    Best regards,
    Victoria

    #807276

    HI Victoria
    I’m not sure about that
    if you go to the attributes page (there is a a screen shot in the private content) you will see
    all attributes, including weight, has only Hebrew name (which is this websites’s front end language) none are in english
    (weight is the pink number 1 in the screen shot and number 2 is ‘price per 100gr’)

    I’m pretty sure the code snippet above uses the weight specified in the product shipping values (look at the second screen shot in the private content) and not the weight attribute

    if I give you login details, would it help?

    #808464

    by googling I found something that might do the trick
    https://stackoverflow.com/questions/38487561/woocommerce-get-custom-product-attribute
    But I’m still not sure how to Combine it with the current code
    (and especially not sure if its possible when the attribute name isn’t in English)
    Victoria? can you help me?

    • This reply was modified 6 years, 10 months ago by Doron.
    #808503

    Hi Doron,

    Did you create the attribute yourself? The “price per 100gr” one?

    Best regards,
    Victoria

    #808521

    yes
    by the way – I’m able to change the attribute name to English but I’m not sure if I can because than it will also display in English in the inner product pages ‘more info’ tab and the client needs the websites language to be Hebrew

    #809914

    Hi Doron,

    The name of the attribute has to be in English, and then you translate it. What is the name and what code are you using?

    Best regards,
    Victoria

    #809977

    o.k
    I’ve changed from Hebrew (מחיר ל 100 גרם) to English (price per 100gr)
    so the attribute name is now price per 100gr
    whats the next step?
    I’m note sure what code to use or how to use each code
    (I’m o.k with CSS but not so strong with PHP, was hoping you could guide me with this?)

    #810153

    Hi,

    Please, may you provide to us your WP credentials and the FTP too?

    Best regards,
    John Torvik

    #810462

    Yes
    thank you
    I posted them in the private content

    #812915

    hi.. is there any news?

    #813675

    Hi,

    Please replace the filter with the following code.

    /*
     * show product weights
     */
    add_action( 'woocommerce_after_shop_loop_item', 'rs_show_weights', 9 );
    function rs_show_weights()
    {
      global $product;
      $weight  = $product->get_weight();
    	$pergram = $product->get_attribute( 'pa_price-per-100gr' );
    
      if ( $product->has_weight() )
    	{
          echo '<div class="product-meta"><span class="product-meta-label">משקל ליחידה: </span>' . $weight . get_option('woocommerce_weight_unit') . '</div></br>';
      }
    
    	if ( $pergram )
    	{
          echo '<div class="product-meta"><span class="product-meta-label">משקל ליחידה: </span>' . $pergram . '</div></br>';
      }
    }
    

    Best regards,
    Ismael

    #813715

    It works!!
    thank you so much!!

    #814022

    Hi,

    We’re happy to help!

    Please let us know here in the forums if you have any other questions.

    Thank you for using Enfold.

    Cheers!
    Sarah

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘WooCommerce display product attributes in archive page’ is closed to new replies.