【发布时间】:2017-07-19 16:54:18
【问题描述】:
在 Woocommerce 中,我想在第一次创建订单之前在 "checkout" 页面上隐藏 "paypal" 网关,只显示 “货到付款” 网关(标记为预留)。
另一方面,当订单状态为“待处理”时,在结账/订单支付页面,隐藏'Reserve'网关并显示”贝宝”。 (当我们手动将订单状态更改为“待处理”并通过付款链接将发票发送给客户时,就会发生这种情况。
我认为应该通过检查订单状态并使用 woocommerce_available_payment_gateways 过滤钩子来完成。但是我在获取当前订单状态时遇到了问题。
此外,我不确定用户在结帐页面上新创建的订单的状态是什么,但该订单仍未显示在管理后端。
这是我不完整的代码:
function myFunction( $available_gateways ) {
// How to check if the order's status is not pending payment?
// How to pass the id of the current order to wc_get_order()?
$order = wc_get_order($order_id);
if ( isset($available_gateways['cod']) && /* pending order status?? */ ) {
// hide "cod" gateway
} else {
// hide "paypal" gateway
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'myFunction' );
我也尝试了WC()->query_vars['order'] 而不是wc_get_order(); 到get the current order 并检查了它的状态,但它也没有用。
我sawwoocommerce_order_items_table动作钩子,但也拿不到订单。
如何在结帐/订单支付页面上检索订单 ID 和状态?
【问题讨论】:
标签: php wordpress woocommerce checkout orders