WooCommerce

WooCommerce Customization Without Plugins: Hooks, Filters, and Shortcodes

Text
Contents

Every additional plugin means another license to pay for, another update to keep track of, and more scripts loaded on every page. Yet a large share of WooCommerce changes can be made with a dozen or so lines of code — without installing anything. Below is a practical overview: where to put the code, how hooks and filters work, and ready-made snippets for the most common tasks.

Where to put your code — and where absolutely not to

Before you copy anything, there's one thing to settle. Never edit the files of a parent theme or the core of WordPress and WooCommerce. The first update will overwrite your changes, and you'll be left wondering why "something stopped working."

Three correct places:

LocationWhen
functions.php child themeChanges related to appearance and layout, tied to a specific theme
A small custom plugin (a single file in wp-content/plugins/)Functional changes that should survive a theme change — recommended
Code snippets pluginWhen you don't have FTP access; convenient, but adds a layer of dependencies

Before you upload anything to production: make a backup and test it in a staging environment. A single syntax error in PHP can take down your entire site — we describe the safe deployment procedure in WordPress updates.

Hook or filter — the difference in one sentence

An action (add_action) adds something at a specific point. A filter (add_filter) changes something along the way.

// ACTION — adds content at a specific point on the product page
add_action( 'woocommerce_before_add_to_cart_button', 'wsk_info_o_wysylce' );
function wsk_info_o_wysylce() {
    echo '<p class="wsk-wysylka">Ships within 24 hours for orders placed by 2:00 PM.</p>';
}

// FILTER — modifies a value that WooCommerce would display anyway
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wsk_tekst_przycisku' );
function wsk_tekst_przycisku() {
    return 'Zamawiam';
}

Function names always prefix with your own prefix (here: wsk_). A function named info_o_wysylce will sooner or later collide with an identical name from some plugin, and your site will stop working.

A map of the most important hook points

It's worth knowing a dozen or so places where things are most often added:

Product page – woocommerce_before_single_product — at the very top – woocommerce_single_product_summary — the block with the title, price, and button (order is determined by priority) – woocommerce_before_add_to_cart_button / woocommerce_after_add_to_cart_button – woocommerce_product_meta_end — below categories and tags

Cart and checkout – woocommerce_before_cart / woocommerce_after_cart_table – woocommerce_before_checkout_form — message above the form – woocommerce_review_order_before_submit — right above the payment button – woocommerce_thankyou — thank-you page

Product listing – woocommerce_before_shop_loop / woocommerce_after_shop_loop – woocommerce_before_shop_loop_item_title

Priority (third argument add_action) determines the order. Lower number = earlier. Default is 10.

Ready-made snippets for the most common tasks

Adding a tax ID (NIP) field to the order

Needed for business invoices — we cover the implementation context in our article on automatic invoices in WooCommerce.

add_filter( 'woocommerce_checkout_fields', 'wsk_dodaj_nip' );
function wsk_dodaj_nip( $fields ) {
    $fields['billing']['billing_nip'] = array(
        'label'    => 'Tax ID (if you want a company invoice)',
        'required' => false,
        'class'    => array( 'form-row-wide' ),
        'priority' => 35,
    );
    return $fields;
}

Hiding fields you don't need

Every unnecessary field in the cart means fewer completed orders — we cover this in more detail in cart abandonment.

add_filter( 'woocommerce_checkout_fields', 'wsk_usun_pola' );
function wsk_usun_pola( $fields ) {
    unset( $fields['billing']['billing_company'] );
    unset( $fields['billing']['billing_address_2'] );
    return $fields;
}

Free shipping over a set amount — a motivational message

add_action( 'woocommerce_before_cart', 'wsk_do_darmowej_dostawy' );
function wsk_do_darmowej_dostawy() {
    $prog    = 200;
    $koszyk  = WC()->cart->get_displayed_subtotal();
    if ( $koszyk < $prog ) {
        $brakuje = wc_price( $prog - $koszyk );
        echo '<div class="woocommerce-info">You're ' . $brakuje . ' away from free shipping.</div>';
    }
}

Changing the number of products per row

