I believe changing the following conditional:
if( !current_user_can( 'manage_options' ) )
to this one:
if( !current_user_can( 'manage_options' ) && 'product' === $query->get( 'post_type' ) )
would do it.
Brief explanation: I added a second condition which checks if the query is for WooCommerce products where the post type is product
.
UPDATE
If you want to make certain that the code runs only on the products page (WooCommerce → Products), then you can (remove the global $pagenow;
and) change this:
if( 'edit.php' != $pagenow || !$query->is_admin )
to this one:
if( !$query->is_admin || 'edit-product' !== get_current_screen()->id )
And instead of relying on the global $user_ID
, you should probably use get_current_user_id()
: $query->set( 'author', get_current_user_id() );
🙂
Related Posts:
- WooCommerce ‘all’ orders no longer being displayed – how may I debug/fix [closed]
- Create WooCommerce Product Category Programmatically
- WooCommerce create new product and add to cart on form submit
- How to save Clicks of a download link button while it doesn’t matter if we refresh the page or again login/logout
- WooCommerce Dynamic Cart Pricing
- Get product attribute for Simple product in WooCommerce
- Over write plugin templates
- How to prevent action in ajax request, when in admin side?
- Add multiple attributes to product from php
- Remove specific product from shop in woocommerce [closed]
- Only Homepage not loading properly
- woocommerce 3.2.1 not sending order notification emails
- Integrating non-WooCommerce and WooCommerce Orders together [closed]
- Override Javascript in a Plugin?
- Woocommerce – How to populate custom select field with stored values on checkout page?
- WordPress automatically removes line break
- Custom post type – no layout section of Document tab, and no author choice
- Add woocommerce variation images in gallery?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- WooCommerce: Building a page with user input which is used to query order status and external API and return a result
- How to toggle between two custom fields in WordPress woocommerce ‘WC Product Field Group’ plugin?
- Modifying Author Link to add Author Meta in URL
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- How to add checkboxes for a woocommerce product? [closed]
- Why am I getting ( WooCommerce Services could not be installed (Could not create directory.). ) error and how to solve it ?
- how to do login using woocommerce rest api From android
- Woocommerce Shop page variation product button replace with add to cart button
- How can I insert thousands of Woocommerce products by batch with PHP? [closed]
- How to use add_submenu_page() for editors?
- woocommerce with custom post type
- Product count in archive page Title in WooCommerce [closed]
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- Conditional Shipping Options if Certain Products are in Cart WooCommerce
- Woocommerce Backend Search by Title and SKU
- WooCommerce Shopping Cart Not Initially Showing Products [closed]
- woocommerce search by sku and title ajax
- Woocomerce add info after order email prouct item
- Getting a ressource ID, from a WC_Order_Item_Product/Order
- Sending customer an email with link to stripe to make payment
- How to remove products-links after the product title using remove_action
- get_term_meta returns false in widget
- Custom search search does not work?
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- Personalized Author Area
- Woocommerce Export and import Orders
- Cannot read properties of undefined (reading ‘firstChild’) using photoswipe in product page
- Grouping imported products and showing variations based on selected product
- Add a Custom email notification to WC actions
- How to hide a woocommerce setting tab from admin & shop manager?
- Create category for each user
- Translations not appended even strings are edited
- Remove Zero Money From Previews Order woocommerce
- How to get brand children with woocommerce brands
- How to display ACF coustom field from category on author.php
- How would I Redirect an existing WooCommerce customer to a specific url after Checkout
- Make downloadable ebook read online without download option
- Woocommerce add products to cart
- Changing wordpress/woocommerce notices default message to other languages (text)
- Woocommerce convert simple products to variations
- How to edit checkout page? [closed]
- WooCommerce Product Table – filter query on attributes
- Disable WC Bookings automatic order completion [closed]
- WooCommerce Stripe payment plugin working perfectly in storefront parent theme but not in the child theme
- WooCommerce Checkout Issue specific to Instagram In-App Browser
- How to access custom post meta data from JavaScript
- Display Woocommerce attribute name above product title
- In woocommerce, is there any way to empty wordpress default mini cart when order placed?
- In woocommerce, is it possible to make payment of one customer order by another customer?
- Woocommerce – Change variations output
- Woocommerce budget search
- Tracking sales/conversions in Woocommerce using Google Analytics
- Plugin for showing single product on a page
- How to capture customer’s credit card details via PayPal on my checkout page?
- Allow vendors on a WordPress site to pick from a gallery of pre-selected images when choosing product’s featured image
- Hide ‘add to cart’ button for some products [duplicate]
- Payment failed but order is placed on wp site
- How to change the product short description for each product with PHP?
- Help needed with woocommerce (wc stripe) filter
- Woocommerce: deleted single-product.php, everything still works. How is it possible?
- Want to add post to user dashboard
- Add A Button to WooCommerce Product Page
- How ACF Advanced Custom Field works with Woocommerce Single Product [closed]
- The plugin generated xxx characters of unexpected output during activation
- WP Customer Reviews call short code on another page [closed]
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Send Processing Order Email from custom payment plugin
- Populate Woocommerce order notes with custom field value
- Woocommerce Product Add-ons – Auto-select first option
- Predefine Product Variations for specific custom product type [closed]
- Display out of stock products in WooCommerce [closed]
- Console errors after WordPress Update 6.1
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor
- How to create a “plugin” or “block” that can manipulate WordPress DOM in frontend?
- I want to set a different banner for each product in the woocommerce plugin on my wordpress site
- Template selector for woocommerce product
- How to add product thumbnail on orders list on backend?
- Plugin Icon does not work correctly
- I want create woocommerec match products columns
- Free multi dealer rental cars (sign up) [closed]
- Convert from Portfolio post to WooCommerce products [closed]