【问题标题】:Override WooCommerce public function in child theme覆盖子主题中的 WooCommerce 公共功能
【发布时间】:2014-05-14 20:10:34
【问题描述】:

在 WooComerce 文件中 class-wc-form-handler.php 我想在我的子主题中只覆盖变量$redirect 的一行。

在这种情况下,最佳做法是什么?

class-wc-form-handler

public function process_registration() {
   if ( ! empty( $_POST['register'] ) ) {
    ...
    // Redirect
    if ( wp_get_referer() ) {
        $redirect = esc_url( wp_get_referer() );
    } else {

          //$redirect = esc_url( get_permalink( wc_get_page_id( 'myaccount' ) ) );
        $redirect = home_url() . $_SERVER["REQUEST_URI"];
    }

    wp_redirect( apply_filters( 'woocommerce_registration_redirect', $redirect ) );
    exit;
}

【问题讨论】:

    标签: php wordpress woocommerce woothemes


    【解决方案1】:

    您不需要重写任何方法。正如您在wp_redirect 有过滤器挂钩的在线所见。阅读有关apply_filters 的更多信息。

    您可以使用add_filter 将自己的自定义过滤器添加到标签woocommerce_registration_redirect

    你可以这样做:

    add_filter( 'woocommerce_registration_redirect', 'my_custom_redirect' );
    
    function my_custom_redirect()
    {
        return esc_url( get_permalink( wc_get_page_id( 'myaccount' ) ) );
    }
    

    将上述代码放入您的子主题functions.php 文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      相关资源
      最近更新 更多