add_filter( 'loop_shop_columns', 'wsk_kolumny' );
function wsk_kolumny() {
    return 4;
}

Hiding a shipping method for selected products

Useful for oversized items that a standard courier can't ship:

add_filter( 'woocommerce_package_rates', 'wsk_ukryj_metode', 10, 2 );
function wsk_ukryj_metode( $rates, $package ) {
    foreach ( $package['contents'] as $item ) {
        if ( has_term( 'gabaryt', 'product_cat', $item['product_id'] ) ) {
            unset( $rates['flat_rate:1'] ); // replace with the ID of your method
            break;
        }
    }
    return $rates;
}

Shortcodes — when they're still useful

WooCommerce provides a set of shortcodes that let you insert products anywhere — including in blog post content or on a page built with Elementor:

[products limit="8" columns="4" orderby="popularity"]
[products category="karma-sucha" limit="4"]
[products on_sale="true" limit="4"]
[product_page id="99"]
[add_to_cart id="99"]

Two practical notes:

  • The cart and checkout are now built as blocks, not shortcodes. The older [woocommerce_cart] i [woocommerce_checkout] still work for backward compatibility, but new implementations are built with blocks.
  • The cart, checkout, and account pages must be excluded from caching. This is the most common cause of the "customer sees someone else's cart" problem.

A shortcode works well for sales woven into content — for example, a how-to article with a block of related products at the end. It's a simple way to make your blog actually work for sales.

Overriding templates — a last resort, not the first choice

WooCommerce lets you copy a template file to the folder woocommerce/ in your theme and edit it there. It works, but it has a serious drawback: an overridden template doesn't receive updates. After a major WooCommerce release, you'll see a warning about outdated templates, and in a worse scenario — a broken layout.

Order of preference, from best to worst:

  1. A setting in the WooCommerce admin panel
  2. A hook or filter
  3. CSS
  4. Template override — only when the first three have failed

When it stops paying off

Code snippets are great for individual changes. They stop being a good solution when:

  • You have dozens of snippets and nobody remembers what each one does,
  • the change requires custom database tables or a settings panel,
  • the code has to work identically across several stores,
  • an integration with an external system comes into play.

Then the right step is to consolidate it into a custom plugin — with documentation and versioning. If you need help with this kind of cleanup or with an unusual feature, we handle it as part of dedicated solutions, and when building a new store, we plan it from the start in a WooCommerce store project.

FAQ — WooCommerce hooks and customization

Do I need to know how to code to use these snippets? To copy them and swap in values — no. To modify the logic and debug errors — yes. Safety rule: if you don't understand what a given snippet does, don't deploy it to production without testing.

Where can I find a list of all WooCommerce hooks? In the official developer documentation and in the plugin's source code — hook names are visible there at every do_action i apply_filters. It's the most reliable source because it's always up to date.

Do hooks slow down a store? Not by themselves. Poor implementation does—for example, a database query running inside a product loop on a category page. You can check the performance impact in the context of Core Web Vitals.

What should I do if the site shows a white screen after uploading code? Remove the uploaded snippet via FTP or your hosting file manager. If the code was in a child theme, undo the change in functions.php. Enable WP_DEBUGto see the error message instead of a blank page.

Will the changes survive a WooCommerce update? Hooks and filters—usually yes, because they are part of the public API and rarely disappear. Overridden templates—not always; they need to be reviewed after major releases.

Author: Adrian Kamiński — Websky Studio, Poznań. Designer and developer — WooCommerce stores fine-tuned with code, not a stack of plugins.

Your feedback

Was this article helpful?

One click — it helps me choose future topics.

Share article

Websky Newsletter

New posts straight to your email.

Once a month — practical insights on WordPress, WooCommerce, SEO and AI. No spam, unsubscribe with one click.

  • Case studies from Polish projects
  • Checklists and templates to download
  • Google and WordPress changes in a nutshell

Your data goes to Websky Studio only. You can unsubscribe with one click in every message.

WooCommerce Store

Your store can sell more.

WooCommerce implementation and optimization: Przelewy24, InPost, BaseLinker, B2B price lists, and warehouse integrations. Quote within 24 hours of the brief.

Get a store quote