Display Product attribute on archive loop item

This topic has 4 replies, 2 voices, and was last updated 1 years, 6 months ago ago by Rose Tyler

  • Avatar: Mike Papadakis
    Mike Papadakis
    Participant
    March 16, 2023 at 16:30

    Hi there is there any code to display in the archive loop item? My attribute is delivery and I want to display the term of each product. Thank you

    3 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    March 16, 2023 at 16:36

    Hello, Mike Papadakis,

    Thank you for getting in touch with us.

    We kindly request that you provide more details regarding your request so that we can better understand your needs.
    Thank you for your cooperation.

    Kind Regards,
    8theme team

    Avatar: Mike Papadakis
    Mike Papadakis
    Participant
    March 16, 2023 at 16:40

    So for explanation I have an attribute called delivery and has 2 terms inside, Greece and Only Kalamata, every product has 1 terms of these 2, so I want to display the attribute value on the products archive (shop, category etc) before the title. I have used this code but it doesn’t work

    add_action( ‘woocommerce_shop_loop_item_title’, ‘ecommercehints_show_product_attributes_on_arhive_loop_item’, 1, 0 );
    function ecommercehints_show_product_attributes_on_arhive_loop_item() {
    global $product;
    $product = wc_get_product( get_the_id() );
    $product_attributes = $product->get_attributes();
    $color_id = $product_attributes[‘pa_delivery’][‘options’][‘0’]; // returns the ID of the term. You will need to change ‘pa_color’ to your taxonomy attribute ID.
    $color_name = get_term( $color_id )->name;
    $class= $color_id == 228 ? “greekcolor” : “deliverypa”;
    echo ‘‘ . $color_name . ‘‘;
    };

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    March 16, 2023 at 17:26

    Hello, Mike Papadakis,

    We need to inform you that additional customization of code is outside the scope of our basic support.

    Please provide the URL of your site, temporary wp-admin and FTP access via the Private Content area, so that we can assess what can be done to help you.
    To provide wp-admin access, you can create a new user account with administrator role via the Dashboard, and provide us with the username and password via the Private Content area.
    To create FTP access, please contact your hosting provider for assistance.

    Kind Regards,
    8theme team

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.