gpt4 book ai didi

wordpress - 下单后设置下一个续订付款日期的最可靠 Hook

转载 作者:行者123 更新时间:2023-12-04 12:55:19 26 4
gpt4 key购买 nike

我们在 Woocommerce 订阅设置中遇到了默认同步选项不起作用的情况。我创建了一个手动日历,我的 functions.php在订阅创建时引用文件,但它只在订阅创建时检查,然后插件会自动将下一次续订设置为每 4 周一次。
每次订阅创建后,我都需要启动续订日期检查器功能 和/或 续订以从我的日历中计算下一个续订日期。我知道至少有两个钩子(Hook)可以尝试,分别是:wcs_renewal_order_createdwoocommerce_subscription_payment_complete ,但我不知道什么时候触发那些是最安全的。
关于 woocommerce_subscription_payment_complete ,WC 订阅文档说:

Triggered when a payment is made on a subscription. This can be payment for the initial order or a renewal order. It is important to note, however, that subscription date changes related to early renewals are processed differently than other renewals, so this action should not be relied upon for capturing the next payment date on a subscription.


我不能 100% 确定他们在笔记中指的是什么情况,但这足以让我停下来。
关于 wcs_renewal_order_created ,我不清楚何时触发:

These orders are always created through the wcs_create_renewal_order() function, regardless of whether they are created for a scheduled renewal event, manually via the WooCommerce > Edit Subscription administration screen, or via the Subscriptions endpoints for the WooCommerce REST API. Because of this, it’s possible to add, remove or update the value of anything on that renewal order using this filter.


For example, this can be used to add a discount to specific renewal orders, like the 12th order each year. It could also be used to add one-time fee for a certain renewal order, like a special annual extra fee on a monthly subscription.


会尝试设置 next_date key 通过 update_dates()在此 Hook 期间推送当前付款即将处理或已经发生,因此设置下一个日期现在是安全的?
在为给定订阅处理当前期间后,立即以编程方式设置下一个续订日期的最可靠方法是什么?

最佳答案

免责声明:我分享了我的推理和初步信息,我没有做任何实际检查。
根据描述,两个钩子(Hook)都与所需的事件无关:wcs_renewal_order_created响应订阅订单的创建,以及 woocommerce_subscription_payment_complete响应此类订单的付款。但是这两点都对创建或更新订阅的“簿记原理”负责,而不是创建或更新本身。
我建议测试 woocommerce_helper_subscription_activate_success Hook ,可在 class-wc-helper.php 中找到:

/**
* Active a product subscription.
*/
private static function _helper_subscription_activate() {

// ...

if ( $activated ) {
/**
* Fires when the Helper activates a product successfully.
*
* @param int $product_id Product ID being activated.
* @param string $product_key Subscription product key.
* @param array $activation_response The response object from wp_safe_remote_request().
*/
do_action( 'woocommerce_helper_subscription_activate_success', $product_id, $product_key, $activation_response );
} else {

// ...
看起来这个钩子(Hook)响应订阅成功的那一刻。并且有可能这不仅意味着订阅的初始激活时刻,还意味着其随后的续订。
这可以通过以下代码完成,例如:
function test_woocommerce_helper_subscription_activate_success( $product_id, $product_key, $activation_response ) { 
// your code here
}
add_action('woocommerce_helper_subscription_activate_success', 'test_woocommerce_helper_subscription_activate_success', 10, 3);

关于wordpress - 下单后设置下一个续订付款日期的最可靠 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68194953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com