One way of doing this is check with the get_current_user()
and check if return something, if yes, run the code. Like the example below:
add_action( 'woocommerce_admin_order_data_after_order_details', 'ccef_order_switch_to', 99 );
/**
* Add a switch to user link on the order details.
*
* @param object $order The WC Order that we're working with.
*/
function ccef_order_switch_to( $order ) {
$current_user = wp_get_current_user();
$user_switching = $GLOBALS['user_switching'];
if ( $user_switching && $current_user ) {
$user = get_user_by( 'id', $order->get_user_id() );
$switch_link = '';
// Only try to switch if a $user was set.
if( $user ) {
$switch_link = $user_switching::maybe_switch_url( $user );
}
if ( $switch_link ) {
echo '<a href="' . esc_url( $switch_link ) . '">Switch To</a>';
}
}
}
Related Posts:
- Switch to user link shortcode
- Woocommerce customer role doesn’t change if user is already a subscriber [closed]
- How to update user role without logout
- In WooCommerce filter the available Payment Methods by User Role [closed]
- Admin access for custom user capabilities
- WP_Query with meta_query for children
- WooCommerce limited role
- Allow WooCommerce existing customers to checkout without being logged in [closed]
- How to delete all customer user account that haven’t placed a single order?
- Tried to create a user role that can only edit user information, but my test account cannot view the dashboard. What am I missing?
- Why is my WordPress login credentials missing, but work with WooCommerce?
- WooCommerce which roles and capabilities control user login re-direct to Woo Account Page?
- Send admin new order email to logged in user as well
- WooCommerce get_author_posts_url() – Author URL redirecting to shop base
- I want to store user password (during registration) in an other table in the same database in addition to the user table MD5 Hash
- I have 3 types of prices in WP and I need to change price for each specific user role using hooks
- How to show specific admin menu to specific user role?
- Assign user role by text field in WordPress (Woocommerce) [closed]
- Need help with woocommerce roles
- Add custom field address_3 before city in user profile
- How to merge 2 accounts with same email address after merge of 2 woocommerce databases
- How to change user role after login?
- WordPress user ID prefix
- Get user active posts randomly
- Changing second user role while updating/downgrading membership level – s2member [closed]
- How to add a menu page for options in wordpress for user that has the role of vendor?
- How to disable the “Upgrade or Downgrade” button in “My account” of WooCommerce Subscriptions
- Some Admin disappeared
- Restrict the shop_manager role to the WooCommerce Orders Page
- Change WooCommerce registration form/way?
- Want to add Number of Products added by each shop manager in users list
- Can I remove WooCommerce specific product categories from shop managers?
- How to handle WordPress account for terminated employee
- how to use wc_create_order with subscription product
- Set a maximum upload count for users on a specific user role
- WooCommerce changes lost password reset link
- WooCommerce: Add New Report Tab
- Custom Woocommerce image size [closed]
- How can I get the last posts by user role?
- Migrate WooCommerce Orders [closed]
- WooCommerce Subscriptions: Show monthly Price for annual Product
- How to add multiple product gallery images from front-end
- Hide income in Woocomercer [closed]
- woocommerce_email_subject_customer_completed_order
- is_shop, is_home, is_front_page doesn’t work for woocommerce
- WooCommerce: The model of e-mail is displaying only the html, not css [closed]
- How to show loading spinner after click on add to cart button [closed]
- Woocommerce – Show random product thumbnail from specific product category
- Roles for Custom Post Types
- How to add a greeting message upon logging into WordPress for certain user role
- Modify some CSS with functions if (function_exists
- Limit total quantity of products in WooCommerce group product
- Woo-commerce Checkout Summarized in Pop-up Card Entry Only
- Display Message if woocommerce coupon is not applicable to some items in the cart
- How do I add an extra field to comment form above the submit button?
- woocommerce email template detect email recipient
- WooCommerce – buying as well as selling
- How do I hide ‘out of stock’ products in the admin ‘product’ page?
- Add custom field to Woocommerce add new attribute / edit page
- woocommerce axios react
- Woocommerce – Add HTML around Product description [closed]
- relocate woocommerce notices/messages on Cart page
- lost password link not working for my site
- How to give each category name its own ACF background color?
- WooCommerce 4: Gallery size is too large in mobile
- Filter default_content only for products
- Get woocommerce coupon code
- WooCommerce set a min order price for a single country [closed]
- “Reset my password” links to itself (page refreshes) [closed]
- How to check if woocommerce_order_item_name is use in email?
- Logo showing on some page but not on product categories pages
- Categories on attribute archive pages
- How to solve `Error getting remote image` in woocommerce rest api script?
- Woocommerce Multisite global search how to mod ajax function?
- How to let users create lists of woocommerce products?
- How to force Woocommerce to deliver the product to the paypal adress which was used?
- Photo cover in WooCommerce
- How to vary WooCommerce product prices based on order dates
- How to save one API response to WooCommerce order meta data
- WooCommerce and ACF: How to Redirect Upon Add to Cart – Partially Working Example
- Woocommerce: Search by custom attribute
- Increase the download speed of a large number of variations in WooCommerce
- remove add to cart for free (0 $) product woocommerce
- merge tabs in woocommerce
- Removing shipping for one product with coupon
- Disabling user capability to edit_posts or delete_posts in the front-end
- Awesome Support Custom Field for show Woocommerce orders
- How to make a custom redirect in WooCommerce?
- Firstname and lastname greyout or hidden Billing details at next checkout like username is hidden [closed]
- How to use woo commerce login to authenticate code php pages?
- Site with WooCommerce section moved to HTTPS – all pages except home and main store are 404s
- Multiple quantities with options
- how to add custom reviews button in woocommerce order complete generated mail
- Not all strings are translated
- Woocommerce make appear when items added to cart
- How to display Woocommerce catagories
- Display and Allow users to edit their own profiles
- How to give access to the particular page in wordpress for specific username/email NOT roles [closed]
- Critical error on woocommerce checkout page
- Can’t add variable products since update WooCommerce [closed]