wpgenie icon

custom url structure for woocommerce simple auctions

wpgenie | PRO | 10/04/16 08:18:44 AM UTC | 0 ⭐ | 1213 👁️ | Never ⏰ | []
PHP |

570 B

|

None

|

0 👍

/

0 👎

function wsa_change_link_for_auction( $url, $post ) {
    
    if ( 'product' == get_post_type( $post ) ) {
        $product = wc_get_product($post);
        if($product->product_type === 'auction'){
            $url = str_replace('product', 'auction', $url);
        }
    }
    return $url;
}
add_filter( 'post_type_link', 'wsa_change_link_for_auction', 10, 2 );
 
function wsa_custom_rewrite_for_auction() {
  add_rewrite_rule('auction/([^/]+)(?:/([0-9]+))?/?$', 'index.php?product=$matches[1]&page=$matches[2]', 'top');
}
add_action('init', 'wsa_custom_rewrite_for_auction');

Comments