保存订单元Woocommerce

时间:2014-10-01 08:23:25

标签: woocommerce save meta orders

我有neoc版本的woocommerce 2.2.4。 我希望在订单中创建一个新字段以显示总重量,我试试这个:

add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');

function my_custom_checkout_field( $checkout ) {
    global $woocommerce;

echo '<div id="my_custom_checkout_field"><h3>'.$weight = $woocommerce->cart->cart_contents_weight+1.100, ' Kg</h3>';

woocommerce_form_field( 'my_field_name', array(
'type' => '',
'class' => array('my-field-class orm-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => $weight,
), $checkout->get_value( 'my_field_name' ));
echo '</div>';

}
add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');

function custom_checkout_field_update_order_meta( $order_id ) {
    if ($_POST['my_field_name']) update_post_meta( $order_id, 'weight', esc_attr($_POST['my_field_name']));

}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );

function my_custom_checkout_field_display_admin_order_meta($order){
    echo '<p><strong>'.__('weight').':</strong> ' . $order->order_custom_fields['weight'][0] . '</p>';
}

我的div显示重量但不保存在订单中? 哪里有问题? 感谢的

0 个答案:

没有答案