Support

Account

Home Forums Bug Reports Impossible to display my fields in Woocommerce tab

Unread

Impossible to display my fields in Woocommerce tab

  • I explain my problem.
    I have imported a list of custom fields (via JSON import tool) from a site to my current site (250) that are related to WooCommerce products. What I would like to do is to display the label and value of each of the filled fields in a characteristic table below each product.

    To do this, I used the get_field_objects function with the product id as parameter. I then looped to display the fields normally. Problem : nothing is displayed. On the other hand, if I go back to the product and update it without touching anything, bam, as if by magic, everything is displayed well…. Except that my client is not going to have fun saving 80,000 products by hand…

    Here is the code:

    add_filter( ‘woocommerce_product_tabs’, ‘wpb_new_product_tab’ );
    function wpb_new_product_tab( $tabs ) {
        // Add the new tab
        $tabs[‘test_tab’] = array(
            ‘title’       => __( ‘Caractéristiques’, ‘text-domain’ ),
            ‘priority’    => 1,
            ‘callback’    => ‘wpb_new_product_tab_content’
        );
        return $tabs;
    }
    function wpb_new_product_tab_content() {
      global $product;
      $id = $product->get_id();
      $fields = get_field_objects($id);
        if( !empty($fields) ): ?>
          <table class=“table”>
            <tbody>
              <?php foreach( $fields as $field ): ?>
                  <?php if( $field[‘value’] && $field[‘label’]!=“Pictogrammes” ): ?>
                    <tr>
                      <th scope=“col”><?php echo $field[‘label’]; ?></th>
                      <th scope=“col”><?php echo $field[‘value’]; ?></th>
                    </tr>
                  <?php endif; ?>
              <?php endforeach; ?>
            </tbody>
          </table>
        <?php else : ?>
          Pas de données actuellement...
        <?php endif;
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.