触发特定订单状态时,会向购物者发送一封自定义电子邮件。我想在电子邮件中包含一个链接,以便他们为订单付款。
根据我目前的理解,付款URL应该类似于:
http://www.example.com/checkout/order-pay/[order number here]
以下是我发送电子邮件并生成付款URL的功能:
add_action("woocommerce_order_status_changed", "my_notification");
function my_notification($order_id) {
global $woocommerce;
$order = new WC_Order( $order_id );
if($order->status === \'prop\' ) {
//HERE IS THE ISSUE
$payment_page = get_permalink( woocommerce_get_page_id( \'pay\' ) ) . \'/order-pay/\' . $order->get_order_number();
// Create a mailer
$mailer = $woocommerce->mailer();
$message_body = __( \'My message to the shopper with payment <a href="\'.$payment_page.\'">link</a>\' );
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( \'Order %s received\' ), $order->get_order_number() ), $message_body );
// Send email
$mailer->send( $order->billing_email, sprintf( __( \'Order %s received\' ), $order->get_order_number() ), $message );
// Set status to pending payment
$order->update_status(\'pending\');
}
}
上面生成的URL与我期望的一样,但是当浏览到生成的URL时,我得到了Woocommerce错误:
抱歉,此订单无效,无法付款。
我也尝试过:
$checkout_url = $woocommerce->cart->get_checkout_url();
触发订单状态时,最终会出现致命错误:
对中的非对象调用成员函数get\\u checkout\\u url()。。。功能。php联机。。。
如何生成valid 订单的付款URL?
最合适的回答,由SO网友:Und3rTow 整理而成
生成付款URL的正确方法是:
get_checkout_payment_url()
因此,我的代码改为:
$payment_page = $order->get_checkout_payment_url();
将生成以下URL:
http://www.example.co.za/checkout/order-pay/[order-number]?pay_for_order=true&key=order_[order-key]
这就是我要找的。
Note that the order status must be set to unpaid or pending in order for the generated link to be valid