2016-11-30 117 views
1

我想要從客戶可以直接支付他們的發票的URL,也應該與wc-cancelledwc-transaction-declined定製訂單狀態)一起使用。如何在WooCommerce中獲得帶有自定義訂單狀態的Pay Now URL?

我的解決方案
我在做什麼,現在創建一個自定義頁面與我的自定義參數獲取和處理整個付款流程在網關供應商網站的文檔。

我的問題
但問題是,每當他們更新有doc文件和插件,我也有更新我的代碼;但是如果我獲得了Pay Now URL,那麼WooCommerce和Gateway Plugin將負責處理它。

有沒有更好的解決方案?

回答

2

我在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. 

但這個網址只適用於pendingfailed訂單狀態;所以我使用的過濾器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文件。


參考:

+1

這是非常有用......好球:) – LoicTheAztec

+1

感謝@LoicTheAztec,我已經爲這場鬥爭中,所以認爲在SO中貢獻這個,所以別人會從中受益。 –