Override WooCommerce public function in child theme

In WooComerce file class-wc-form-handler.php
I wanted to override in my child theme just one line where the variable $redirect.

What is the best practice in this case ?

Read More

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;
}

Related posts

Leave a Reply

1 comment

  1. You don’t need to override any method. As you can see on line where wp_redirect there is filter hook. Read more about apply_filters.

    You can add your own custom filter to the tag woocommerce_registration_redirect using add_filter.

    Heres how you can do it:

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

    Place the above code in your child theme functions.php file.