Support

Account

Home Forums Front-end Issues Post Object Field – Woocommerce Archive

Unread

Post Object Field – Woocommerce Archive

  • I am working on a Woocommerce Costumization and am struggling with a Post Object type field. (Reference here: https://www.advancedcustomfields.com/resources/post-object/).

    Basically, in the product creating page I have a custom field that allows me to associate pages objects to a product. The pages should then be displayed as a list inside the product item on the Product Archive Page.

    Right now this is the code I have:
    functions.php (hooks into content-product.php)

    
    /** 
     * Adds ACF CUSTOM FIELDS to the Archive Page 
     */
    
    add_action('woocommerce_shop_loop_item_title', 'add_module_info', 15);
    function add_module_info()
    {
       do_action('woocommerce_before_shop_loop_item_title');
      
       $modules = get_field('modules');
    
       if ($modules) :
          echo '<ul>';
          foreach ($modules as $module) :
             echo '<li><a href="' . get_permalink($module->ID) . '">' . $module->post_name . '</a></li>';
          endforeach;
          echo '</ul>';
       endif;
    }
    
    

    **The Problem**
    What happens is that instead of getting the pages associated with a product, instead I get post objects for all the pages on the website. Which is not at all what I want.

    However, if I use the exact same code in the content-single-product.php it works just fine.

    I have tried several different options, namely adding the product ID to the get_field() query, tried using different alternatives to fetch the field, and also tried different answers on stackoverflow.. but nothing until now managed to solve my problem.

    Any light on what I am doing wrong??

    Regards,
    T.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.