Skip to:
Content
Pages
Categories
Search
Top
Bottom

Redirection after photo upload


  • Philippe
    Participant

    @philippebrousse

    Hi BuddyPress Community,

    So I’ve been struggling with a redirect issue for a couple days and I can’t seem to be able to find a solution on the forum or elsewhere.

    Basically, I am developing an eCommerce website with WooCommerce, BuddyPress amongst other plugins. In my UX, users need to create an account and add a profile pic before purchasing an item.

    Hence,
    – if they try to buy a product as a visitor:
    > they will be redirected to login
    – if they don’t have an account
    > they will be redirected to signup
    – Once they have signed up
    > they are redirected to change profile photo page (since it cannot be made compulsory in bp register)

    And finally, on successful photo upload
    > if there is a product in the cart, they are redirect to checkout

    This is the last one that I cannot get done properly, so far here is what I tried

                add_action( 'xprofile_avatar_uploaded', array( $this, 'potentially_redirect_to_checkout' ), 30 );
    
    public function potentially_redirect_to_checkout() {
            write_log('I was in potentially_redirect_to_checkout');
            # if there is a product in the cart, the user probably wants to go back to checkout
            if( !WC()->cart->is_empty() ) {
                write_log('I was in potentially_redirect_to_checkout: cart not empty');
                // wp_safe_redirect( get_permalink( get_option('woocommerce_checkout_page_id') ) );
                // exit;
                wp_redirect( wc_get_checkout_url() );
                exit;
            }
        }
    
    

    I can confirm that the code in the final ‘if’ is executed but no redirection is made, instead I end up in the change profile photo page with an empty red notice (and the profile photo is still successfully updated)

    Anyone can help?

    Thanks,

    Phil

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar