You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何覆盖WooCommerce Subscriptions支付重试规则避免插件更新重置

修改WooCommerce订阅支付重试规则(避免插件更新重置)

不要直接修改wp-content/plugins/woocommerce-subscriptions/includes/payment-retry/class-wcs-retry-rules.php这类插件核心文件——每次插件更新时,这些文件会被完全覆盖,你的修改会丢失。正确的做法是利用官方提供的wcs_default_retry_rules过滤器,在主题或自定义插件中自定义规则。

实现步骤

  1. 打开当前激活主题的functions.php文件,或者创建一个简单的自定义插件(更推荐,避免主题更新影响规则)
  2. 添加以下代码,自定义你的重试规则:
add_filter( 'wcs_default_retry_rules', 'custom_wcs_retry_rules' );
function custom_wcs_retry_rules( $default_rules ) {
    // 重置为自定义规则
    return array(
        array(
            'retry_after_interval'     => DAY_IN_SECONDS, // 24小时后重试
            'email_template_customer'  => '', // 不发送客户通知邮件
            'email_template_admin'     => 'WCS_Email_Payment_Retry', // 发送管理员重试通知邮件
            'status_to_apply_to_order' => 'pending', // 订单状态设为pending
            'status_to_apply_to_subscription' => 'on-hold', // 订阅状态设为on-hold
        ),
        array(
            'retry_after_interval'     => DAY_IN_SECONDS * 7, // 7天后重试
            'email_template_customer'  => 'WCS_Email_Customer_Payment_Retry', // 发送客户重试通知邮件
            'email_template_admin'     => 'WCS_Email_Payment_Retry', // 发送管理员重试通知邮件
            'status_to_apply_to_order' => 'pending', // 订单状态设为pending
            'status_to_apply_to_subscription' => 'on-hold', // 订阅状态设为on-hold
        ),
    );
}
  1. 保存文件后,规则立即生效,且不受WooCommerce Subscriptions插件更新的影响。

参数说明

  • retry_after_interval:重试间隔(单位:秒),用DAY_IN_SECONDS可简化天数计算(1天=86400秒)
  • email_template_customer:发送给客户的邮件模板标识,留空则不发送通知
  • email_template_admin:发送给管理员的邮件模板标识
  • status_to_apply_to_order:重试操作时订单要设置的状态
  • status_to_apply_to_subscription:重试操作时订阅要设置的状态

内容的提问来源于stack exchange,提问作者user7692855

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 02:31:02