Advertisement
mbis

WCV Vendor | Use %store% in products' permalinks

Mar 25th, 2022
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. /**
  3.  * WCV Vendor | Use %store% in Products' permastructure settings
  4.  */
  5. function pm_wcv_shop_name($default_uri, $native_slug, $post, $slug, $native_uri) {
  6.     // Do not affect native URIs
  7.     if($native_uri == true || empty($post->post_type) || $post->post_type !== 'product') { return $default_uri; }
  8.    
  9.     if(strpos($default_uri, '%store%') !== false && class_exists('WCV_Vendors')) {
  10.         $store_name = WCV_Vendors::get_vendor_shop_name($post->post_author);
  11.         $default_uri = str_replace('%store%', sanitize_title($store_name), $default_uri);
  12.     }
  13.        
  14.     return $default_uri;
  15. }
  16. add_filter('permalink_manager_filter_default_post_uri', 'pm_wcv_shop_name', 3, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement