Advertisement
wpgenie

custom url structure for woocommerce simple auctions

Oct 4th, 2016
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. function wsa_change_link_for_auction( $url, $post ) {
  2.    
  3.     if ( 'product' == get_post_type( $post ) ) {
  4.         $product = wc_get_product($post);
  5.         if($product->product_type === 'auction'){
  6.             $url = str_replace('product', 'auction', $url);
  7.         }
  8.     }
  9.     return $url;
  10. }
  11. add_filter( 'post_type_link', 'wsa_change_link_for_auction', 10, 2 );
  12.  
  13. function wsa_custom_rewrite_for_auction() {
  14.   add_rewrite_rule('auction/([^/]+)(?:/([0-9]+))?/?$', 'index.php?product=$matches[1]&page=$matches[2]', 'top');
  15. }
  16. add_action('init', 'wsa_custom_rewrite_for_auction');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement