• Resolved ihdumille

    (@ihdumille)


    Hi guys

    Is there anyone that can help me with this code, my codesnippet don’t accept it and I am not a php master so I cant see what to change
    I need to redirect customer to the profile page after a puchase

    add_action( 'template_redirect', 'ld_custom_redirect_after_purchase');
    function id_custom_redirect_after_purchase() {
    global $wp;
    
    if (ia_checkout() && ! empty( $wp->query_vars['order-recived'] )) (
    wp_redirect ( 'https://www.meisolle.dk/profil/*);
    exit;
    )
    )
    • This topic was modified 5 years, 4 months ago by ihdumille.
    • This topic was modified 5 years, 4 months ago by ihdumille.
Viewing 6 replies - 1 through 6 (of 6 total)
  • function redirect( $order_get_id ){
        $order = wc_get_order( $order_get_id );
        $url = 'https://www.yoursite.com/';
        if ( ! $order->has_status( 'failed' ) ) {
            wp_safe_redirect( $url );
            exit;
        }
    }
    add_action( 'woocommerce_thankyou', 'redirect');
    Thread Starter ihdumille

    (@ihdumille)

    Thank you for answer me so fast.
    No problems this time to add the code but it doesn’t work

    I made this changes, is it right?

    `function redirect( $order_get_id ){
    $order = wc_get_order( $order_get_id );
    $url = ‘https://www.meisolle.dk/profil/’;
    if ( ! $order->has_status( ‘failed’ ) ) {
    wp_safe_redirect( $url );
    exit;
    }
    }
    add_action( ‘woocommerce_thankyou’, ‘redirect’);

    Did you do add code to your functions.php? be sure to look for closing PHP tags (they look like: ?>).

    If your theme file ends in one of these, you need to make sure you put custom code above it.

    function redirect( $order_get_id ){
        $order = wc_get_order( $order_get_id );
        $url = home_url('/profil');
        if ( ! $order->has_status( 'failed' ) ) {
            wp_safe_redirect( $url );
            exit;
        }
    }
    add_action( 'woocommerce_thankyou', 'redirect');
    Thread Starter ihdumille

    (@ihdumille)

    No I added it to my plugin code snippet

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @ihdumille,

    The code snippet sent in @crslz’s last message does the trick for me. If it doesn’t work on your site, this might mean that the function name redirect is already used in the theme or plugin code. To make sure this isn’t the case you can try changing it to something unique, such as:

    
    function custom_redirect_to_profile_page( $order_id ){
        $order = wc_get_order( $order_id );
        $url = home_url('/profil');
        if ( ! $order->has_status( 'failed' ) ) {
            wp_safe_redirect( $url );
            exit;
        }
    }
    add_action( 'woocommerce_thankyou', 'custom_redirect_to_profile_page');
    

    Cheers!

    Thread Starter ihdumille

    (@ihdumille)

    okej thanks that worked

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘redirect customer after purchase’ is closed to new replies.