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
1 Answer
Reset to default 0How 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
版权声明:本文标题:categories - How to display custom fields as table in Woocommerce 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291823a1928805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论