You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should add a method to automatically sort items into parcels with a weight below a given limit.
This method should be automatically fired when an order is placed. It will split the items into parcels and then save the configuration in the order meta data.
That way it will be used whether or not the webshop over creates labels automatically, via bulk or via order details.
Example
/*
* Function to split items into parcels
*
* This function can be run any time you like, as long as it happens before creating a label with Smart Send
*
*/
public function split_items_into_parcels($order) {
$packaging_weight = 0.5;//TODO: packaging_weight should be a setting
$max_parcel_weight_excluding_packaging = 20;//TODO: max_box_weight should be a setting
$max_parcel_weight_including_packaging = $max_parcel_weight_excluding_packaging + $packaging_weight;
$parcels = array();//Array that will contain parcels and items
$package_count = 1;
foreach( $order->get_items() as $item ) {
if( $item['product_id'] > 0 ) {
$_product = $order->get_product_from_item( $item );
if ( !$_product->is_virtual() ) {
for ($x = 1; $x <= $item['qty']; $x++) {//TODO: Find a better way to "split" the different items. They should be divided into as few parcels as possible
if( $weight + $_product->get_weight() > $max_parcel_weight_including_packaging ){
//Create a new package
$package_count++;
$weight = $packaging_weight + $_product->get_weight();
} else {
$weight += $_product->get_weight();
}
// Add item
$parcels[] = array(
'id' => $_product['product_id'],//TODO: account for variation_id see line 204 @ smart-send-logistics/includes/class-ss-shipping-wc-order.php
'name' => $_product['name'],
'value' => $box_count,
);
}
}
}
}
// This is where we save the parcel/item configuration
SS_SHIPPING_WC()->get_ss_shipping_wc_order()->save_ss_shipping_order_parcels($order_id, $parcels);
//It can also be done manually using: update_post_meta($order_id, 'ss_shipping_order_parcels', $parcels);
}
The text was updated successfully, but these errors were encountered:
We should add a method to automatically sort items into parcels with a weight below a given limit.
This method should be automatically fired when an order is placed. It will split the items into parcels and then save the configuration in the order meta data.
That way it will be used whether or not the webshop over creates labels automatically, via bulk or via order details.
Example
The text was updated successfully, but these errors were encountered: