Add Advanced Custom Field to Archive Product Loop

This topic has 4 replies, 3 voices, and was last updated 2 months ago ago by Andrew Mitchell

  • Avatar: carlyliczyk
    carliczyk
    Participant
    September 27, 2024 at 01:47

    Hello, I want to use this code to include a custom field on the product archive loop, but its not showing up on the xstore loops, only the elementor loops. Is there any way to alter the code so that it can show up on the xstore loop?

    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘pedro_add_acf_field_to_product_loop’, 15 );

    function pedro_add_acf_field_to_product_loop() {
    global $product;

    // Get the product ID
    $product_id = $product->get_id();

    // Get the ACF field value
    $product_highlight = get_field( ‘product_highlight’, $product_id );

    // Check if the ACF field value exists and display it
    if ( ! empty( $product_highlight ) ) {
    echo ‘

    ‘ . esc_html( $product_highlight ) . ‘

    ‘;
    }
    }

    code is from this website: https://puri.io/blog/how-to-add-acf-fields-to-the-woocommerce-product-loop/

    Thanks so much for your help

    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    September 27, 2024 at 10:19

    Dear @carliczyk,

    We recommend utilizing the following hook for your implementation: after_etheme_product_grid_list_product_element_title.

    Please integrate the custom code as outlined below:

    
    add_action( 'after_etheme_product_grid_list_product_element_title', 'pedro_add_acf_field_to_product_loop', 15 );
    function pedro_add_acf_field_to_product_loop() {
        global $product;
    
        // Retrieve the product ID
        $product_id = $product->get_id();
    
        // Fetch the ACF field value
        $product_highlight = get_field('product_highlight', $product_id);
    
        // If the ACF field value exists, display it
        if (!empty($product_highlight)) {
            echo esc_html($product_highlight);
        }
    }
    

    Please implement this code and inform us about the results at your earliest convenience.

    Best Regards,
    8Theme’s Team.

    Avatar: carlyliczyk
    carliczyk
    Participant
    September 27, 2024 at 18:25

    Thanks so much! This is perfect

    Avatar: Andrew Mitchell
    Andrew Mitchell
    Support staff
    September 27, 2024 at 18:25

    Dear carliczyk,

    Choosing our theme reflects your commitment to quality, and for that, we’re genuinely grateful. As we constantly strive to elevate your experience, your feedback is an invaluable gift. Could you kindly take a moment to rate our product with 5 stars on ThemeForest?

    Click here to share your insights: https://themeforest.net/downloads

    Your support fuels our journey, and we appreciate it more than words can express.

    Best Regards,
    The 8Theme Team

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

The issue related to '‘Add Advanced Custom Field to Archive Product Loop’' has been successfully resolved, and the topic is now closed for further responses

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.