【发布时间】:2021-06-05 16:29:49
【问题描述】:
当订单状态为pending时如何创建“为此订单付款”按钮,以便在查看订单时显示在我的帐户页面上
链接结构如下:
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>';
}
}
【问题讨论】:
标签: php wordpress woocommerce payment orders