Behind the Scenes: Developing a Custom WooCommerce Plugin
Ibrahim Monir
Full-Stack Developer

A behind-the-scenes look at building a custom WooCommerce plugin for a real client — why we went custom, the WooCommerce hooks that powered it, the tricky edge cases, and what shipped in the end.
Every custom plugin starts with a problem no off-the-shelf solution solves cleanly. A wholesale client came to me with exactly that: they needed role-based wholesale pricing and per-product minimum order quantities — and every plugin they tried was either bloated, slow, or did 80% of the job with no way to fix the last 20%. So we built a custom WooCommerce plugin. This is the behind-the-scenes story of how it came together: the decisions, the WooCommerce hooks that powered it, the edge cases that nearly broke it, and what finally shipped.
What the plugin needed to do
- Show wholesale prices automatically to logged-in wholesale customers, and normal prices to everyone else.
- Enforce a minimum order quantity per product at the cart and checkout.
- Add simple admin fields so the client could manage it all without touching code.
- Stay lightweight and fast — no dashboard bloat, no impact on store speed.
Key takeaways
- Build custom when the last 20% matters — that's usually where off-the-shelf plugins fall short.
- WooCommerce hooks do the heavy lifting — you extend behavior instead of overriding core.
- The edge cases are the real work — pricing display, caching, and cart validation take the most time.
- Keep it lean — a focused custom plugin beats a bloated multipurpose one on speed and maintainability.
Step 1: Discovery — understanding the real requirement
Before writing a line of code, I mapped out exactly how the client worked: which user role counted as "wholesale," how prices were set, and what the minimum-quantity rules were per product. Most plugin projects fail here — building the wrong thing perfectly. Getting the requirements precise up front saved days of rework later.
Step 2: Deciding to build custom vs. using an existing plugin
I always try to avoid reinventing the wheel. But the existing wholesale plugins added heavy admin dashboards, loaded scripts on every page, and still couldn't handle the client's specific minimum-quantity logic. A focused custom plugin would be smaller, faster, and do exactly what was needed — so custom won.
Step 3: Planning the architecture
I structured the plugin as a small, organized folder rather than one giant file — a main plugin file, plus separate includes for pricing, admin fields, and cart validation. Every file started with the standard ABSPATH guard, and every function was prefixed to avoid conflicts. Clean structure now means easy maintenance later.
Step 4: Building the core — hooking into WooCommerce pricing
The heart of the plugin was a single filter. WooCommerce lets you modify a product's price without touching core, so I hooked into woocommerce_product_get_price to return the wholesale price for the right users:
add_filter( 'woocommerce_product_get_price', 'store_wholesale_price', 20, 2 );
function store_wholesale_price( $price, $product ) {
if ( current_user_can( 'wholesale_customer' ) ) {
$wholesale = $product->get_meta( '_wholesale_price' );
if ( $wholesale !== '' ) {
return $wholesale;
}
}
return $price;
}
This is the beauty of WooCommerce: you extend behavior through hooks instead of hacking the platform.
Step 5: Adding the admin fields
The client needed to manage prices themselves, so I added custom fields to the product data panel — a wholesale price and a minimum quantity — saved as product meta. No code, no support tickets: they just fill in two boxes per product and the plugin handles the rest.
Step 6: The tricky part — cart and checkout validation
Enforcing minimum quantities was where the real work began. I hooked into woocommerce_check_cart_items so the rule was validated every time the cart or checkout loaded:
add_action( 'woocommerce_check_cart_items', 'store_enforce_min_qty' );
function store_enforce_min_qty() {
foreach ( WC()->cart->get_cart() as $item ) {
$min = (int) $item['data']->get_meta( '_min_order_qty' );
if ( $min && $item['quantity'] < $min ) {
wc_add_notice(
sprintf( 'You must order at least %d of %s.', $min, $item['data']->get_name() ),
'error'
);
}
}
}
The lesson: adding a feature is easy — enforcing it everywhere the customer can change quantities (cart, checkout, mini-cart) is the actual job.
Step 7: Handling the edge cases
This is where most of the time went. I had to make sure:
- Wholesale prices displayed correctly in price HTML, cart totals, and order emails — not just at checkout.
- Prices weren't cached and shown to the wrong user role.
- Sale prices, tax, and coupons still behaved correctly on top of wholesale pricing.
- The minimum-quantity notice was clear and didn't block unrelated products.
Edge cases are the difference between a demo that works and a plugin you can trust on a live store.
Step 8: Testing, performance, and security
Before launch I tested with real wholesale and retail accounts, empty carts, mixed carts, and boundary quantities. I confirmed the plugin added zero measurable load time, sanitized every admin input, escaped all output, and included the ABSPATH guard on every file. A plugin touching pricing and checkout has to be bulletproof.
Step 9: Launch and results
We deployed to a staging site first, ran the full purchase flow, then shipped it live. The result: wholesale customers saw their pricing automatically, minimum quantities were enforced without confusion, and the client managed everything from two simple fields — with none of the bloat of the plugins they'd tried before. It just worked, quietly, in the background.
Frequently asked questions
When should you build a custom WooCommerce plugin instead of using an existing one?
Build custom when existing plugins are too bloated, too slow, or can't handle your specific logic — especially when the last 20% of a requirement isn't configurable. A focused custom plugin is lighter, faster, and does exactly what you need, which often outweighs the upfront development time.
How do you change product prices in WooCommerce with code?
Use the woocommerce_product_get_price filter (and related pricing filters) to modify a product's price dynamically without editing core. Inside the filter you can apply role-based pricing, discounts, or custom logic, then return the adjusted price — WooCommerce handles the rest across the cart and checkout.
How do you enforce minimum order quantities in WooCommerce?
Hook into woocommerce_check_cart_items, loop through the cart, compare each item's quantity to its minimum, and use wc_add_notice() to show an error if the minimum isn't met. This validates the rule on both the cart and checkout pages so it can't be bypassed.
Is a custom plugin better than a page builder add-on for WooCommerce?
For focused, performance-sensitive functionality, yes. A custom plugin loads only the code you need and does exactly one job well, while general add-ons often carry features and scripts you'll never use. For complex store logic, custom is usually the cleaner, faster, more maintainable choice.
Final thoughts
Building a custom WooCommerce plugin isn't about showing off — it's about solving a problem cleanly when nothing off the shelf quite fits. The pattern is always the same: understand the real requirement, extend WooCommerce through its hooks rather than fighting it, and spend your time on the edge cases that make it trustworthy. Done right, a custom plugin disappears into the background and just works — which, for the client running the store, is exactly what success looks like.
