2016-08-13 18 views
0

私は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)); 
 
}

答えて

1

[OK]を、私は解決策を見つけます。

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 } 
 
}

関連する問題