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 ?
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;
}
You don’t need to override any method. As you can see on line where
wp_redirect
there is filter hook. Read more aboutapply_filters
.You can add your own custom filter to the tag
woocommerce_registration_redirect
usingadd_filter
.Heres how you can do it:
Place the above code in your child theme
functions.php
file.