WooCommerce Snippets
1 min read

WooCommerce Snippets

WooCommerce Snippets
Photo by Fikret tozak / Unsplash

Sometimes the lack of settings and flexibility inside the WooCommerce engine calls for a functions.php modification. Of course there are those plugins that will fix all your problems, but don't forget, we are talking about your webshop.

Too many plugins won't give you any advantages because of the pain staking time of updating, and remember it will bloat your website, that's why, for small changes to the WooCommerce plugin, we use the functions.php inside your (hopefully) child theme. Here you can add minor changes to your template and or in this case WooCommerce plugin.

Hide shipping rates when Free Shipping is enabled/available.

For some reason, when the price is right and the user has access to free shipping, he is still able to select the prices shipping. Here is a snippet on how to hide it on the checkout page.

function hide_shipping_when_free_is_available($rates)
    $free = array();

    foreach ($rates as $rate_id => $rate) {
        if ('free_shipping' === $rate->method_id) {
            $free[$rate_id] = $rate;

    return !empty($free) ? $free : $rates;

add_filter('woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100);

Remove product dropdown filter from shop page.

add_filter( 'woocommerce_catalog_orderby','wc_remove_default_sorting_options' );

function wc_remove_default_sorting_options( $options ){
    unset( $options[ 'popularity' ] );
    unset( $options[ 'menu_order' ] );
    unset( $options[ 'rating' ] );
    unset( $options[ 'date' ] );
    unset( $options[ 'price' ] );
    unset( $options[ 'price-desc' ] );
    return $options;