我正在开发一种新的送货方式,根据包装重量,数量和客户邮政编码计算费率……
我在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' ] );
}