WooCommerce挂钩“付款后完成"行动 [英] WooCommerce hook for "after payment complete" actions

查看:452
本文介绍了WooCommerce挂钩“付款后完成"行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WooCommerce和Wordpress.我有一个自定义许可证密钥生成器,当有人通过WooCommerce成功购买我的插件时,我希望它生成许可证密钥.

I'm using WooCommerce and Wordpress. I have a custom license key generator, and I'd like it to generate a license key when someone successfully purchases my plugin through WooCommerce.

这看起来很简单:

  1. 用户在我的网站上完成结帐
  2. 用户被重定向到Paypal,在此输入他们的付款凭证
  3. Paypal告诉我的网站,付款已经完成
  4. 我加入了某种支付完成"或"order_complete" WooCommerce操作并生成了许可证.

这是问题所在:我真的不确定哪个钩子可以很好地工作. Woocommerce在其网站上列出了他们的整个钩子,但是实际上没有关于哪个钩子很好的文档为了什么.

Here's the problem: I'm really not sure what hook would work well for this. Woocommerce has their entire collection of hooks listed on their site, but virtually no documentation about which is good for what.

仅基于钩子名称,我认为woocommerce_payment_complete将是一个很好的操作.不幸的是,它似乎根本没有被解雇.我读过的一些地方说它从未被解雇过.

Based on just the hook names, I'd think that woocommerce_payment_complete would be a good action to use. Unfortunately it doesn't seem to be fired at all; some places I've read say that it isn't ever fired.

我还阅读了有关Paypal IPN的内容,但我不明白如何从中获取通知(是否连接到Woocommerce挂钩?)

I've also read something about Paypal IPN, but I don't understand how I could hook in to the notification from that (does that connect to a Woocommerce hook?)

简而言之,我想在验证付款后立即生成许可证密钥.为了实现这一目标,我应该迷上什么?

In short, I'd like to generate the license key as soon as the payment has been verified. What do I hook in to in order to achieve this?

推荐答案

好的,我提出了两种可能的解决方案.

Okay, I've come up with a couple possible solutions.

WooCommerce的Paypal Standard网关实际上已经支持内置在其中的Paypal的IPN服务.无论选择哪种挂机"路线,您都将要使用它.

WooCommerce's Paypal Standard gateway actually has support for Paypal's IPN service built right in to it. You'll want to use that regardless of the 'hook' route you choose.

如何设置贝宝IPN

Paypal IPN连接到作为收款人的任何帐户.例如,如果您通过myemail@gmail.com获得报酬,则需要使用该帐户设置IPN.所有IPN都是Paypal发出的付款完成!" (各种)通知到您选择的URL.为了选择您希望Paypal发送通知的网址,您需要执行以下步骤:

Paypal IPN is connected to whichever account is the receiver of the money. For example, if you're getting paid at myemail@gmail.com, then you need to set up IPN with that account. All IPN is, is Paypal sending out a "Payment Complete!" (of sorts) notification to the URL of your choice. In order to choose the url that you want Paypal to send the notice to, you need to do these steps:

  1. 登录到Paypal
  2. 单击右上角的小脸图标
  3. 点击个人资料和设置"
  4. 点击左侧栏中的我的销售工具"
  5. 找到即时付款通知",然后单击更新"
  6. 启用它们并设置URL.您的WooCommerce Paypal付款标准网关地址为: http://yoursite.com/?wc-api=WC_Gateway_Paypal (在WooCommerce的 Paypal标准文档中 ).
  7. 保存设置
  1. Log in to Paypal
  2. Click on the little face icon on the top right
  3. Click "Profile and settings"
  4. Click "My selling tools" in the left sidebar
  5. Find "Instant payment notifications" and click "Update"
  6. Enable them and set the url. Your WooCommerce Paypal Payments Standard gateway url is: http://yoursite.com/?wc-api=WC_Gateway_Paypal (which is noted in WooCommerce's Paypal Standard documentation).
  7. Save your settings

付款完成后,您的WooCommerce安装现在将收到Paypal的通知.哦,顺便说一句,请确保:

Your WooCommerce installation will now hear from Paypal when the payment is complete. Oh, and by the way, make sure that:

  • 您在Paypal设置中的收件人电子邮件"是正确的
  • 在服务器上启用了fsockopen(您可以在WooCommerce设置中检查此系统状态")

选项1:自动完成已完成付款的订单,并关联到woocommerce_order_status_completed进行特殊操作/功能

OPTION 1: Auto-complete orders that have completed payment and hook in to woocommerce_order_status_completed for your special actions/functions

为了使您的产品在完成验证付款后自动完成,您只需安装Mirko Grewing出色的

In order to get your products to auto-complete upon verified payment, you can simply install Mirko Grewing's fabulous WooCommerce Autocomplete Order plugin. Be sure to set the correct settings (which will appear under the "Woo Extra Options" tab in your WooCommerce settings).

现在,在验证付款后,您的订单将自动完成,您可以简单地挂接到您的完成挂钩woocommerce_order_status_completed,以实现您的特殊功能.

Now that your orders are being autocompleted when the payments are verified, you can simply hook in to your completion hook, `woocommerce_order_status_completed, for your special functionality.

该方法的好处是,如果允许您以完成的任何顺序进行挂接,无论您是手动完成还是自动完成.换句话说,它非常通用.

The benefit to that method is that if allows you to hook in any order that is completed--regardless of whether or not you manually completed it or it was automatically completed. In other words, it's pretty versatile.

选项2:插入woocommerce_payment_complete_order_status过滤器,这表示付款成功.

OPTION 2: Hook in to the woocommerce_payment_complete_order_status filter, which denotes a successful payment.

我想那是很不言自明的.这种方法的好处是,这几乎是整个过程的第一步,并且发生在上面的完成挂钩之前(如果您设置了适当的优先级).

I guess that one is pretty self-explanatory. The benefit to this method is that it's pretty much the first step in the whole process, and takes place prior to the completion hook above (if you have your priorities set appropriately).

我不知道一个人是否比另一个更好,但是他们俩似乎都达到了我的目标:在付款被验证后执行一项操作.

I don't know if one is better than the other, but they both seem to accomplish my goal: perform an action AFTER payment has been verified.

这篇关于WooCommerce挂钩“付款后完成"行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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