How to add a payment date field to womerce

The check-out page of many online stores requires custom fields. For example, the checkout page of a cake shop may require a delivery date field. The advantage of woocommerce is that you can add custom fields on the checkout page, such as after the payment and delivery fields or in front of the order button. Add a date field to woocommerce checkout this post will learn how to add a delivery date field to the woocommerce payment page. I want to add it after the settlement field. This field allows the customer to select the delivery date for the order. You can also share the display of custom fields on the email notification and order receiving pages.
1. Add a custom date field on the woocommerce payment page. Woocommerce allows you to add custom fields in different locations according to the hook to be used. The checkout page contains a large number of tasks defined by woocommerce. This guide adds a field after the billing or shipping address field. To add custom fields here, use the woomerge_after_checkout_billing_form action. functions. Add the following code to the PHP file: add_action( ‘woocommerce_after_checkout_billing_form’, ‘njengah_extra_fields_after_billing_address’ , 10, 1 );
Function njengah_extra_fields_after_billing _address (){
_E (\
?>

The customer must select a delivery date for the order. That is, you must add a calendar to this field. Alternatively, you can try and keep it simple with simple text fields. Use the jQuery date selector. That is, you must use the WordPress wp_enqueue_scripts action to include the required JavaScript and CSS files. add_action( ‘woocommerce_after_checkout_billing_form’, ‘display_extra_fields_after_billing_address’ , 10, 1 );
Display_extra_fields_after_billing _address (){
_E (\
?>
<?php

} 결과는 다음과 같습니다.

JQuery (document). Ready (function ($){
$( \
Minimum date: 0,
} );
} );

How the code works I attached the display_extra_fields_after_billing_address() function to the woocomer task. First, print a label called \
After adding the above code segment, the custom field will be displayed under the invoice receiving address field. 2. Display custom fields in email notification. The next step is to add custom fields to display in customer email. functions. Add the following code to the PHP file: add_action( ‘woocommerce_checkout_update_order_meta’, ‘add_order_delivery_date_to_order’ , 10, 1);
Function add_order_delivery
_date_to_order ( $order_id ) {
if ( isset( $_POST [‘add_delivery_date’] ) && ” != $_ POST [‘add_delivery_date’] ) {
add_post_meta( $order_id, ‘_delivery_date’, Sanitize_text_field( $_POST [‘add_delivery_date’] ) );
}
}How the code works, I attached the add_order_delivery_date_to_order() function to the woocommerce action. Add the delivery date to the post meta table. Before adding a date to the database, make sure that the customer has selected a date.
If the customer selects a date, it will be saved in the wp_posteta table using the WordPress function add_post_meta(). This function requires post_id, meta key and meta value. In our case, the order ID is used as post_id, the meta key is _delivery_date, and the meta value is the delivery date selected by the customer$_ It is recommended to delete the post variable data. Removes line breaks, tabs, and additional spaces from the string. Save the delivery date to the database and display it in the customer email. functions. Add the following code to the PHP file:
add_filter( ‘woocommerce_email_order_meta_fields’, ‘add_delivery_date_to_emails’ , 10, 3 );
Function add_delivery_date_to_mails ($fields, $sent_to_admin, $order){
if( version_compare( get_option( ‘woocommerce_version’ ), ‘3.0.0’, \
$order_id = $order->get_id();
}Another{
$order_id = $order->id;
}
$delivery_date = get_post_meta( $order_id, ‘_delivery_date’, true );
if ( ” != $delivery_date ) {
$fields [\
\
\
);
}
Return the $field;
} 3. Display custom fields on the woocommerce audit page. Display custom fields on the woocommerce order received page. Use the woocommerce filter woocommerce_order_details_after_order_table. functions. Add the following code to the PHP file:
<?php

}

add_action( 'wp_enqueue_scripts', 'enqueue_datepicker' );

함수 enqueue_datepicker() {

if ( is_checkout() ) {

// datepicker 스크립트를 로드합니다(WordPress에 사전 등록됨).

wp_enqueue_script( 'jquery-ui-datepicker' );

// 날짜 선택에 대한 스타일 지정이 필요합니다. 단순화를 위해 Google에서 호스팅하는 jQuery UI CSS에 연결했습니다.

wp_register_style( 'jquery-ui', '//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css');

wp_enqueue_style( 'jquery-ui' );

}

} 결과는 다음과 같습니다. add_filter( ‘woocommerce_order_details_after_order_table’, ‘add_delivery_date_to_order_received_page’, 10 , 1 );
Function add_delivery_date_to_order_receive_page{
if( version_compare( get_option( ‘woocommerce_version’ ), ‘3.0.0’, \
$order_id = $order->get_id();
}Another{
$order_id = $order->id;
}
$delivery_date = get_post_meta( $order_id, ‘_delivery_date’, true );
if ( ” != $delivery_date ) {
Eco“

”__ (\
}
}The results are as follows:
How the code works I attach add_delivery_date_to_order_receive_page() to the ukmouth filter. Li Han
Methods the method of moving the basic menu store foreground woocommerce. If it can be delivered free of charge, how to hide the delivery fee, how to add the woocommerce invoice settlement page, how to add additional fields in the woocommerce settlement form, how to add the woocommerce checkout basic national anthem, and how to hide the woocommerce Title

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *