Useful WooCommerce Hooks & Snippets

December 12, 2025
Useful WooCommerce Hooks & Snippets

WooCommerce is built around WordPress actions and filters. Once you know a few key hooks, you can customize product pages, cart/checkout behavior, and emails without editing core files or installing extra plugins.

This post collects practical WooCommerce hooks and snippets you can copy into a child theme’s functions.php or a Code Snippets plugin.


Before You Add Snippets

  • Test on staging first.
  • Add one snippet at a time.
  • Keep a rollback option (Code Snippets safe mode or FTP access).
  • Escape output and sanitize user input.

1) Product Page Hooks

Add text under the price

add_action( 'woocommerce_single_product_summary', function() {
  echo '<p class="product-note">Free shipping on orders over $50.</p>';
}, 11 );

woocommerce_single_product_summary is a key hook for adding content around title/price/excerpt/add-to-cart on single product pages.


Move the product short description (excerpt)

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 35 );

This changes the placement by adjusting priority.


Remove product tabs (Description / Reviews / Additional Info)

add_filter( 'woocommerce_product_tabs', function( $tabs ) {
  unset( $tabs['reviews'] );          // Reviews tab
  unset( $tabs['additional_information'] ); // Additional info tab
  return $tabs;
}, 99 );

Rename product tabs

add_filter( 'woocommerce_product_tabs', function( $tabs ) {
  if ( isset( $tabs['description'] ) ) {
    $tabs['description']['title'] = 'Details';
  }
  if ( isset( $tabs['reviews'] ) ) {
    $tabs['reviews']['title'] = 'Customer Reviews';
  }
  return $tabs;
}, 98 );

Change “Add to cart” text (simple products)

add_filter( 'woocommerce_product_single_add_to_cart_text', function( $text ) {
  return 'Buy Now';
});

For archive pages, use woocommerce_product_add_to_cart_text.


Disable zoom / lightbox / slider on product gallery

add_action( 'after_setup_theme', function() {
  remove_theme_support( 'wc-product-gallery-zoom' );
  remove_theme_support( 'wc-product-gallery-lightbox' );
  remove_theme_support( 'wc-product-gallery-slider' );
}, 100 );

2) Shop & Category Page Hooks

Change number of products per page

add_filter( 'loop_shop_per_page', function( $per_page ) {
  return 24;
}, 20 );

Change number of columns on shop pages

add_filter( 'loop_shop_columns', function() {
  return 3;
});

Remove sorting dropdown

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

Remove result count (“Showing 1–12 of 200 results”)

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );

3) Cart & Checkout Hooks

Remove “Coupon code” field on checkout

remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );

Rename checkout fields (labels/placeholders)

add_filter( 'woocommerce_checkout_fields', function( $fields ) {
  $fields['billing']['billing_first_name']['label'] = 'First name';
  $fields['billing']['billing_phone']['placeholder'] = 'e.g. +1 555 123 4567';
  return $fields;
});

Make phone optional

add_filter( 'woocommerce_checkout_fields', function( $fields ) {
  $fields['billing']['billing_phone']['required'] = false;
  return $fields;
});

Force checkout login for guests

add_action( 'template_redirect', function() {
  if ( function_exists( 'is_checkout' ) && is_checkout() && ! is_user_logged_in() ) {
    wp_safe_redirect( wp_login_url( wc_get_checkout_url() ) );
    exit;
  }
});

Use this only if you intentionally require accounts (it can reduce conversions).


Minimum order amount (block checkout compatible)

add_action( 'woocommerce_checkout_process', function() {
  $minimum = 50; // currency units
  if ( WC()->cart && WC()->cart->total < $minimum ) {
    wc_add_notice(
      sprintf( 'Minimum order amount is %s.', wc_price( $minimum ) ),
      'error'
    );
  }
});

Remove shipping fields when shipping is not needed

add_filter( 'woocommerce_cart_needs_shipping_address', function( $needs_address ) {
  return false;
});

Useful for digital products-only stores.


4) Account & Login Hooks

Change “My Account” menu items

add_filter( 'woocommerce_account_menu_items', function( $items ) {
  unset( $items['downloads'] );
  $items['edit-account'] = 'Account Settings';
  return $items;
}, 99 );

Redirect users after login (example: to My Account)

add_filter( 'woocommerce_login_redirect', function( $redirect, $user ) {
  return wc_get_page_permalink( 'myaccount' );
}, 10, 2 );

5) Emails Hooks

Add content to order emails

add_action( 'woocommerce_email_after_order_table', function( $order, $sent_to_admin, $plain_text, $email ) {
  if ( $plain_text ) {
    echo "\nThank you for your order!\n";
    return;
  }
  echo '<p>Thank you for your order! Need help? Reply to this email.</p>';
}, 10, 4 );

Change “From” name for WooCommerce emails

add_filter( 'woocommerce_email_from_name', function( $name ) {
  return 'My Store Support';
});

6) Pricing & Product Logic Hooks

Hide prices for guests

add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
  if ( ! is_user_logged_in() ) {
    return '<a href="' . esc_url( wp_login_url() ) . '">Login to see price</a>';
  }
  return $price;
}, 10, 2 );

Disable checkout if cart contains a specific product

add_action( 'woocommerce_check_cart_items', function() {
  $blocked_product_id = 123;

  foreach ( WC()->cart->get_cart() as $item ) {
    if ( (int) $item['product_id'] === $blocked_product_id ) {
      wc_add_notice( 'This item cannot be purchased at the moment.', 'error' );
      break;
    }
  }
});

7) Performance-Friendly Tweaks

Disable WooCommerce scripts/styles on non-Woo pages

Only use this if your theme doesn’t load Woo components site-wide (like mini-cart on every page).

add_action( 'wp_enqueue_scripts', function() {
  if ( function_exists( 'is_woocommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ) ) {
    return;
  }

  wp_dequeue_style( 'woocommerce-general' );
  wp_dequeue_style( 'woocommerce-layout' );
  wp_dequeue_style( 'woocommerce-smallscreen' );

  wp_dequeue_script( 'wc-add-to-cart' );
  wp_dequeue_script( 'woocommerce' );
  wp_dequeue_script( 'wc-cart-fragments' );
}, 99 );

Disable WooCommerce widgets if unused

add_action( 'widgets_init', function() {
  unregister_widget( 'WC_Widget_Cart' );
  unregister_widget( 'WC_Widget_Product_Search' );
}, 11 );

Small win, but helpful on lean sites.


Where to Put These Snippets

  • Best: Code Snippets plugin (easy enable/disable per snippet)
  • Also OK: Child theme functions.php
  • Best for many snippets: a small custom plugin (keeps logic independent of theme)

Conclusion

WooCommerce becomes much easier to customize once you know a handful of core hooks. Start with small changes (text labels, tab tweaks, checkout fields), then move into more advanced logic (minimum order, email customization, performance optimization).

If you want, tell me what you’re trying to customize (product page, cart/checkout, emails, or performance), and I’ll generate a clean snippet set tailored to your exact setup.

Avatar

Written by

satoshi

I’ve been building and customizing WordPress themes for over 10 years. In my free time, you’ll probably find me enjoying a good football match.