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
- Add a product for all users based on a condition (WooCommerce)
- Add another user role based on a defined input field in WordPress (Woocommerce)
- Removing unwanted role after purchase
- How to let contributors to create a new revision(draft) editing their published posts
- How to remove an action within a class with extends
- Create WooCommerce custom stock option that is non-purchasable
- Query multiple post type and categories
- Shipping restrictions with WooCommerce variable products
- WooCommerce – Flat rate shipping based on X quantity steps?
- Custom URL for each product variation – rewrite rules
- Change “Shipping” text to “Delivery” everywhere I appears in woocommerce
- Customize WooCommerce orders displayed shipping
- creating product with variations using woocommerce REST API
- Adding extra one email address who receives email as admin – woocommerce
- Woocomerce language
- How to set default values in Woocommerce checkout? [closed]
- Payment methods are not displaying in Woocommerce
- get approved users only ( ultimate member plugin )
- Product admin page breaking with too many product variations [closed]
- Add content to the last slide of each product
- Remove add to cart icon/view product button woocommerce
- Expired session error (admin) when I try to make a call to WooCommerce api [closed]
- Woocommerce is_shop not on page slug? [closed]
- Role can edit just one page [closed]
- WooCommerce – Trigger Checkout Form Validation
- Debugging why featured images have stopped showing in WooCommerce on the homepage [closed]
- WooCommerce minimum order amount for specific country excluding local pickup [closed]
- woocommerce list product by id
- Woocommerce Login Redirect to old domain
- Show Content On below single product with specific category
- How to change a WooCommerce Subscription Deposit and Monthly Payment? [closed]
- how to scrolling image on single product page
- How to display WooCommerce product tag names on home and category pages
- Specifically Link To the “Leave a review” part of product page? [closed]
- Next/Previous Product with custom order by price & products inside the product category [closed]
- Display list of only specific tags on product
- Change the “Register” headline in Woocommerce
- How to Add “parent category description” in Woocommerce sub category page if there is no description available for child category
- Woocommerce – Hide shipping at all, if only certain product or products with certain shipping class is in the cart
- Update user role for expired membership
- Running JavaScript after using WooCommerce Filter Plugin
- Include stock information in WooCommerce order confirmation email
- Woocommerce get attributes
- How to upload very large JPGs to Media Library for WooCommerce digital download prints
- use vendor address instead of store main address for shipping and taxes calculation
- where does $checkout in form-checkout.php woocommerce come from? [closed]
- How to find which last line executed in wordpress?
- WooCommerce – Hide price and add to cart button
- Send a different “thank you” email based on payment method
- Delete product image using WooCommerce API?
- Empty Cart on just mobile and Microsoft edge browser
- How to add a special Woocommerce “Buy Now” button?
- WP All import sale price 0 [closed]
- WooCommerce database upgrade behaviour
- How to neutralize a parent theme php template?
- creating number of database entries based on users numerical input
- Import download attachment from woocommerce product
- Duplicate post/product permalinks. (Link is temporary)
- Add an extra column to /my-account/subscriptions/ WooCommerce page
- Understanding WooCommerce Build-In Geolocation/ Geo_IP classes
- Same WooComerce shop for different WP sites?
- Access level seems to have gone from admin to editor
- file upload user profile
- How to give different user access to different people?
- Why does have_comments return false but get_comments return array of commemts?
- How can I solve WordPress error “Cannot load product_attributes” and “Cannot load product-reviews”?
- how to refrence woocommerce blocks in code?