admin管理员组

文章数量:1123161

I am looking to change the payment retry rules.

I’m following the guide on /

I’ve found the file wp-content/plugins/woocommerce-subscriptions/includes/payment-retry/class-wcs-retry-rules.php which seems to be where they are specified.

How do I override the rules so they’re not reset every time I update the plugin? I am looking to retry after 24 hours and 7 days e.g.

    $this->default_retry_rules = apply_filters( 'wcs_default_retry_rules', array(
        array(
            'retry_after_interval' => DAY_IN_SECONDS, // how long to wait before retrying
            'email_template_customer' => '', // don’t bother the customer yet
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
        array(
            'retry_after_interval' => DAY_IN_SECONDS * 7,
            'email_template_customer' => 'WCS_Email_Customer_Payment_Retry',
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
    ) );
}

I am looking to change the payment retry rules.

I’m following the guide on https://woocommerce.com/document/subscriptions/develop/failed-payment-retry/

I’ve found the file wp-content/plugins/woocommerce-subscriptions/includes/payment-retry/class-wcs-retry-rules.php which seems to be where they are specified.

How do I override the rules so they’re not reset every time I update the plugin? I am looking to retry after 24 hours and 7 days e.g.

    $this->default_retry_rules = apply_filters( 'wcs_default_retry_rules', array(
        array(
            'retry_after_interval' => DAY_IN_SECONDS, // how long to wait before retrying
            'email_template_customer' => '', // don’t bother the customer yet
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
        array(
            'retry_after_interval' => DAY_IN_SECONDS * 7,
            'email_template_customer' => 'WCS_Email_Customer_Payment_Retry',
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
    ) );
}
Share Improve this question edited 5 hours ago LoicTheAztec 253k24 gold badges393 silver badges441 bronze badges asked 6 hours ago user7692855user7692855 1,4186 gold badges21 silver badges44 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You should never overwrite any plugin core files, for many different reasons.

In your case, wcs_default_retry_rules is the right filter hook to change WooCommerce Subscriptions Payment Retry rules.

So the correct code to be used instead is:

add_filter( 'wcs_default_retry_rules', 'custom_wcs_default_retry_rules' );
function custom_wcs_default_retry_rules( $retry_rules ) {
    return array(
        array(
            'retry_after_interval' => DAY_IN_SECONDS, // how long to wait before retrying
            'email_template_customer' => '', // don’t bother the customer yet
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
        array(
            'retry_after_interval' => DAY_IN_SECONDS * 7,
            'email_template_customer' => 'WCS_Email_Customer_Payment_Retry',
            'email_template_admin' => 'WCS_Email_Payment_Retry',
            'status_to_apply_to_order' => 'pending',
            'status_to_apply_to_subscription' => 'on-hold',
        ),
    );
}

Code goes in functions.php file of your child theme (or in a plugin). It should work.

Don't forget to replace the original plugin file for class-wcs-retry-rules.php file.

本文标签: phpHow to Change Payment Retry Rules for Woocommerce SubscriptionsStack Overflow