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 關注
- 219 瀏覽
添加回答
舉報