I've found already many helpful code snippets for my WooCommerce 3 online shop.
Description/Example
If a customer buys 10 items and only 7 items are available he can choose (via a select field) to partially ship the order. If the option "Ja, teilliefern" is selected, the freight charges should be charged twice.
- At "regular shipping" 4,90 € -> 9,80 €
- At "free shipping" 0,00 € -> 4,90 €
Below is my current code:
add_filter( 'woocommerce_checkout_fields' , 'wp_bibel_de_add_checkout_fields' );
function wp_bibel_de_add_checkout_fields( $fields ) {
$fields['billing']['billing_phone'] = array(
'label' => 'Telefonnummer',
'placeholder' => 'Telefonnr.',
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
$fields['billing']['billing_delivery'] = array(
'type' => 'select',
'label' => 'Wünschen Sie eine Teillieferung der verfügbaren Artikel?',
'placeholder' => 'bitte auswählen...',
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
'options' => array(
' ' => ' ',
'ja' => 'Ja, teilliefern',
'nein' => 'Nein'
)
);
return $fields;
}
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'wp_bibel_de_add_custom_order_data', 10, 1 );
function wp_bibel_de_add_custom_order_data( $order ) {
echo get_post_meta( $order->id, '_billing_delivery', true );
}