Okay
  Public Ticket #3071475
user creation password
Closed

Comments

  •  10
    feruap started the conversation

    Me as a sales operator: Im creating an order for a customer by phone. So, I create the customer by filling name, emails, user, etc... and I need to set the password for the customer--------------------------System sends email about the user creation but not the password, and I need to tell customer the password by other means, lets say by phone

    Then, on sales agent panel I use the function to shop as customer, that way I can change the price to whatever I agree to customer. 

    System sends the payment request to user email, with the idea that customer clicks and make credit card payment.

    Here is the problem

    Customer receives the email, it clicks the link and it takes him to login. For that, customer forgets everything (particulary for new customers) login can be retrieved from system email (first step) but password, since I gave it by phone, it could be forgoten. 

    I have lost customers because the login for finishing the payment. 

    Is there a way to make the things simplier for customer. Something like, received the payment email and when clicking the link it autologins and goes straignt to finalice the purchase.

    Or maybe other solution

    I hope the problem makes sense to you 



  •  2,214
    WebWizards replied

    Hi there,


    1) I believe you can add the following PHP code snippet to your site and it would help allow customers to pay without logging in first:

    add_filter( 'user_has_cap', 'bbloomer_order_pay_without_login', 9999, 3 );
     
    function bbloomer_order_pay_without_login( $allcaps, $caps, $args ) {
       if ( isset( $caps[0], $_GET['key'] ) ) {
          if ( $caps[0] == 'pay_for_order' ) {
             $order_id = isset( $args[2] ) ? $args[2] : null;
             $order = wc_get_order( $order_id );
             if ( $order ) {
                $allcaps['pay_for_order'] = true;
             }
          }
       }
       return $allcaps;
    }
    

    A PHP snippet can be added to functions.php, or by following our guide here: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/

    Try to add this, maybe it can resolve your issue,


    2) Normally when a sales agent creates a new customer account, the customer should receive an email like this:

    2513893158.png

    The email would contain the username and a link to set a new password, as you can see above.


    Kind regards,

    Stefan

  •  10
    feruap replied

    Wow, you are soooo good. Thank you. It worked… almost.

     

    On email link it takes you to payment page, but it is not showing payment information: name, address, phone, etc.

     

    So, when customer is willing to pay and no information is shown, well it gives doubts about “if everything is correct”

     

    How to solve it?¡

     

  •  2,214
    WebWizards replied

    If you also add this code, it will also show the billing and shipping addresssmile.png :

    add_action( 'before_woocommerce_pay', 'bbloomer_order_pay_billing_address' );
    function bbloomer_order_pay_billing_address() {
       // ONLY RUN IF PENDING ORDER EXISTS
        if ( isset( $_GET['pay_for_order'], $_GET['key'] ) ) {
          // GET ORDER ID FROM URL BASENAME
            $order_id = intval( basename( strtok( $_SERVER["REQUEST_URI"], '?' ) ) );
            $order = wc_get_order( $order_id );
          // INCLUDE CUSTOMER ADDRESS TEMPLATE
            wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) );
        }
    }
    
  •  10
    feruap replied

    Now I can see the information, but it is not editable (as supposed to be on regular checkout process)


    Thank you, thank you!!



  •  2,214
    WebWizards replied

    I don't think there's a way we can make it editable without the user logging in unfortunately. At least I'm now aware of any way - it also may be sort of a security issue if anyone with the link can edit the order address, so maybe that's why it doesn't work by default.

  •  10
    feruap replied

    understood.

    A turn around would be to add a login button at the beginning of the screen

    <change delivery address> <login now> (button)


    Can you help please?


    Thank you

  •  2,214
    WebWizards replied

    You can change the last code snippet with the following:

    add_action( 'before_woocommerce_pay', 'bbloomer_order_pay_billing_address' );
    function bbloomer_order_pay_billing_address() {
        if (!is_user_logged_in()){
            $link = get_permalink( wc_get_page_id( 'myaccount' ) );
            echo 'To change the delivery address, please log in.';
            ?>
            <a href="<?php echo esc_attr($link);?>"><button type="button" value="Login">Login</button></a><br><br>
            <?php
        }
       // ONLY RUN IF PENDING ORDER EXISTS
        if ( isset( $_GET['pay_for_order'], $_GET['key'] ) ) {
          // GET ORDER ID FROM URL BASENAME
            $order_id = intval( basename( strtok( $_SERVER["REQUEST_URI"], '?' ) ) );
            $order = wc_get_order( $order_id );
          // INCLUDE CUSTOMER ADDRESS TEMPLATE
            wc_get_template( 'order/order-details-customer.php', array( 'order' =--> $order ) );
        }
    }
    

    You can edit the part there after ' if (!is_user_logged_in()){' to any content you want. You can also move it after the rest of the code, to make the link and button show after the addresses.