基于 Show custom fields on the order editing page in WooCommerce 答案代码,我做了一些细微的更改:
add_action( 'woocommerce_before_order_itemmeta', 'add_admin_order_item_custom_fields', 10, 2 );
function add_admin_order_item_custom_fields( $item_id, $item ) {
// Targeting line items type only
if( $item->get_type() !== 'line_item' ) return;
$product = $item-> get_product();
$value1 = $product->get_meta('model_number');
if ( ! empty($value1) ) {
echo '<table cellspacing="0" class="display_meta">';
if ( ! empty($value1) ) {
echo '<tr><th>' . __("Modelnummer", "woocommerce") . ':</th><td>' . $value1 . '</td></tr>';
}
echo '</table>';
}
}
我想让该代码也适用于可变产品自定义字段。
我需要更改什么才能使其适用于可变产品?
答案 0 :(得分:1)
如果是没有为其设置自定义字段的产品变体,以下将获取父变量产品自定义字段:
AVAudioFile
代码位于活动子主题(或活动主题)的functions.php 文件中。经测试有效。