I have an issue to update shipping methods on woocommerce checkout, when user change zip code. I use woocommerce_checkout_update_order_review (standart woocommerce ajax action) to get ZIP code, and send it and products from cart to freightquote. This API can return big list of shipping methods: http://b2b.freightquote.com/documents/Freightquote_API_Programmers_Reference.pdf (3 point)
add_action( 'woocommerce_checkout_update_order_review', 'freightquote_get_methods' );
function freightquote_get_methods( $data ){
$Zip = /*billing_postcode from $data*/
$xml = /*some xml for api with $Zip, products etc.*/
$ch = curl_init('https://b2b.freightquote.com/WebService/QuoteService.asmx?WSDL');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch); //xml with methods if success
curl_close($ch);
}
list of methods has more than 24 options (list can change every time after changing zip code in checkout form)
after parsing $output XML to an array, methods looks like:
Array
(
[0] => Array
(
[CarrierOptionId] => 1
[CarrierName] => Frontline Freight (Consolidated Services)
[SCAC] => FCSY
[DOTNumber] => 2215162
[QuoteAmount] => 332.95
[Currency] => USD
[IsGuaranteed] => false
[IsTMS] => false
[IsInterline] => false
[Transit] => 7
[TariffMultiplier] => 1
[Mode] => Inter Direct
[ProviderList] => Array
(
)
[CarrierAccessorials] => Array
(
[Accessorial] => Array
(
[0] => Array
(
[AccessorialId] => 158
[AccessorialDescription] => Fuel surcharge
[AccessorialCharge] => 69.41
)
[1] => Array
(
[AccessorialId] => 423
[AccessorialDescription] => ARBITRARY ORIGIN CHARGE
[AccessorialCharge] => 20
)
)
)
)
)
how to add those methods dynamically after changing zip? i cant create all classes, list of methods can change every time. right now i have 24 methods for my current query.