admin管理员组文章数量:1134249
I'm looking for a way to show the Shipping Class of a product in the product admin overview to be able to quickly check if the right shipping class was selected for a product.
Can you help?
I'm looking for a way to show the Shipping Class of a product in the product admin overview to be able to quickly check if the right shipping class was selected for a product.
Can you help?
Share Improve this question asked Oct 19, 2023 at 10:00 HelmiHelmi 1186 bronze badges1 Answer
Reset to default 3You can add a new column to the product admin overview that displays the shipping class of each product. Here's how you can do it:
Add the following code to your theme's
functions.php
file or a custom plugin:// Add new 'Shipping Class' column to the product admin overview add_filter( 'manage_edit-product_columns', 'show_product_shipping_class_column' ); function show_product_shipping_class_column( $columns ) { $columns['shipping_class'] = __( 'Shipping Class', 'woocommerce' ); return $columns; } // Populate 'Shipping Class' column with the product's shipping class add_action( 'manage_product_posts_custom_column', 'populate_product_shipping_class_column', 10, 2 ); function populate_product_shipping_class_column( $column, $postid ) { if ( $column == 'shipping_class' ) { $_product = wc_get_product( $postid ); $shipping_class = $_product->get_shipping_class(); if ( ! empty( $shipping_class ) ) { echo $shipping_class; } else { echo '<span class="na">–</span>'; } } } // Make 'Shipping Class' column sortable add_filter( 'manage_edit-product_sortable_columns', 'sortable_product_shipping_class_column' ); function sortable_product_shipping_class_column( $columns ) { $columns['shipping_class'] = 'shipping_class'; return $columns; }
This code does three things:
- It adds a new 'Shipping Class' column to the product admin overview.
- It populates this column with the shipping class of each product.
- It makes the 'Shipping Class' column sortable.
Now, when you go to the product admin overview, you should see a new 'Shipping Class' column that displays the shipping class of each product. You can click on the column header to sort the products by their shipping class.
本文标签: woocommerce offtopicShow shipping class in admin product list
版权声明:本文标题:woocommerce offtopic - Show shipping class in admin product list 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736771773a1952124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论