0
woocommerce 제품 메모를 저장하기 위해 textarea 필드를 만들었습니다. 장바구니에 담긴 제품 메모가있는 경우이 메모를 관리자 주문으로 저장하고 싶습니다. Woocommerce 제품 메모 추가 주문 메타
woocommerce 제품 메모를 저장하기 위해 textarea 필드를 만들었습니다. 장바구니에 담긴 제품 메모가있는 경우이 메모를 관리자 주문으로 저장하고 싶습니다. Woocommerce 제품 메모 추가 주문 메타
확인
// WooCommerce Products Custom Field
add_action('woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields');
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Textarea Field
\t woocommerce_wp_textarea_input(
\t \t array(
\t \t \t 'id' => 'product_notes',
\t \t \t 'label' => __('Product Notes', 'woocommerce'),
\t \t \t 'placeholder' => 'Enter product notes here.',
\t \t \t 'desc_tip' => 'true',
\t \t \t 'description' => __('Enter product notes here.', 'woocommerce')
\t \t)
\t);
echo '</div>'; \t
}
// Save Product notes
add_action('woocommerce_process_product_meta', 'woo_add_custom_general_fields_save');
function woo_add_custom_general_fields_save($post_id){
\t // Textarea
\t $woocommerce_textarea = $_POST['product_notes'];
\t if(!empty($woocommerce_textarea))
\t \t update_post_meta($post_id, 'product_notes', esc_html($woocommerce_textarea));
}
add_action('woocommerce_checkout_update_order_meta', 'custom_product_notes_order_meta', 10, 2);
function custom_product_notes_order_meta($order_id) {
\t global $woocommerce;
\t $i=1; //product counter
\t foreach ($woocommerce->cart->get_cart() as $cart_item_key => $cart_item) {
\t $product_id = $cart_item['product_id']; \t
\t $product_note = 'product_notes_'.$i++;
\t if(!empty(get_post_meta($product_id, 'product_notes', true))){
\t \t $product_notes = get_post_meta($product_id, 'product_notes', true);
\t \t add_post_meta($order_id, $product_note, $product_notes);
\t }
\t }
}