0

I imported around 7000 products into a WooCommerce project I'm working on, and each product has specifications, and I would like to display them in a table, like something you would see on Amazon for example.

I imported the specifications into custom fields. I am not even sure if it is best to import them as custom fields or if there is a better way to do it.

I found a few plugins that can display a table, but all of them required me to enter the info manually.

I want something that will work automatically using the custom fields.

Also, Every category will have different custom fields, so I want something that will work per category.

I attached a picture of what I would like to achieve. specifications table

  • What is your question? Now it looks like a design specification for the freelancer. – Max Yudin Mar 8 at 20:17
0

How are the custom fields saved? If you use ACF - Advanced custom fields, you can use get_field() function to get the variables.

This should get you started. You can use another action hook or priority if you want the table to be displayed somewhere else.

function display_product_table(){
  global $product;

  ?>
  <table class="shop_attributes">
    <tr>
      <th><?php _e( 'Brand', 'woocommerce' ) ?></th>
      <?php // example if you use acf - advanced custom fields?>
      <td class="product_brand"><?php //echo get_field('brand'); ?></td>
    </tr>
    <?php if ( $product->has_weight() ) : ?>
        <tr>
            <th><?php _e( 'Weight', 'woocommerce' ) ?></th>
            <td class="product_weight"><?php echo esc_html( wc_format_weight( $product->get_weight() ) ); ?></td>
        </tr>
    <?php endif; ?>

    <?php if ( $product->has_dimensions() ) : ?>
        <tr>
            <th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
            <td class="product_dimensions"><?php echo esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ); ?></td>
        </tr>
    <?php endif; ?>

  </table>
  <?php
}
add_action( 'woocommerce_single_product_summary', 'display_product_table', 45);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.