25% off ProSNIPC25OFF

Snippet library

PHP snippets for WordPress.

467 free & Pro snippets and modules. Copy-paste-ready, or import in one click with SnipCraft.

PHPPro

Auto Cart Discount Over Spend Threshold

Automatically adds a flat-rate discount fee to the cart when the subtotal reaches or exceeds a configurable spending threshold, incentivising larger orders.

#cart#conversion#discount
PHPPro

Auto-Apply Coupon via URL Parameter

Reads a coupon code from the ?coupon_code= URL query parameter, stores it in the WooCommerce session, and applies it automatically when the cart or checkout page loads.

#coupon#discount#marketing
PHPPro

Require Account for High-Value Orders

Blocks guest checkout when the cart total meets or exceeds a configurable threshold, prompting the customer to log in or register before placing a high-value order.

#account#checkout#conversion
PHP

Add Custom Terms Checkbox at Checkout

Adds a required Terms and Conditions acceptance checkbox before the Place Order button on the WooCommerce checkout page and validates it server-side.

#checkout#compliance#terms
PHPPro

Remove and Reorder Checkout Fields

Streamlines the WooCommerce checkout form by removing unused fields such as Company and Address Line 2 and adjusting field order via priority values.

#billing#checkout#fields
PHP

Hide Coupon Field on Cart and Checkout

Disables the coupon entry field on both the cart and checkout pages to prevent discount hunting while keeping WooCommerce coupon functionality intact for admin-applied coupons.

#cart#checkout#coupon
PHPPro

Add Buy Now Button to Product Page

Adds a Buy Now button alongside Add to Cart on single product pages; clicking it adds the product to the cart and immediately redirects to checkout, bypassing the cart page.

#buy-now#checkout#conversion
PHP

Redirect to Checkout After Adding to Cart

Redirects customers directly to the checkout page after they add any product to the cart, reducing funnel steps for stores with a single-product or impulse-buy focus.

#cart#checkout#conversion
PHPPro

Add Quantity Selector to Shop Archive

Replaces the single-click Add to Cart link on shop and archive pages with a proper form containing a quantity input for simple in-stock products.

#archive#cart#quantity
PHP

Set Products per Shop Page

Controls how many products are displayed per page on WooCommerce shop and archive pages via the loop_shop_per_page filter.

#display#pagination#products
PHP

Hide Out-of-Stock Products From Catalog

Excludes out-of-stock products from shop and archive pages via a meta query, keeping catalog listings clean without disabling stock management.

#catalog#products#shop
PHP

Change Zero Price to Free Label

Replaces the WooCommerce '$0.00' price display with the word 'Free' for products that have a zero price, giving a more customer-friendly presentation.

#display#free-products#pricing
PHP

Prevent Duplicate Items in Cart

Blocks adding a product to the cart if it is already present, showing a friendly notice and redirecting the customer to the cart instead.

#cart#checkout#duplicates
PHP

Limit Cart to a Single Item

Prevents customers from adding more than one item to the cart at a time, clearing the existing item when a new product is added.

#cart#checkout#single-item
PHPPro

Set Maximum Quantity per Product

Enforces a store-wide cap on the quantity input for every product in WooCommerce, preventing bulk purchases beyond the configured limit.

#cart#checkout#limits
PHPPro

Auto-Cancel Unpaid Pending Orders

Cancels pending orders that have not been paid within a configurable number of hours, automatically releasing reserved stock back to inventory.

#automation#orders#pending
PHPPro

Auto-Complete Virtual and Downloadable Orders

Automatically moves orders to Completed status after payment when every item in the order is virtual or downloadable, skipping the manual Processing step.

#automation#digital#downloadable
PHP

Set the Default Payment Gateway

Pre-selects a specific payment gateway on the checkout page by moving it to the top of the available methods list.

#checkout#gateway#payment
PHPPro

Restrict Payment Gateways by Role

Shows or hides specific payment gateways based on the logged-in user's role, letting you offer invoice or bank-transfer options only to wholesale or trusted accounts.

#checkout#payment#roles
PHPPro

Restrict Payment Gateways by Cart Total

Hides specified payment gateways when the cart subtotal falls below a configurable minimum, useful for bank-transfer or invoice methods that are only practical on larger orders.

#cart#checkout#conditional
PHPPro

Restrict Shipping Methods by Role

Limits available shipping methods based on the current user's role so different customer segments see only the shipping options relevant to them.

#checkout#roles#shipping
PHPPro

Hide Other Shipping When Free Available

Removes all non-free shipping methods from the package rates when at least one free-shipping method is available, keeping checkout focused on the free option.

#checkout#free-shipping#shipping
PHPPro

Scheduled Cleanup of Unattached Media Files

Registers a weekly WP-Cron event that permanently deletes unattached media attachments older than 30 days to keep the media library tidy.

#cleanup#cron#maintenance
PHPPro

Allow Uploading Web Font Files

Adds WOFF, WOFF2, TTF, OTF, and EOT font formats to the WordPress upload allowlist so webfonts can be hosted in the media library.

#admin#fonts#media