1 回答
TA贡献1866条经验 获得超5个赞
要将“时段”选定值包含到客户订单备注中,您将从代码中替换:
// Update the order meta with field value
add_action('woocommerce_checkout_update_order_meta', 'wps_select_checkout_field_update_order_meta');
function wps_select_checkout_field_update_order_meta( $order_id ) {
if ( $_POST['daypart']) update_post_meta( $order_id, 'daypart', esc_attr($_POST['daypart']));
}
通过以下方式:
// Update the order meta with field value
add_action( 'woocommerce_checkout_create_order', 'wps_update_order_meta', 20, 2 );
function wps_update_order_meta( $order, $data ) {
if ( isset($_POST['daypart']) && ! empty($_POST['daypart']) ) {
// Add "daypart" selected value as custom order meta data
$order->update_meta_data('daypart', esc_attr($_POST['daypart']));
// Get customer note
$customer_note = isset( $data['order_comments'] ) ? $data['order_comments'] . ' ' : '' );
// add to existing customer note the "daypart" selected value
$order->set_customer_note( $customer_note . esc_attr($_POST['daypart']) );
}
}
- 1 回答
- 0 关注
- 172 浏览
添加回答
举报