我正在开发一种新的运输方式,它根据包裹重量、体积和客户邮政编码计算费率... 我在 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 ) {
//remove the first bracket at the end of $postal_code
$postal_code = $package[ 'destination' ][ 'postcode' ];
}
关于php - Woocommerce:获取运输邮政编码以计算运费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935918/