Firstly let me say i currently know nothing about php. I am hoping that changes soon.
I am assisting with a friend who has bought a plugin that calculates shipping based on individual product weight/dimensions based on integers for each.
The problem exists that most of the products are fractions of a kg (the width/length/height thing doesnt matter as its only mm) but the plugin requires everything to be based on whole kg. And calculates each item individually (as far as I can tell from the attached code.) This creates a major distinction with the pricing from the courier’s site to the tune of 3-4000 % prices gaps. Most of the products are between 0-100g, not kg.
public function calculate_shipping($package = array()) { global $woocommerce;
$address['suburb'] = $package['destination']['city'];
$address['state'] = $package['destination']['state'];
$address['postcode'] = $package['destination']['postcode'];
$address['country'] = $package['destination']['country'];
$i = 0;
$products = array();
foreach ( $package['contents'] as $item_id => $values ) {
$_product = $values['data'];
$q = 1;
while($values['quantity']>=$q) {
$products[$i]->length = $_product->get_length();
$products[$i]->height = $_product->get_height();
$products[$i]->width = $_product->get_width();
$products[$i]->weight = $_product->get_weight();
$q++;
$i++;
}
}
$items = $woocommerce->cart->cart_contents_count;
$weight = $woocommerce->cart->cart_contents_weight;
$sizes['weight'] = $weight;
$sizes['height'] = $height;
$sizes['length'] = $length;
$sizes['width'] = $width;
What I am hoping for is someone to help me.
- allow the whole of cart weight (and dimensions if applicable as well) to be calculated at the end of the cart, after a rounding up
- stop the “each product” call that seems to be occurring.
or at least point me in the right direction as to HOW to do this myself.
Thanks in advance.
SeanB