Custom development
Develop custom WooCommerce online store features via hooks, snippets and custom code when standard extensions are insufficient.
In this chapter :

Hooks and filters
Hooks and filters are the extensibility system of WordPress and WooCommerce, allowing you to modify behavior without touching the core code.
Actions vs filters
Actions execute code at a precise moment (for example, sending an email after an order, or adding a column in the admin).
Filters modify data before it is displayed or saved (e.g. product price, title, button text).
The fundamental difference: Actions do something, while Filters transform something.
Current WooCommerce hooks
Product Actions:
woocommerce_before_single_product- Before product displaywoocommerce_after_single_product_summary- After descriptionwoocommerce_product_thumbnails- Product image area
Checkout actions :
woocommerce_before_checkout_form- Before formwoocommerce_checkout_order_processed- Post-order validationwoocommerce_thankyou- Confirmation page
Price filters :
woocommerce_get_price_html- Price displaywoocommerce_cart_item_price- Basket pricewoocommerce_order_amount_total- Order total
Text filters :
woocommerce_product_single_add_to_cart_text- Text "Add to cart" buttonwoocommerce_breadcrumb_defaults- Breadcrumb trail
Practical examples
Edit text "Add to cart " button:
add_filter('woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_text');
function custom_add_to_cart_text($text) {
return 'Buy now';
}
Result: the button displays "Buy now" instead of "Add to cart".
Add custom text after product price :
add_action('woocommerce_single_product_summary', 'custom_text_after_price', 15);
function custom_text_after_price() {
echo '<p class="shipping-notice">Free shipping on orders over ā¬50</p>';
}
The priority 15 means that this text will be displayed after the price (which has priority 10) and before the add to cart button (which has priority 30).
Hide out-of-stock products :
add_filter('woocommerce_product_is_visible', 'hide_out_of_stock_products', 10, 2);
function hide_out_of_stock_products($visible, $product_id) {
$product = wc_get_product($product_id);
if (!$product->is_in_stock()) {
return false;
}
return $visible;
}
With this code, products whose stock is zero no longer appear in the catalog.
Find the right hook
Browser DevTools allow you to inspect an element, identify its CSS class (such as .single_add_to_cart_button), then search for "add to cart button hook" on Google.
Query Monitor (a plugin) displays hooks executed on the current page and their order of priority.
WooCommerce source code can be found in /wp-content/plugins/woocommerce/templates/ and contains all templates. The command grep -r "do_action" . lists all available actions.
The official documentation at woocommerce.github.io/code-reference/ provides a complete reference for all hooks and functions.
Be patient: finding the right hook represents 30% of the total effort. It's a gradual learning process.
Code snippets šŗ
Snippets are pieces of custom PHP code added to your site without the need to create a complete plugin.
Child theme functions.php
The functions.php file in your child theme is the standard location for snippets.
Procedure :
- Create a child theme (with the Child Theme Configurator plugin)
- Go to Appearance > Theme File Editor.
- Select your child theme from the drop-down menu
- Open the file
functions.php. - Add your code to the end of the file (before the
?>tag if it exists)
Example of adding a snippet to display custom text on the checkout page :
add_action('woocommerce_before_checkout_form', 'custom_checkout_message');
function custom_checkout_message() {
echo '<div class="custom-message">Enjoy 10% off with code WELCOME10</div>';
}
Save the file, then test your checkout page to verify its display.
Advantages :
- Quick and easy to set up
- No need to install an additional plugin
Disadvantages:
- The file becomes huge and unreadable with over 100 snippets
- A PHP syntax error causes a fatal error.
- If you disable the theme, you lose all your snippets
Plugin code snippets
Code Snippets is a free plugin with over 3 million installations. It's a snippets manager with a secure interface.
Installation :
- Go to Extensions > Add and search for "Code Snippets".
- Click Activate after installation
- Go to Snippets > Add menu
To create a snippet:
- Give it a descriptive name, e.g. "Custom Add to Cart Text".
- Add your code:
add_filter('woocommerce_product_single_add_to_cart_text', function($text) {
return 'Buy now';
});
- Check the "Run snippet everywhere" option
- Click on Save and Activate.
Benefits:
- Visual interface, no need to use FTP or a code editor
- Possibility of deactivating a snippet without deleting the code (facilitates debugging)
- Syntax errors are detected, so your site doesn't break
- Export and import of snippets possible (for backup or migration)
- Organization of your snippets by category
Recommendation: Use Code Snippets rather than functions.php in 90% of cases.
Useful WooCommerce snippets
Minimum order ā¬30:
add_action('woocommerce_checkout_process', 'minimum_order_amount');
function minimum_order_amount() {
$minimum = 30;
if (WC()->cart->total < $minimum) {
wc_add_notice(sprintf('Minimum order: %sā¬', $minimum), 'error');
}
}
Heavy product handling fees :
add_action('woocommerce_cart_calculate_fees', 'heavy_item_fee');
function heavy_item_fee() {
if (is_admin() && !defined('DOING_AJAX')) return;
$heavy_fee = 0;
foreach (WC()->cart->get_cart() as $item) {
$product = $item['data'];
if ($product->get_weight() > 10) { // >10kg
$heavy_fee += 5;
}
}
if ($heavy_fee > 0) {
WC()->cart->add_fee('Frais manutention', $heavy_fee);
}
}
Product custom field :
// Add admin field
add_action('woocommerce_product_options_general_product_data', 'custom_product_field');
function custom_product_field() {
woocommerce_wp_text_input([
id' => '_custom_field',
label' => 'Warranty (month)',
type' => 'number'
]);
}
// Save
add_action('woocommerce_process_product_meta', 'save_custom_product_field');
function save_custom_product_field($post_id) {
$value = $_POST['_custom_field'];
if (!empty($value)) {
update_post_meta($post_id, '_custom_field', esc_attr($value));
}
}
// Display
add_action('woocommerce_single_product_summary', 'display_custom_field', 25);
function display_custom_field() {
global $product;
$value = get_post_meta($product->get_id(), '_custom_field', true);
if ($value) {
echo '<p>Guarantee: ' . $value . ' months</p>';
}
}
Repository snippets: Find more code snippets in our Hooks and filters directory and at businessbloomer.com, wpsnippets.com, github.com/woocommerce/woocommerce/wiki/snippets
Template modification šŗ
WooCommerce templates are PHP files located in the /templates/ folder that control the display of pages (product, cart, checkout).
Template structure
Templates are located in /wp-content/plugins/woocommerce/templates/ :
- single-product.php` - Individual product page
archive-product.php- Product list (category, store)cart/cart.php- Shopping cart pagecheckout/form-checkout.php- Checkout formmyaccount/my-account.php- Customer account
NEVER modify these files directly - WooCommerce updates overwrite them. Always use an override in your child theme.
Template override
To customize a template, copy it to your child theme, then modify the copy.
Procedure :
- Identify the template to be modified (e.g.
cart/cart.php) - Create the folder
/wp-content/themes/your-child/woocommerce/cart/. - Copy the file
/wp-content/plugins/woocommerce/templates/cart/cart.phpto the created folder. - Modify this copy as required
WooCommerce will give priority to the version present in your theme.
Example - Modify "Shopping Cart" title:
File /your-theme-enfant/woocommerce/cart/cart.php :
<h1><?php esc_html_e('Your selection', 'woocommerce'); ?></h1>
Instead of :
<h1><?php esc_html_e('Cart', 'woocommerce'); ?></h1>
Template updates
WooCommerce updates its templates in new versions. An overridden template that becomes obsolete can cause bugs.
WooCommerce System Status - Go to WooCommerce > Status > System > Templates tab.
This page lists all your overridden templates with their version. If you see cart.php version 3.5.0 when WooCommerce 8.0 uses cart.php 4.2.0, you will see an "Outdated" warning.
Recommended action: Compare your current template with the new version (use a diff tool like WinMerge or VSCode), then transfer your custom modifications to the new version.
Perform these checks twice a year after major updates.
Code-free alternatives
Elementor WooCommerce Builder (Pro version) lets you edit templates visually (product page, archive, shopping cart). No code required.
Theme Customizers (Storefront, Astra) offer template customization options without the need for overrides.
Choose these solutions whenever possible: maintenance is simplified.
REST API šŗ
The WooCommerce REST API exposes your store data (products, orders, customers) via HTTP endpoints. It enables third-party integrations, mobile applications and automations.
Authentication
API keys - WooCommerce > Settings > Advanced > REST API > Add key
Permissions :
- Read - Read-only (external analytics)
- Write** - Create/modify (imports)
- Read/Write - Complete (dangerous, limit)
Keep Consumer Key and Consumer Secret (displayed once).
Current endpoints
Base URL: https://votresite.com/wp-json/wc/v3/
Products :
GET /products- List all productsGET /products/{id}- Specific product details- POST /products` - Create product
PUT /products/{id}- Modify productDELETE /products/{id}- Delete product
Orders :
GET /orders- Order listGET /orders/{id}- Order details- POST /orders - Create order (rare, external payments)
PUT /orders/{id}- Change status
Customers :
GET /customers- Customer listGET /customers/{id}- Customer details
Documentation : woocommerce.github.io/woocommerce-rest-api-docs/
Example query
Retrieve products (cURL) :
curl https://votresite.com/wp-json/wc/v3/products \
-u consumer_key:consumer_secret
Create product (Python) :
python import requests from requests.auth import HTTPBasicAuth
url = "https://votresite.com/wp-json/wc/v3/products" auth = HTTPBasicAuth('ck_xxxxx', 'cs_xxxxx') data = { "name": "New Product", "type": "simple", "regular_price": "29.99", "description": "Product description" } response = requests.post(url, auth=auth, json=data) print(response.json())
**Modify command status** (JavaScript) :
```javascript
const axios = require('axios');
axios.put('https://votresite.com/wp-json/wc/v3/orders/123', {
status: 'completed'
}, {
auth: {
username: 'ck_xxxxx',
password: 'cs_xxxxx'
}
}).then(response => console.log(response.data));
Use cases
ERP synchronization - Daily stock import from internal system to WooCommerce.
Custom mobile app - Fetch products, place orders via React Native/Flutter app.
Advanced analytics - Export orders to BI tools (Tableau, Power BI).
Zapier/Make automations - Webhook order ā CRM, personalized emails, shipping management.
Marketplace - Multiple vendors manage catalogs via API (multi-vendor).
The REST API offers almost infinite integration power. However, it requires solid back-end development skills.
When to call on a developer šŗ
Some needs go beyond simple snippets.
Signals indicating the need for a developer
Complex functionality - You need a custom recurring subscription system, dynamic multi-criteria pricing, or integration with a proprietary ERP.
No existing plugin - You've searched WooCommerce.com, WordPress.org and CodeCanyon, but nothing quite fits your needs.
Critical performance - Your catalog contains over 100,000 products, you have complex queries and need custom database optimizations.
Sensitive security - You need to handle non-standard payments, complex GDPR data, or a multi-currency system with crypto conversions.
Budget available - Custom development costs between ā¬1,000 and ā¬10,000 depending on complexity. It's cost-effective if it's at the heart of your business.
WooCommerce developer profile
Skills required:
- Advanced PHP** (POO, namespaces, Composer)
- WordPress** (hooks, CPT, taxonomies, WP_Query)
- WooCommerce** (CRUD objects, sessions, cart API)
- MySQL** (query optimization, indexes)
- JavaScript** (React for modern checkout blocks)
- REST API** (third-party integrations)
- Git** (versioning, deployment)
Check the developer's portfolio with WooCommerce projects similar to yours. Ask for references from e-commerce customers.
Platforms
Upwork - International freelancers charging between $30 and $80/hour depending on location and expertise.
Codeur.com - French freelancers charging between 50 and 120ā¬/hr.
Malt - Premium French freelancers charging between ā¬400 and ā¬800 per day.
Specifications
A precise document avoids misunderstandings and budget overruns.
Must include :
- Business objective - For example, "Increase conversions by 20% via a simplified checkout".
- Detailed functionalities** - Written in the form of user stories ("As a customer, I want...").
- Designs and wireframes - Figma or Adobe XD mock-ups of key pages
- Integration requirements** - Third-party APIs (Stripe, Mailchimp, ERP)
- Technical constraints** - Your current hosting provider, existing technology stack
- Timeline** - Realistic deadline (3 to 6 months for medium-sized projects)
- Budget** - Clear, documented budget range
The more precise your specifications, the more precise your quote. Vague specifications can double the final budget.
Post-development maintenance
Custom code requires ongoing maintenance.
Updates - WordPress and WooCommerce are constantly evolving, so your custom code will require adjustments.
Bug fixes - Occasional fixes will be required.
Upgrades - You'll need to add new business features.
Maintenance contract - Expect to pay between ā¬500 and ā¬2000 per month, depending on complexity. Or an hourly rate of ā¬80 to ā¬120/hour.
Budget around 20% of the initial development cost per year for maintenance.
In a nutshell
WooCommerce custom development relies on hooks (actions and filters) to modify behavior without touching the core. Use code snippets via Code Snippets or functions.php of the child theme for small modifications. Create custom plugins for complex, reusable functionality. Consult official WooCommerce documentation and forums for tried-and-tested solutions before coding from scratch. Always staging test and comment your code to facilitate maintenance. Respect WordPress standards (PHP_CodeSniffer, WordPress Coding Standards) to guarantee quality and security.
Next steps šŗ
- Recommended - Selection of proven plugins
- Installation - Secure process
- Theme - Design without code
- Back - Overview
Navigation: ā Theme Customization | Custom Code | Next: Troubleshooting ā