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 to set product category base the same as shop base in WooCommerce?
- remove “index.php” from permalinks
- What’s the difference between WC() and $woocommerce
- How to get values from woocommerce admin input fields?
- Permalinks for CPT breaks permalinks to pages
- Permalinks for WooCommerce Categories and Subcategories
- How to show “Previous Category” and “Next Category” in categories archieve template [closed]
- Woocommerce Product Image and Thumbnails custom function
- Create WooCommerce new order with specific ID
- woocommerce change order statuses count for specific role
- is_user_logged_in() always returns false for woocommerce_login_redirect
- WordPress ‘on behalf of’ email
- Display description on cart page
- Which hook should I use to capture $_POST(‘password’) via profile update and password reset
- display first sale product in shop
- Keep getting Notice: Trying to get property of non-object in …\wp-includes\post.php on line 4153 when generating woocommerce coupon
- How to subscribe free subscription on user registration in woocommerce subscription plugin?
- WordPress Persistent connection rule does not work for “posts”
- WooCommerce Product URL re-writing
- Woocommerce cart page – Add “Free” to the shipping label when shipping is 0
- Change product in cart when billing country is changed
- remove product-category base but still redirect to page with same permalink
- Calculate tax on sales price excluding discount [closed]
- how to change permalinks format for pagination?
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Additional fields on Woocommerce’s rating system
- Question on WooCommerce Syntax
- How to re-arrange this hooked content?
- Pre filter woocommerce products to remove a certain category of products
- WooCommerce Stripe Plugin not showing up in settings [closed]
- WooCommerce plaintext mail doesn’t display currency symbol
- Woocommerce, finding the ordinal number of a purchase for a certain product
- WooCommerce order refund get qty refunded
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- Route subpage to Custom Post Type
- WooCommerce add_to_cart
- WooCommerce Simple Product Options List
- Add custom body tag if product is out of stock
- WooCommerce login redirect based on cart
- call_user_func_array() expects parameter 1 to be a valid callback, class ‘WC_Rapyd’ does not have a method ‘install’
- Conditional for product attribute page
- Setting Page Visibility for WooCommerce Default Page Doesn’t Work
- Deleted products from woocommerce are still in the database
- Remove cart functionality from WooCommerce so it doesn’t remember the products [closed]
- Apply CSS to certain product thumbnails only
- Order Woocommerce Products by On Sale and Alphabetically
- Customer Email Address
- Uninitialised Parameters using woocommerce_checkout_update_order_meta hook
- Woocommerce customer role doesn’t change if user is already a subscriber [closed]
- How to get the WooCommercer product variation image
- how add css class to product boxes li, for img, add cart button, decs, price… [closed]
- How can I hide the entire “Shipping Details” block on the admin side of Woocommerce? [closed]
- How to change pagination base from slash to query form?
- Custom post type permalink structure
- Decrease stock quantity when a variation is sold using Woocommerce
- Woocommerce – display all sold out products
- Woocommerce how to show most selling products by category
- AffiliateWP not calculating multiple quantities when using affwp_calc_referral_amount filter
- WordPress pointing animated GIF images with wrong file name upon upload (GIFs animation not working)
- How to prevent woocommerce product tag field from update?
- How do we ReWrite HTACCESS to point a cat/subcat Product URL, to Cat/ only?
- WooCommerce custom SVG coloring tool [closed]
- Woocomerce erro shipping [closed]
- How do I prevent double the amount of stock being reduced with this Split Order Woocommerce Code? [closed]