gpt4 book ai didi

php - 在 WooCommerce 上添加支付订单按钮我的帐户查看待处理订单的订单

转载 作者:行者123 更新时间:2023-12-04 08:00:06 25 4
gpt4 key购买 nike

当订单状态为 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>';

}


}

最佳答案

尝试以下简化代码版本,它将显示挂单的支付订单按钮:

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 );

if ( $order->get_status() == "pending" ) {
printf(
'<a class="woocommerce-button button pay" href="%s/order-pay/%s/?pay_for_order=true&key=%s">%s</a>',
wc_get_checkout_url(), $order_id, $order->get_order_key(), __("Pay for this order", "woocommerce")
);
}
}
代码位于事件子主题(或事件主题)的 functions.php 文件中。测试和工作。

关于php - 在 WooCommerce 上添加支付订单按钮我的帐户查看待处理订单的订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66518859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com