您忘记保存自定义元数据字段数据,所以请在下面的代码中进行检查。Reference
add_filter( \'woocommerce_checkout_fields\' , \'occasion_checkout_field_update_order_meta\' );
function occasion_checkout_field_update_order_meta( $fields ) {
$fields[\'billing\'][\'occasion\'] = array( \'type\' => \'select\',
\'id\' => \'occasion\',
\'placeholder\' => __(\'Select Occasion\', \'woocommerce\'),
\'required\' => false,
\'class\' => array(\'form-row-wide\'),
\'clear\' => false,
\'options\' => array(
\'Birthday\' => __(\'Birthday\', \'woocommerce\'),
\'Anniversary\' => __(\'Anniversary\', \'woocommerce\'),
\'Congratulations\' => __(\'Congratulations\', \'woocommerce\'),
\'Sorry\' => __(\'Sorry\', \'woocommerce\'),
\'Good Luck\' => __(\'Good Luck\', \'woocommerce\'),
\'Thank You\' => __(\'Thank You\', \'woocommerce\'),
\'Get Well Soon\' => __(\'Get Well Soon\', \'woocommerce\'),
\'Love\' => __(\'Love\', \'woocommerce\')
)
);
return $fields;
}
add_action( \'woocommerce_checkout_update_order_meta\', \'occasion_checkout_update_order_meta\' );
function occasion_checkout_update_order_meta( $order_id ){
if( !empty( $_POST[\'occasion\'] ) )
update_post_meta( $order_id, \'_occasion\', sanitize_text_field( $_POST[\'occasion\'] ) );
}
add_action( \'woocommerce_admin_order_data_after_billing_address\', \'occasion_edit_woocommerce_checkout_page\', 10, 1 );
function occasion_edit_woocommerce_checkout_page($order){
echo __(\'Occasion\').\': \'.get_post_meta($order->id, \'_occasion\', true );
}