如何在订单状态为pending
时创建“Pay for This Order”按钮,以便在查看订单时显示在“My Account”页面上
链接结构如下:https://url.com/checkout/order-pay/XXXXX/?pay_for_order=true&key=wc_order_XXXXXXXXXXXX
add_action( 'woocommerce_view_order', 'order_pay_button' );
function order_pay_button( $order_id ){
// Get an instance of the `WC_Order` Object
$order = wc_get_order( $order_id );
// Get the order number
$order_number = $order->get_order_number();
// Get the order status name
$status_name = wc_get_order_status_name( $order->get_status() );
// Get the order key
$test_order_key = $order->get_order_key();
// Display the order status
echo '<div>' . __("Order Status:") . ' ' . $status_name . '</div>';
if ($status_name == "pending") {
echo '
<a href="https://url.com/checkout/order-pay/'.''.$order_number.''.'/?pay_for_order=true&key='.''.$test_order_key.''.'">
<button type="submit" class="button alt" id="place_order">Pay for this order</button></a>';
}
}
1条答案
按热度按时间shyt4zoc1#
尝试以下简化的代码版本,它将显示挂起订单的支付订单按钮:
代码放在活动子主题(或活动主题)的函数.php文件中。经过测试,效果良好。