私はwoocommerce 2.2.4のnexバージョンを持っています。総重量を表示するために新しいフィールドを作成したいので、これを試してください:
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は正確に体重を表示しますが、順番に保存されませんか? どこに問題がありますか?ありがとう