Как добавить примечание в кассе WooCommerce?

Adding a note in checkout on WooCommerce is easy!

First, add the following code to your functions.php file:

add_action( "woocommerce_after_order_notes", "custom_checkout_field" );

function custom_checkout_field( $checkout ) {

echo "<div id="custom-checkout-field">";

WooCommerce_form_field( "order_comments", array(
"type" => "textarea",
"class" => array("my-field-class form-row-wide"),
"label" => __("Order Notes"),
"placeholder" => __("Notes about your order, e.g. special instructions"),
), $checkout->get_value( "order_comments" ));

echo "</div>";
}

This code adds a new field to the checkout page where customers can leave notes about their order.

PRO TIP: Adding a note in Checkout WooCommerce can be tricky and may cause unexpected results. Be sure to test thoroughly before using on a live site.

Next, add the following code to your functions.php file:

add_action( "woocommerce_checkout_update_order_meta", "custom_checkout_field_update_order_meta" );

function custom_checkout_field_update_order_meta( $orderID ) {
if ( ! empty( $_POST["order_comments"] ) ) {
update_post_meta( $orderID, "Order Comments", sanitize_textarea_field( $_POST["ordernotes"] ) ); } }

Этот код сохраняет данные из пользовательского поля оформления заказа в метаданные заказа.

Теперь, когда покупатель добавляет примечание к своему заказу, вы сможете увидеть его на странице деталей заказа и в админке заказа.

Как добавить примечание в кассу WooCommerce?.

Вкратце, вам нужно добавить новое поле на страницу оформления заказа, а затем сохранить данные в метаданных заказа.