Rob
Rob

Reputation: 6370

Fire function from functions.php instead of within a plugin

I need to make some amends to a function in a Woocommerce Stripe plugin. The function is below, how can I fire this from my functions.php in my theme instead?

public function display_update_subs_payment_checkout() {
    $subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active' ) );
    if (
        apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) &&
        wcs_user_has_subscription( get_current_user_id(), '', $subs_statuses ) &&
        is_add_payment_method_page()
    ) {
        $label = esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions.', 'woocommerce-gateway-stripe' ) ) );
        $id    = sprintf( 'wc-%1$s-update-subs-payment-method-card', $this->id );
        woocommerce_form_field(
            $id,
            array(
                'type'    => 'checkbox',
                'label'   => $label,
                'default' => apply_filters( 'wc_stripe_save_to_subs_checked', false ),
            )
        );
    }
}

I specifically need to amend the second line to be:

$subs_statuses = apply_filters( 'wc_stripe_update_subs_payment_method_card_statuses', array( 'active', 'on-hold' ) );

Upvotes: 1

Views: 81

Answers (1)

Ihar Aliakseyenka
Ihar Aliakseyenka

Reputation: 14183

Default statuses are handled by wc_stripe_update_subs_payment_method_card_statuses filter hook. So you need to override it by your own filter

In your functions.php add

add_filter('wc_stripe_update_subs_payment_method_card_statuses', 'add_payment_method_card_statuses');
function add_payment_method_card_statuses ( $statuses ) {
  $new_statuses = [ 'active', 'on-hold' ]; // or whatever you want
  return $new_statuses;
}

In general, filter must have something to accept and something to return instead. In this case we accept default statuses ($statuses) and simply return new array of our statuses.

Upvotes: 2

Related Questions