Support » Plugin: WooCommerce » “Order Pay” Without Login

  • Resolved zackeryfretty

    (@zackeryfretty)


    Hello!

    I’m looking for a way to make the /checkout/order-pay/ or the “Customer Payment Page” to be unprotected — meaning — I’d like it so that anyone who has that link from the email can pay for the open order. How can I achieve this? Currently it seems that you must be logged in as the users account to make the payment which doesn’t work for us.

    Our use case is that we cater to a non technical market, 70% of our orders come in via phone or fax. The rest come through via simple emails just asking for a restock. Doing a full store for them would be a big ask and it could cause us to lose clients.

    The goal is to use WooCommerce in the same way we used to use Freshbooks. We’d like to be able to manually create the client in the backend and then use “Add Order” to draft the order for them and send them an invoice to pay. This works beautifully, the only issue we run into is they’re requested to login when they click the “Pay This Order” link on the invoice email. I’d like that to be fully open so they can pay without login, (Which is how it worked on Freshbooks) but I still want it to be attached to an account for our personal records. It would also be helpful for us to be able to view that as an admin to record payments given to us via the phone.

    Is there some way, even if it’s via a function or filter, that I could exclude the payment page from needing a login?

    Thank you so much!

    Best,
    Zack

Viewing 13 replies - 1 through 13 (of 13 total)
  • superkot

    (@superkot)

    Currently it seems that you must be logged in as the users account to make the payment which doesn’t work for us.

    That is not a standard behavior. By default, one can do exactly what you wish with Woocommerce. Maybe it is your payment gateway or other extra plugins that require logging in to pay.

    zackeryfretty

    (@zackeryfretty)

    Thanks so much for your reply, but, I don’t think that’s quite true — it seems like at some point in time it was added,Perhaps in 3x?

    I don’t have anything solid yet, but, it seems like it’s lines 95 – 109 on this file:

    https://github.com/woocommerce/woocommerce/blob/master/includes/shortcodes/class-wc-shortcode-checkout.php

    zackeryfretty

    (@zackeryfretty)

    Had some help from the WooCommerce Slack, this did the trick for anyone who needs the same functionality:

    function jp_custom_order_caps( $allcaps, $caps, $args ) {
        if ( ! isset( $caps[0], $args[2] ) ) {
            return $allcaps;
        }
    
        switch ( $caps[0] ) {
            case 'pay_for_order':
                $order = wc_get_order( $args[2] );
                if ( 'admin' === $order->get_created_via() ) {
                    $allcaps['pay_for_order'] = true;
                }
                break;
        }
    
        return $allcaps;
    }
    add_filter( 'user_has_cap', 'jp_custom_order_caps', 10, 3 );

    Added it to functions.php and everything runs exactly as I need it. 👌🏼

    Plugin Support Hannah S.

    (@fernashes)

    Automattic Happiness Engineer

    Thanks for sharing the solution!

    Just tightening up this solution, so that the WooCommerce-generated Payment URLs should work, but ensuring that there is some level of Authentication…

    function allow_payment_without_login( $allcaps, $caps, $args ) {
        // Check we are looking at the WooCommerce Pay For Order Page
        if ( !isset( $caps[0] ) || $caps[0] != 'pay_for_order' )
            return $allcaps;
        // Check that a Key is provided
        if ( !isset( $_GET['key'] ) )
            return $allcaps;
    
        // Find the Related Order
        $order = wc_get_order( $args[2] );
        if( !$order )
            return $allcaps; # Invalid Order
    
        // Get the Order Key from the WooCommerce Order
        $order_key = $order->get_order_key();
        // Get the Order Key from the URL Query String
        $order_key_check = $_GET['key'];
    
        // Set the Permission to TRUE if the Order Keys Match
        $allcaps['pay_for_order'] = ( $order_key == $order_key_check );
    
        return $allcaps;
    }
    add_filter( 'user_has_cap', 'allow_payment_without_login', 10, 3 );

    This will allow users accessing URLs like https://your.domain/checkout/order-pay/987/?pay_for_order=true&key=wc_order_5c4155dd4462c to complete payment, but not allow users to simply go to https://your.domain/checkout/order-pay/987/?pay_for_order=true

    • This reply was modified 7 months, 3 weeks ago by  Luke Stevenson. Reason: formatting
    • This reply was modified 7 months, 3 weeks ago by  Luke Stevenson. Reason: Trying to break hyperlinks
    • This reply was modified 7 months, 3 weeks ago by  Luke Stevenson.

    How can i make this working also with woocommerce subscriptions? i tried your function but it redirects me to https://your.domain/my-account/?wcs_redirect=pay_for_order&wcs_redirect_id=987
    Do you have any idea?

    Thank you.

    markpasztor

    (@markpasztor)

    Have you found a solution for subscriptions? I have the same issue.
    Thank you!

    ptravassos

    (@ptravassos)

    You actually need to be logged in to have a subscription.
    I did to possible solutions, it depends why you arre trying to bypass the login.
    1. you can automatically login-in the user (if it’s a valid order and key order) (not so secure)
    2. add a passwordless login to make it easier for the user (i used WP auth0).

    The redirect i solved with:

    /**
     * Pay order redirect for subscriptions Fix beacause of Aut0 Plugin
     */
    function pt_maybe_redirect_after_login() {
    	if ( class_exists( 'WP_Auth0' ) ) {
    		if (is_user_logged_in() && is_account_page() && isset( $_GET['wcs_redirect'], $_GET['wcs_redirect_id'] ) && 'pay_for_order' == $_GET['wcs_redirect'] ) {
    			$order = wc_get_order( $_GET['wcs_redirect_id'] );
    			if ( $order ) {
    				wp_redirect( $order->get_checkout_payment_url() );
    				die();
    			}
    		}
    	} else {
    		// you don't appear to have WP_Auth0 activated
    	}
    }
    add_action('template_redirect', 'pt_maybe_redirect_after_login');

    Thank you very much for this! I’ve been looking for this for days to enhance my website Binh WPO and finally found this code and it works. Now the customer can just proceed without having to login, which reduce the drop rate.

    @lucanos anyway to obtain to payment url with order key by itself? Im trying to send this by sms to my clients.

    Thanks for the solution!

    Hi,

    I have the same problem with woocommerce saying you need to be logged in to proceed to checkout. I tried both bits of codes and it will not work. Is there another solution for this? The plugin under accounts has an option for this but it doesn’t work either. Appreciate any help.

    mehmetogul

    (@mehmetogul)

    Hi,

    I am the same problem for Woocommerce subscription.

    @lucanos code looks very good with extra security. But it does not work with woocommerce Subscription.

    It keeps redirection to this page and asking for login again ..?wcs_redirect=pay_for_order&wcs_redirect_id=122

    So I guess it needs some additional code to work with Subscription orders.

    @ptravassos your code need another plugin (WP_Auth0) to be installed and activated.

    Thanks…

    gibsongk55

    (@gibsongk55)

    I was unable to get any code changes or a workaround for this problem. As no alternative i just commented out the part of code that checks to see if they are logged. This is a good work around but must be watched in case an update changes this.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.