本文介绍了WooCommerce:获取和设置运输 &账单地址的邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在woocommerce中设置/获取邮政编码(邮政编码)?有这个功能吗?
How do I set/get the Postcode(Zip-code) in woocommerce? Is there a function for this?
即,我可以通过任何功能设置邮政编码吗?
ie., can I set the zip code through any function?
我还想知道,如果用户未登录,如何使用我的数据(例如 546621)填充此字段?
I would also like to know, how to populate this field with my data(say 546621) if the user is not logged in?
推荐答案
您可以执行以下操作来获取/设置帐单/送货邮政编码,
You can do the following to get/set billing/shipping postcodes,
要设置值,
$customer = new WC_Customer();
$customer->set_postcode('123456'); //for setting billing postcode
$customer->set_shipping_postcode('123456'); //for setting shipping postcode
如果您只想获取邮政编码,您可以从用户元表本身获取,
If you just want to fetch the postcodes, you can fetch it from the user meta table itself,
$shipping_postcode = get_user_meta( $current_user->ID, 'shipping_postcode', true );
$billing_postcode = get_user_meta( $current_user->ID, 'billing_postcode', true );
这篇关于WooCommerce:获取和设置运输 &账单地址的邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!