【发布时间】:2019-12-28 15:03:51
【问题描述】:
对WC() 的调用未在WC()->customer 中返回所需的值,结果为空。
我使用的示例代码是:
$customer = new WC_Customer( $customer_id );
$country = $customer->get_shipping_country();
if ( $country ) {
WC()->customer->set_location( $country, $state, $postcode, $city );
WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
}
任何帮助将不胜感激。
【问题讨论】:
-
请不要根据我的回答更改您的问题代码。您应该保留原始问题代码。您可以在我的答案下方的评论区中给我一个反馈,我将不胜感激。
-
@LoicTheAztec 将 woocommerce 从 3.5.3 更新到 3.7 后,我面临许多问题,例如为客户、运输、购物车等获取空 wc() 对象……而不是仅在客户中……紧急帮助需要。
-
所以这是一个你应该在 Github Woocommerce 中报告的错误......所以正如我在答案末尾评论的那样,你最好恢复到稳定的 WooCommerce 3.6.x 版本。 3.7 版相当新,并且在新的主要版本发布时仍然存在很多错误。此外,在更新生产网站之前,您应该始终在舞台网站上测试主要更新。
-
@LoicTheAztec 我有一段时间没有更新 woocommerce 了......而且我的 3.6.5 版本中也存在问题......仅在通过 rest api 调用时......你能告诉我吗像以前一样使用 wc() 有什么问题
-
Sorry rest Api 非常复杂,具体取决于您使用的版本和使用方式……现在一般
WC()主要用于前端。您可以尝试旧方法,即:global $woocommerce;与$woocommerce->customer或$woocommerce->cart。例如,我注意到有些方法适用于new WC_Customer( $user_id );,但不适用于WC()->customer...
标签: php wordpress object methods woocommerce