Public Ticket #2883581

Copy Shop as customer-button

Closed
Comments
19 Tickets 1
Mervin started the conversation 5 years ago on September 29, 2021 at 3:59pm

Hi,

I am using a CRM-plugin and would love to be able to add the "Shop as customer"-button to that view as well, so that I do not have to click my way to the dashboard everytime. Is it possible for you to give me the code used to redirect us as a specific customer?

2,762
KingsPlugins replied 5 years ago on September 30, 2021 at 2:16am

Hi Mervin,

The plugin runs the following JavaScript code when the page is loaded:

$( document ).ready(function() {
    // when clicking shop as customer
    $('body').on('click', '.salesking_shop_as_customer', function(){
        var customerid = $(this).val();
        var datavar = {
            action: 'saleskingshopascustomer',
            security: salesking_display_settings.security,
            customer: customerid,
        };
        $.post(salesking_display_settings.ajaxurl, datavar, function(response){
            window.location = salesking_display_settings.shopurl;
        });
    });
});

It's not a simple redirect - the code calls an ajax function that needs to set cookies, check security, etc.

I suggest you to add the above as a JS code snippet ( https://b2bkingplugin.com/docs/how-to-add-a-snippet-php-or-js/ ) 

You would need to replace '.salesking_shop_as_customer' with the class or id of your button.

The value of the button must also be equal to the user id of the customer you want to shop as.

(such as this html: <button value="123">Shop Customer</button>)

Hope this helps,

Kind regards,

Stefan

Sign In