Woocommerce使用运输包裹拆分订单

时间:2019-01-13 02:18:46

标签: php wordpress woocommerce

我希望对运输包装如何与Woocommerce结合使用有所了解。

我有一个站点,我们希望根据该站点(最初)根据订单分类。目前,根据Jeroen Sormani在他的博客上创建的代码,我已经实现了将多种送货方式添加到结帐中,并且现在也是一个插件。

我的主要问题是,由于下面的代码已经具有与每个包装相关的相关订单项和运输方式,每个包装可以用于生成新订单吗?还是子订单?

//////////// SPLIT SHIPPING METHODS BY CLASS

function custom_split_shipping_packages_shipping_class( $packages ) {
// Reset all packages
$packages              = array();
$regular_package_items = array();
$split_package_items   = array();
$split_shipping_class = 'pharma-product'; // Shipping class slug
foreach ( WC()->cart->get_cart() as $item_key => $item ) {
    if ( $item['data']->needs_shipping() ) {
        if ( $split_shipping_class == $item['data']->get_shipping_class() ) {
            $split_package_items[ $item_key ] = $item;
        } else {
            $regular_package_items[ $item_key ] = $item;
        }
    }
}
// Create shipping packages
if ( $regular_package_items ) {
    $packages[] = array(
        'contents'        => $regular_package_items,
        'contents_cost'   => array_sum( wp_list_pluck( $regular_package_items, 'line_total' ) ),
        'applied_coupons' => WC()->cart->get_applied_coupons(),
        'user'            => array(
             'ID' => get_current_user_id(),
        ),
        'destination'    => array(
            'country'    => WC()->customer->get_shipping_country(),
            'state'      => WC()->customer->get_shipping_state(),
            'postcode'   => WC()->customer->get_shipping_postcode(),
            'city'       => WC()->customer->get_shipping_city(),
            'address'    => WC()->customer->get_shipping_address(),
            'address_2'  => WC()->customer->get_shipping_address_2()
        )
    );
}
if ( $split_package_items ) {
    $packages[] = array(
        'contents'        => $split_package_items,
        'contents_cost'   => array_sum( wp_list_pluck( $split_package_items, 'line_total' ) ),
        'applied_coupons' => WC()->cart->get_applied_coupons(),
        'user'            => array(
             'ID' => get_current_user_id(),
        ),
        'destination'    => array(
            'country'    => WC()->customer->get_shipping_country(),
            'state'      => WC()->customer->get_shipping_state(),
            'postcode'   => WC()->customer->get_shipping_postcode(),
            'city'       => WC()->customer->get_shipping_city(),
            'address'    => WC()->customer->get_shipping_address(),
            'address_2'  => WC()->customer->get_shipping_address_2()
        )
    );
}
return $packages;
}
add_filter( 'woocommerce_cart_shipping_packages', custom_split_shipping_packages_shipping_class' );`

只要能帮助您,了解其潜力(或没有潜力)。

问候 特里

0 个答案:

没有答案