我有这个代码在产品页面上创建一个下拉列表。它保存所选数据并显示在订单上。我需要帮助的是在自定义列中显示值。
这是……
要在自定义列中显示此自定义订单商品元数据,请使用以下内容:
// Display data to custom column in admin orders list add_action( 'manage_shop_order_posts_custom_column' , 'display_enclosed_invoice_order_column_data' ); function display_enclosed_invoice_order_column_data( $column ) { global $the_order, $post; if( $column == 'cost_center' ) { $values = []; // Initializing // Loop through order items foreach ( $the_order->get_items() as $item ) { if( $cost_centre = $item->get_meta( 'Cost Center' ) ) { $values[] = $cost_centre; } } // Display the value(s) if( sizeof( $values ) > 0 ) { echo implode( ', ', $values); // Convert the array to a coma separated string } } }
代码在您的活动子主题(或活动主题)的function.php文件中。它应该有效。