Reputation: 418
I am trying to build a slider of users with vendors role, and trying to get the vendors url from dokan plugin here is what I am trying to generate the link for each vendor in the slider loop but it is not working :
function store_query_filter( $query ) {
global $wp_query;
$author = get_query_var( $query->custom_store_url );
if ( !is_admin() && $query->is_main_query() && !empty( $author ) ) {
$seller_info = get_user_by( 'slug', $author );
$store_info = dokan_get_store_info( $seller_info->data->ID );
if ( !empty( $store_info['store_name'] ) ) {
$vendor_link = dokan_get_store_url( $store_info->ID );
return $vendor_link;
}
}
}
add_shortcode( 'store_vendor_url', 'store_query_filter' );
Upvotes: 1
Views: 3898
Reputation: 418
I managed to solve it by adding this to the function.php and register the shortcode,
function get_store_url($atts){
$a = shortcode_atts(
array(
'id' => '1',
),
$atts );
$seller_id = get_user_by( 'id', $a['id'] );
$vendor = dokan()->vendor->get( $seller_id );
return $vendor->get_shop_url();
}
add_shortcode( 'store_vendor_url', 'get_store_url' );
now I can either use :
[store_vendor_url id="5"]
or :
[store_vendor_url id="[wpv-user field='ID']"]
Upvotes: 3