简体   繁体   English

从functions.php而不是在插件中触发function

[英]Fire function from functions.php instead of within a plugin

I need to make some amends to a function in a Woocommerce Stripe plugin.我需要对 Woocommerce Stripe 插件中的 function 进行一些修改。 The function is below, how can I fire this from my functions.php in my theme instead? function 在下面,我怎样才能从我的函数中触发它。php 在我的主题中呢?

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' ) );

Default statuses are handled by wc_stripe_update_subs_payment_method_card_statuses filter hook.默认状态由wc_stripe_update_subs_payment_method_card_statuses过滤器挂钩处理。 So you need to override it by your ownfilter所以你需要用你自己的过滤器覆盖它

In your functions.php add在您的函数中。php 添加

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.在这种情况下,我们接受默认状态($statuses)并简单地返回我们状态的新数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM