Woocommerce订阅在Wordpress / Woocommerce交互中包含Webhook,允许在创建或修改订阅时触发,但在完成订阅付款时不会触发。
可用的触发器包括subscription.created和subscription.updated,但这些触发器仅在付款处理器返回已付款状态之前触发。当前,该触发器会在按下“购买”按钮时触发,这意味着无法知道某人是否付款。
有很多方法可以实现,但是我不知道从哪里开始实现以及如何实现。他们来了; woocommerce_subscription_payment_complete woocommerce_subscription_renewal_payment_complete woocommerce_subscription_payment_failed woocommerce_subscription_renewal_payment_failed
文档在这里https://docs.woocommerce.com/document/subscriptions/develop/action-reference
class WCS_Webhooks {
/**
* Setup webhook for subscriptions
*
* @since 2.0
*/
public static function init() {
add_filter( 'woocommerce_webhook_topic_hooks', __CLASS__ . '::add_topics', 20, 2 );
add_filter( 'woocommerce_webhook_payload', __CLASS__ . '::create_payload', 10, 4 );
add_filter( 'woocommerce_valid_webhook_resources', __CLASS__ . '::add_resource', 10, 1 );
add_filter( 'woocommerce_valid_webhook_events', __CLASS__ . '::add_event', 10, 1 );
add_action( 'woocommerce_checkout_subscription_created', __CLASS__ . '::add_subscription_created_callback', 10, 1 );
add_action( 'woocommerce_subscription_date_updated', __CLASS__ . '::add_subscription_updated_callback', 10, 1 );
add_action( 'woocommerce_subscriptions_switch_completed', __CLASS__ . '::add_subscription_switched_callback', 10, 1 );
add_filter( 'woocommerce_webhook_topics' , __CLASS__ . '::add_topics_admin_menu', 10, 1 );
add_filter( 'wcs_new_order_created', __CLASS__ . '::add_subscription_created_order_callback', 10, 1 );
}
付款完成后,我将如何构建其他触发器以触发?