php – Woocommerce:获取运输邮政编码以计算运费
作者:互联网
我正在开发一种新的送货方式,根据包装重量,数量和客户邮政编码计算费率……
我在calculate_shipping函数上检索购物车信息没有问题,但是当我尝试从客户检索邮政编码时,它似乎返回一个空值.
如何在运行时检索此信息以计算最终成本?
public function calculate_shipping( $package ) {
GLOBAL $woocommerce;
$items = $woocommerce->cart->get_cart();
$cliente = $woocommerce->customer;
$peso = $woocommerce->cart->cart_contents_weight;
$customer_postcode = $woocommerce->customer->get_shipping_postcode();
}
解决了:
$customer_postcode = get_user_meta(get_current_user_id(),’shipping_postcode’,true);
解决方法:
// add this in your calculate_shipping function
public function calculate_shipping( $package ) {
$postal_code = $package[ 'destination' ][ 'postcode' ] );
}
标签:shipping,php,wordpress,woocommerce 来源: https://codeday.me/bug/20190728/1560671.html