Below, you’ll find a detailed guide on how to add the Dokan Lite Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Dokan Lite Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Dokan Lite Plugin and the shortcodes it provides:
"Dokan is a superior WooCommerce multivendor marketplace solution. It empowers you to build your own Amazon, eBay, or Etsy styled marketplace effortlessly."
- [dokan_best_selling_product_per_page]
Dokan Lite [dokan_best_selling_product_per_page] Shortcode
The Dokan-Lite plugin shortcode is designed to render a list of best-selling products. It uses the ‘dokan_best_selling_product_per_page’ filter to determine the number of products to display, and accepts ‘no_of_product’ and ‘seller_id’ as parameters. It then generates a query to fetch the best selling products based on these parameters. The shortcode starts an output buffer, iterates through the query results, and for each post, it gets the ‘content-product’ template part. After the loop, it resets the post data and returns the buffered output.
Shortcode: [render_shortcode]
Parameters
Here is a list of all possible render_shortcode shortcode parameters and attributes:
no_of_product
– defines the number of best selling products to display.seller_id
– specifies the ID of the seller whose products are displayed.
Examples and Usage
Basic example – A simple usage of the shortcode to display the eight best selling products from a specific seller. Here, ‘seller_id’ is the unique identifier of the seller.
[dokan_best_selling_products no_of_product=8 seller_id=123 /]
Advanced examples
Using the shortcode to display the top five best selling products. If ‘seller_id’ is not provided, the shortcode will return the top selling products from all sellers.
[dokan_best_selling_products no_of_product=5 /]
Using the shortcode to display the top ten best selling products from a specific seller. Here, ‘seller_id’ is the unique identifier of the seller.
[dokan_best_selling_products no_of_product=10 seller_id=456 /]
These examples demonstrate the versatility of the dokan_best_selling_products shortcode. You can adjust the ‘no_of_product’ and ‘seller_id’ attributes to customize the output to your specific needs.
PHP Function Code
In case you have difficulties debugging what causing issues with [render_shortcode]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( $this->shortcode, [ $this, 'render_shortcode' ] );
Shortcode PHP function:
function render_shortcode( $atts ) {
/**
* Filter return the number of best selling product per page.
*
* @since 2.2
*
* @param array
*/
$atts_val = shortcode_atts(
apply_filters(
'dokan_best_selling_product_per_page', array(
'no_of_product' => 8,
'seller_id' => '',
), $atts
), $atts
);
ob_start();
?>
<ul class="products">
<?php
$best_selling_query = dokan_get_best_selling_products( $atts_val['no_of_product'], $atts_val['seller_id'] );
?>
<?php
while ( $best_selling_query->have_posts() ) :
$best_selling_query->the_post();
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; ?>
</ul>
<?php
wp_reset_postdata();
return ob_get_clean();
}
Code file location:
dokan-lite/dokan-lite/includes/Abstracts/DokanShortcode.php
Conclusion
Now that you’ve learned how to embed the Dokan Lite Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply