当用户更改邮政编码时,我在更新woocommerce结帐时的送货方式时遇到问题。 我使用woocommerce_checkout_update_order_review(standart woocommerce ajax action)获取邮政编码,并将其和产品从购物车发送到货运。此API可以返回大量的送货方式: http://b2b.freightquote.com/documents/Freightquote_API_Programmers_Reference.pdf (3分)
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);
}
方法列表有超过24个选项(每次更改邮政编码后,列表都可以更改)
将$ output XML解析为数组后,方法如下:
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
)
)
)
)
)
如何在更改zip后动态添加这些方法?我无法创建所有类,每次都可以更改方法列表。现在我有24种方法用于我当前的查询。