WordPress Codesnippets

woocommerce best selling products widget


if ( ! empty( $title ) )
echo $before_title . $title . $after_title;

// Widget code here
// …

echo $after_widget;

This code registers a widget to display best selling products on a WordPress website. It creates a Woocommerce_Best_Selling_Products_Widget class and calls the register_widget function, passing in the new widget class. Within the widget function, it extracts the widget arguments and applies a filter to the title. Finally, it displays the widget title before and after the widget code.

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »