category ↓

Coding Snippets

Copy-ready PHP snippets for WooCommerce and WordPress, with notes on where to add them and what each hook does.

How to Add Custom PHP Code in WordPress (Without Breaking Your Site)
Coding Snippets Apr 9

How to Add Custom PHP Code in WordPress (Without Breaking Your Site)

Quick answer: The safest way to add custom PHP to WordPress is a code snippets plugin, because the code survives theme updates and a…

Zohaib
Read
WooCommerce Cart Fees with PHP: woocommerce_cart_calculate_fees Hook + Examples
Coding Snippets Mar 24

WooCommerce Cart Fees with PHP: woocommerce_cart_calculate_fees Hook + Examples

Quick answer: Hook a function to woocommerce_cart_calculate_fees and call $cart->add_fee( 'Label', $amount, $taxable ) inside it. WooCommerce runs the hook every time it recalculates…

Tom Anbinder
Read
Insert Standard Text in All WordPress Posts Automatically
Coding Snippets Dec 31

Insert Standard Text in All WordPress Posts Automatically

Quick answer: To show the same content under every post, hook a function to the the_content filter that appends your HTML when is_single() is…

Zohaib
Read
How to Customize the WooCommerce Add to Cart Button (Text, Color, Style & Position)
Coding Snippets Nov 27

How to Customize the WooCommerce Add to Cart Button (Text, Color, Style & Position)

Quick answer: To change the Add to Cart button text, use the woocommerce_product_single_add_to_cart_text filter (single product pages) and woocommerce_product_add_to_cart_text (shop pages), or set labels…

Zohaib
Read
How to Hide WooCommerce Products by User Role Using PHP Snippets
Coding Snippets Aug 3

How to Hide WooCommerce Products by User Role Using PHP Snippets

Quick answer: To hide a product from certain roles, return false from the woocommerce_product_is_visible filter when the current user has that role. To keep…

Tom Anbinder
Read
Get WooCommerce Product Price by ID (PHP): get_price(), get_regular_price() & get_sale_price()
Coding Snippets Jun 6

Get WooCommerce Product Price by ID (PHP): get_price(), get_regular_price() & get_sale_price()

Quick answer: Load the product with wc_get_product( $product_id ), then call get_price() for the current price, get_regular_price() or get_sale_price() for the individual prices, or…

Tom Anbinder
Read
all access · lifetime

The plugins behind most of what we write about.

A lot of the posts here reference WPFactory plugins because that's what we build with. All Access gets you every plugin we make, on as many sites as you run. Pay once. Own it.

lifetime, once
$ 499 once
vs. $59.99/yr per plugin, break-even after 9 plugins
  • Every WPFactory plugin, current and future
  • Unlimited sites, no per-site caps
  • Lifetime updates, no renewals
  • 30-day refund, no questions asked