我在WooCommerce templates/emails/customer-invoice.php
文件中得到了解決方案。我正在尋找的功能是get_checkout_payment_url()
。
使用
$order = wc_get_order($order_id);
$pay_now_url = esc_url($order->get_checkout_payment_url());
echo $pay_now_url; //http://example.com/checkout/order-pay/{order_id}?pay_for_order=true&key={order_key}
//http://example.com will be site_url and protocol will depending upon SSL checkout WooCommerce setting.
但這個網址只適用於pending
,failed
訂單狀態;所以我使用的過濾器woocommerce_valid_order_statuses_for_payment
if (!function_exists('filter_woocommerce_valid_order_statuses_for_payment')) {
//http://woocommerce.wp-a2z.org/oik_api/wc_abstract_orderneeds_payment/
//http://hookr.io/filters/woocommerce_valid_order_statuses_for_payment/
// define the woocommerce_valid_order_statuses_for_payment callback
function filter_woocommerce_valid_order_statuses_for_payment($array, $instance) {
$my_order_status = array('cancelled', 'transaction-declined');
return array_merge($array, $my_order_status);
}
// add the filter
add_filter('woocommerce_valid_order_statuses_for_payment', 'filter_woocommerce_valid_order_statuses_for_payment', 10, 2);
}
^^我說這在我的活動主題的functions.php
文件。
參考:
這是非常有用......好球:) – LoicTheAztec
感謝@LoicTheAztec,我已經爲這場鬥爭中,所以認爲在SO中貢獻這個,所以別人會從中受益。 –