我已经为我的WooCommerce 3在线商店找到了许多有用的代码段。
说明/示例
如果客户购买10件商品,而只有7件商品可用,他可以选择(通过选择字段)部分运送订单。如果选择了“ Ja,teilliefern”选项,则运费应收取两次。
下面是我当前的代码:
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 );
}