如何在WooCommerce中获取具有自定义订单状态的“立即付款" URL? [英] How to get Pay Now URL with custom order status in WooCommerce?

查看:221
本文介绍了如何在WooCommerce中获取具有自定义订单状态的“立即付款" URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从客户那里直接获取其发票的URL,它也应与wc-cancelledwc-transaction-declined(自定义订单状态)一起使用.

I want to get the URL from where Customer can directly pay for their Invoice and also it should work with wc-cancelled and wc-transaction-declined (custom order status).

我的解决方案
我现在正在做的是创建一个自定义页面,其中包含我的自定义get参数,并将整个付款过程作为网关提供商网站中的文档进行处理.

My Solution
What I'm doing now is created a custom page with my custom get parameters and processing the whole Payment Process as Documentation in Gateway provider Website.

我的问题
但是问题是,每当他们更新文档文件和插件时,我也必须更新代码.但是如果我得到了Pay Now URL,则WooCommerce和Gateway Plugin会处理它.

My Problem
But the problem is whenever they update there doc file and plugin I also have to update my code; but if I get the Pay Now URL then WooCommerce and Gateway Plugin will take care of it.

有更好的解决方案吗?

推荐答案

我在WooCommerce templates/emails/customer-invoice.php文件中找到了解决方案.我一直在寻找的功能是get_checkout_payment_url().

I got the solution in WooCommerce templates/emails/customer-invoice.php file. The function that I was looking for is 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

But this url only works with pending, failed order status; So I used filter 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文件中.

^^ I added this in my active theme's functions.php file.

参考:

  • get_checkout_payment_url()
  • wc_abstract_orderneeds_payment
  • woocommerce_valid_order_statuses_for_payment

这篇关于如何在WooCommerce中获取具有自定义订单状态的“立即付款" URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