要添加其他订单注释自定义字段,请执行以下操作:
外接程序功能。php:
/**
* add new order note field
*/
add_filter( \'woocommerce_checkout_fields\' , \'customizing_checkout_fields\', 10, 1 );
function customizing_checkout_fields( $fields ) {
// Define new custom Order Notes field data array
$customer_note = array(
\'type\' => \'textarea\',
\'class\' => array(\'form-row-wide\', \'notes\'),
\'label\' => __(\'Order Notes New\', \'woocommerce\'),
\'placeholder\' => _x(\'Notes about your order, e.g. special notes for delivery.\', \'placeholder\', \'woocommerce\')
);
$fields[\'order\'][\'billing_new_customer_note\'] = $customer_note;
return $fields;
}
/**
* Process the checkout
*/
add_action(\'woocommerce_checkout_process\', \'customise_checkout_field_process\');
function customise_checkout_field_process()
{
#if the field is set, if not then show an error message.
if (!$_POST[\'billing_new_customer_note\']) wc_add_notice(__(\'Please enter Order Notes New value.\') , \'error\');
}
/**
* Update the order meta with field value
*/
add_action(\'woocommerce_checkout_update_order_meta\', \'custome_checkout_field_update_order_meta\');
function custome_checkout_field_update_order_meta($order_id)
{
if (!empty($_POST[\'billing_new_customer_note\'])) {
update_post_meta($order_id, \'billing_new_customer_note\', sanitize_text_field($_POST[\'billing_new_customer_note\']));
}
}
Display field value on the order edit page
add_action( \'woocommerce_admin_order_data_after_shipping_address\', \'custom_checkout_field_display_admin_order_edit\', 10, 1 );
function custom_checkout_field_display_admin_order_edit($order){
echo \'<p><strong>\'.__(\'Order Notes New\').\':</strong> <br/>\' . get_post_meta( $order->get_id(), \'billing_new_customer_note\', true ) . \'</p>\';
}
Display field In Order review page after order note
add_action(\'woocommerce_order_details_after_order_table\',\'custom_checkout_field_display_order_reviews\',20);
function custom_checkout_field_display_order_reviews( $order ){
?>
<table class="woocommerce-table shop_table">
<tbody>
<tr>
<th>Custom order note </th>
<td><?php echo "<strong>".get_post_meta( $order->get_id(), \'billing_new_customer_note\', true )."</strong>"; ?></td>
</tr>
</tbody>
</table>
<?php }