Handy WooCommerce Code Snippets

WooCommerce is a very heavily used plugin to turn your WordPress child site into a full eCommerce store.

MainWP offers a very easy to use code snippets extension which makes it easy to run code snippets over all of the connect child sites.

A couple of common of handy code snippets if you needed to temp disable all products from being purchasable on your child site you can use this code snippet;

add_filter( 'woocommerce_is_purchasable', '__return_false');

You would then need to deactivate that code snippet from the child sites where it was running.

Another common code snippet fix would be for changing the read more button text which normally shows for products which are out of stock you can make that change using this code snippet;

add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
    if ( 'Read more' == $text ) {
        $text = __( 'More Info', 'woocommerce' );

    return $text;
} );

Going along with the previous code snippet if you wanted to change the link that would show for out of stock products you can use this code snippet;

Manage all your WordPress sites with the MainWP Dashboard

WordPress Management for Professionals

Are you ready to go Pro?

All MainWP Pro Extensions are available through one of our convenient bundled packages.

add_filter( 'woocommerce_product_add_to_cart_url', 'out_of_stock_read_more_url', 50, 2 );
function out_of_stock_read_more_url( $link, $product  ) {
    // Only for "Out of stock" products
    if( $product->get_stock_status() == 'outofstock' ){

        // Here below we change the link
        $link = home_url("/");
    return $link;

Using the code snippets extension is an easy way to make code changes over all connect child sites.

Remember to join the MainWP community which has a whole category where new handy code snippets are being added every week.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Looking for something?

Your Download Is Just One Click Away

…or just download the plugin.

By entering your email, you agree to our Terms of Service and Privacy Policy.