Ok, so the second code is:
function custom_rewrite_basic() {
$prodCatArgs = ['taxonomy' => 'product_cat'];
$wooCats = get_categories($prodCatArgs);
$catSlugs = [];
foreach($wooCats as $wooCat) {
$catSlugs[] = $wooCat->slug;
}
add_rewrite_rule(
'^('.implode('|', $catSlugs).')/([^/]*)/?',
'index.php?post_type=product&category=$matches[1]&product=$matches[2]',
'top'
);
flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_basic');
Related Posts:
- Custom WooCommerce rewrite rules with comma delimiter
- Cannot use dynamic prefix for WooCommerce permalink
- Custom URL for each product variation – rewrite rules
- Rewriting Woocommerce Product Filters To URL Segments
- How to remove the sub-category from Woocommerce product URL
- How to remove product base from WooCommerce product permalinks
- Unable to update Woocommerce Product Permalink
- Permalinks contain unwanted space resulting in broken links
- Subcategories not working when using shared base with custom taxonomy
- WooCommerce product category permalinks
- Add Custom Slug Tags Per Page
- Woocommerce product rewrite rules not working
- Add rewrite rule to make Woocommerce product category page seo friendly
- Add only sku to product url woocoomerce
- Woocommerce Product permalinks “product” word is not working
- Rewrite rules for sub category (child product categry & grand-child)
- How to change product category permalinks programmatically?
- One Time Access URL after purchasing subscription
- WooCommerce return 404 in the product page
- How to update permalink programmatically?
- How to remove the Sub category product URL Woocommerce
- Woocommerce posts and products links works only once and then get 404 error
- Custom pagination permalink structure Product page
- Custom account page that accepts a query parameter
- Adding country subdomain to an existing website like www.example.com/uk
- WooCommerce product id as permalink
- Disable Woocommerce main shop page, but not the product category archive pages
- Single product link in woocomerce
- permalinks url with woocommerce
- How to get the perfect WordPress, WooCommerce, Custom Post Type pretty permalinks?
- url rewrite doesn’t load woocommerce product
- Change variants URL
- Woocommerce product and category in url [closed]
- WooCommerce product permalink based on product’s current category
- Woocommerce products permalink based on SKU
- woocommerce permalinks like “?p=%post_id%”
- How can I get the product permalink on the WooCommerce shop page?
- How to set product category base the same as shop base in WooCommerce?
- How to Programmatically Replace Characters in WooCommerce Product Slugs?
- Get all categories inside a Product Tag archive page
- What is the problem with these lines of code?
- Send all emails to Shop Manager along with admin
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Dynamic product total add to cart amount
- unable to customize query to get filtered products by meta_key
- WooCommerce pagination: remove ‘page’ from url
- Woocommerce + Google Analytics (Conversion Rate Not Working)
- WooCommerce custom product type not saving with namespaces
- A different permalink structure for different categories
- Snippet to copy product affiliate link to a custom field
- Coupon for product / woocommerce
- Sharing data between filters on a snippet (user specific) for Woocommerce
- How to add custom checkboxes from loop to WooCommerce product variation options?
- How can I make a thumbnail slider
- send order detail to swiftpos
- WordPress Woocommerce REST API JSON Error
- data-value for custom woocommerce field showing in code but not visable on page load
- Multisite login – registration is duplicated
- WooCommerce – 500k Jump in Order Number?
- Woocommerce Checkout Page Total Price Inside Google Pay Script
- How can I show “sold out” instead of “out of stock” for some products with particular tags and categories [closed]
- WooCommerce variable product can not add to cart using ajax after updating latest version of WooCommerce
- Create a Search Form that only Searches with WooCommerce Sale Products
- Update WooCommerce Sale Price & Date Based On Attribute Value
- Add shortcode to show woocommerce shipping class name on product template
- How to hide order action button after changing order status to completed
- Save product short description in order (without updating in order details if it is updated in product)
- How to change URL from /%postname%/ to custom-name/%category%/%year%/%monthnum%/%day%/%postname%/
- Can I create categories or attribute contain more than 70,000?
- Custom Email via Hook only for completed order
- Access custom meta_data in processing order email
- Woocommerce custom log in and register
- Format decimals of get_price_html
- Woocommerce : Add name filed of checkout page to buyers wordpress display name
- Hidden permalink different from displayed permalink
- How to select the first product variant as a default?
- Woocommerce : How to automatically input the same email for every order?
- Add prefix to url, but products not showing in page SHOP
- Create different permalinks for same post
- Woocommerce – Change order of products in Confirmed Order
- echo product parent category
- Woocommerce checkout page issue – Payment methods not loading – strange “Credit/Debit Card Secure Payment” form
- remove SLASH on single_post but KEEP on categories and parent pages
- url not using query string no longer working
- WooCommerce – dynamically loading checkout page using ajax not showing payment methods for guest
- SOLVED – add_action() for $product->get_date_created
- Add “new” tag for existing products
- Sort products by Sale price and stock status
- How to hide a random text with a div tag using a class on product pages with a specific tag
- Pagination in woocommerce – Limiting page-numbers
- Two Filter Issue [closed]
- How to edit wc_get_template_part for archive products
- Switch to user link shortcode
- apply_filter and add_filter conflict
- Adding a ‘blogs’ prefix in the URL structure but only for blogs
- Syncing WP Database Changes Between Environments: How To Handle Merging w/o touching database
- Missing variable options on add to cart form
- Migrating WordPress + WooCommerce from server to Local
- wp-cron and woocommerce subscriptions killing performance
- Show shipping class in admin order list