Custom permalink wc marketplace vendor/product-name
I’m developing a marketplace website. At some point I’m stuck and waiting for your support. I use the WC Marketplace plugin. Different vendors can also sell the same product. However, there are some problems:
When different vendors add the same product, a different new URL is created. Like this:
1st seller: x.com/pizza/ — 2nd seller: x.com/pizza-2/
I want to customize this URL per vendor. For example:
x.com/pizza-first-seller/ — x.com/pizza- second-seller/
With the code below, I can get the nickname of the vendor and add it to the URL structure, but I couldn’t add it wherever I want. And when I wanted to view the products I got a 404 error.
I want:
- Getting the vendor page URL instead of the nickname. (I tried the code _vendor_page_slug instead of nickname but it returned empty)
- Adding the vendor page URL to the end of the product name.
- To be able to view the product pages.
My code:
function dab_prefix_filter_vendor_permalink ($post_link, $post, $leavename, $sample) {
global $WCMp, $product;
$vendor = get_wcmp_product_vendors ($product->id);
if ($vendor) (
$term_vendor = wp_get_post_terms($product->id, dc_vendor_shop);
$store_name = $vendor->user_data->nickname;
$post_link = str_replace ('%vendor_slug%', $store_name, $post_link);
}
return $post_link;
}
add_filter ('post_type_link', 'dab_prefix_filter_vendor_permalink', 10, 4);
Leave an answer
You must login or register to add a new answer .