admin管理员组

文章数量:1122846

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.

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.

Share Improve this question asked Mar 8, 2019 at 19:12 ali pikali pik 193 bronze badges 1
  • What is your question? Now it looks like a design specification for the freelancer. – Max Yudin Commented Mar 8, 2019 at 20:17
Add a comment  | 

1 Answer 1

Reset to default 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);

本文标签: categoriesHow to display custom fields as table in Woocommerce