Skip to content

Instantly share code, notes, and snippets.

@hedqvist
Created March 13, 2020 08:53
Show Gist options
  • Select an option

  • Save hedqvist/c3370b65aa6505bc0f5c72d9862cc0cb to your computer and use it in GitHub Desktop.

Select an option

Save hedqvist/c3370b65aa6505bc0f5c72d9862cc0cb to your computer and use it in GitHub Desktop.
Unifaun - Weight depending on service
<?php
/**
* @snippet WooCommerce - Adds Default weight to parcel depending on service
* @author Redlight Media AB / Christopher Hedqvist
* @compatible WooCommerce 3.5.3
*/
function redlight_unifaun_minimum_weight_per_service( $shipment, $order) {
foreach( $shipment['parcels'] as $i => $parcel ) {
if( $shipment['parcels'][$i]['weight'] < 0.150 && 'PUA' === $shipment['service']['id'] ){
$shipment['parcels'][$i]['weight'] = 0.150;
}
if( $shipment['parcels'][$i]['weight'] < 1.0 && 'ASPO' === $shipment['service']['id'] ){
$shipment['parcels'][$i]['weight'] = 1.0;
}
}
return $shipment;
}
add_filter('ac_wc_unifaun_shipment_data', 'redlight_unifaun_minimum_weight_per_service', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment