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

查看:62
本文介绍了“付款完成后"的 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.

如何设置 PAYPAL 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. 登录支付宝
  2. 点击右上角的小脸图标
  3. 点击个人资料和设置"
  4. 点击左侧边栏中的我的销售工具"
  5. 找到即时付款通知"并点击更新"
  6. 启用它们并设置网址.您的 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 的精彩WooCommerce 自动完成订单 插件.请务必设置正确的设置(将显示在 WooCommerce 设置中的Woo 额外选项"选项卡下).

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天全站免登陆