WooCommerce Code Snippets

WooCommerce is a free eCommerce plugin that allows you to sell anything, beautifully. Built to integrate seamlessly with WordPress, WooCommerce is the world’s favorite eCommerce solution that gives both store owners and developers complete control.

With endless flexibility and access to hundreds of free and premium WordPress extensions, WooCommerce now powers 30% of all online stores. From simple stores to complex multivendor marketplaces, WooCommerce has you covered.

WooCommerce action hooks are functions that allow you to modify the behavior of WooCommerce. For example, you can use an action hook to add extra functionality to WooCommerce or to change the default behavior of WooCommerce.

WooCommerce filter hooks are functions that allow you to modify the output of WooCommerce. For example, you can use a filter hook to change the way WooCommerce displays prices or to add extra information to the order confirmation page.

Both action and filter hooks are defined in the WooCommerce plugin code and can be used by custom code that you write or by plugins and themes that you install.

If you’re a WooCommerce developer, then you know that finding high-quality code snippets can be tough. That’s why we’ve put together this roundup of the best WooCommerce code snippets.

These snippets can be used to change any elements on a WooCommerce shop.

WooCommerce Snippets


Add Sort by Featured
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
  $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    if ( 'featured' == $orderby_value ) {
        $args['orderby'] = '_featured';
        $args['order'] = 'asc';
        $args['meta_key'] = '';
    return $args;
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortbyfeatureed['featured'] = 'Featured';
    $sortby = $sortbyfeatureed + $sortby;
    return $sortby;
Change "Add to Cart" button text
Add product attributes to archive pages
Remove or edit “[Product] has been added to your cart” message


Get WooCommerce Thumbnail Size

Menu & Navigation

Modify breadcrumb: remove Home item
Check if current page is checkout or cart

Leave a Comment

Your email address will not be published.