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)
- Taxclass based on certain conditions: location+userrole
- Removing unwanted role after purchase
- Customer Email Address
- Product related to post by title
- WooCommerce product id as permalink
- WordPress/Woocommerce Classes and adding new properties
- currentURL is not defined
- How to send an automatic email to a custom field in Woocommerce order meta 2 weeks after a product is bought
- merge tabs in woocommerce
- How to echo woocomerce attributes values in dropdown box
- Customize categroy catalog page
- How do you programatically add a booking item to the cart?
- Create post when new woocommerce order is created [closed]
- Woocommerce cart table too wide [closed]
- Add new page in WooCommerce My Account page
- How to import products to Woo Commerce given that WP All Import keeps timing out
- Merge “description” and “additional informations” product tab
- Add to cart is not visible in product page
- Clickable product image with hover effect
- wp_get_current_user Not working
- I need to refresh the checkout page if someone changes the zip code
- Adding a second button next to the shop button Woocommerc [closed]
- Notice: Trying to get property of non-object in
- Updating WooCommerce product field when product author updates profile field
- French accented text replaced with ? in woocommerce product list
- Trying to figure out why an error is returned when trying to add an item to the basket on this website
- Conditionnaly replace “Read more” text WooCommerce products
- Correct method of reducing the number of images created by WP and Woo together
- WooCommerce/Authorize.net interface problem
- populating extra field with woocommerce categories
- WooCommerce subscriptions give option of manual renewal on checkout [closed]
- Woocommerce Shop Manager Capabilities
- HTTP Error when uploading pictures and problem with the size of images
- add_rewrite_rule() returns 404 page
- How to set subcategory in Woocommerce?
- Woocommerce – How to Show product tags in shop page
- Using category and its sub-categories products attributes as filter in products pages
- Bulk edit orders to ‘wc-processing’ status
- Woocommerce section name? [closed]
- how to change value return by _stock_status
- Retrieve Woocommerce Cart Url with javascript/jquery [closed]
- How to change “add to basket” button text in WooCommerce based on product category?
- The orders in WooCommerce admin are hidden (they have the “hidden” CSS class)
- Select all product woocommerce
- Woocommerce REST API: creating variations
- How to hide / remove duplicated Woocommerce products from Shop page
- WooCommerce one time checkout pop up
- How to add a special Woocommerce “Buy Now” button?
- Disable theme WooCommerce template [closed]
- WP All import sale price 0 [closed]
- How to add product variations for large number of products in WooCommerce?
- WooCommerce database upgrade behaviour
- WooCommerce: how to set stock per attribute on variable product
- How to display products in sidebar in 2 columns?
- Removing Product from Woocommerce checkout page using Ajax
- WordPress post_content gets deleted in cron after wp_update_post
- How can I locate where the actions are defined? [duplicate]
- Shortcodes in billing fields doesn’t work
- add_post_meta on subcription renewal
- How to neutralize a parent theme php template?
- wordpress site auto redirect to another site when I enable woocommerce
- How to customize product at cart page
- Update a user meta key based on WooCommerce product purchase
- WooCommerce Storefront site-header padding
- login or register then access woocommerce website