php - Woocommerce:获取运输邮政编码以计算运费

标签 php wordpress woocommerce shipping

我正在开发一种新的运输方式,它根据包裹重量、体积和客户邮政编码计算费率... 我在 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/

相关文章:

php - 无法使用 $_GET 请求从多个选择中获取值

php - 无法从 CodeIgniter 中的 SQL-View 选择

php - 如果在 Woocommerce 中付款失败,如何重新加载结帐页面

php - MySQLi 不更新我的查询

html - 如何消除页面上的空白

css - 向右移动重力提交按钮

php - 是否可以在 $post->post_content 中获取帖子内容的 Elementor 样式?

php - Woocommerce 添加到购物车按钮重定向到结帐

php - 如何在 WooCommerce 评论表单上添加 "Review title"字段?

php - 在每个大写单词前添加 <br>