Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile

Brands REST API

The Brands REST API allows you to create, view, update, and delete individual, or a batch, of brands. The endpoint is /wp-json/wc/v1/products/brands which basically mimics /wp-json/wc/v1/products/categories. You can refer to the same documentation of product categories REST API.

In addition to /products/brands endpoints, the /products endpoints also updated to display brands in the response and check the JSON request for brands.

Examples

  • Retrieve all product brands:
@woogists
woogists / wc-replace-catalog-button-text-sold-out-products
Created February 2, 2026 13:33
[WooCommerce core] Use this snippet to adjust the button text for sold-out products in the product catalog view.
/**
* Change add to cart button text to "Sold Out" for out-of-stock products
* (except variable products, which keep their normal text like "Select options").
*/
function custom_sold_out_button_text( $text, $product ) {
if ( ! $product instanceof WC_Product ) {
return $text;
}
$type = $product->get_type();
// Keep default text for variable products and variations
@woogists
woogists / wc-min-order-amount.php
Last active November 6, 2025 16:40
Set a minimum order amount for checkout
/**
* Set a minimum order amount for checkout
*/
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
@woogists
woogists / wc-bookings-bookings_calendar_default_to_first_available.php
Created March 9, 2018 16:17
[WooCommerce Bookings] Make calendar default to first available booking
/**
* Will make the Bookings calender default to the month with the first available booking.
*/
add_filter( 'wc_bookings_calendar_default_to_current_date', '__return_false' );
@woogists
woogists / wc-delivery-counrty-surcharge.php
Last active October 23, 2025 21:02
[Frontend Snippets][Add a surcharge to cart and checkout] Add a surcharge based on the delivery country
/**
* Add a 1% surcharge to your cart / checkout based on delivery country
* Taxes, shipping costs and order subtotal are all included in the surcharge amount
*/
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
@woogists
woogists / apfs-hide-plans-for-specific-roles.php
Created August 20, 2025 20:00
[All Products for WooCommerce Subscriptions] Use this snippet to hide Subscription plans for specific user roles.
<?php
/**
* Plugin Name: All Products for WooCommerce Subscriptions - Hide Subscription plans for specific user roles.
* Plugin URI: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/
* Description: Use this snippet to hide Subscription plans for specific user roles.
* Version: 1.1
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Developer: Jason Kytros
*
@woogists
woogists / wc-xero-send-orders-as-draft-invoices.php
Last active July 7, 2025 06:53
[WooCommerce Xero] Send orders as Draft Invoices rather than Awaiting Payment
<?php
add_filter( 'woocommerce_xero_invoice_to_xml', 'change_xero_invoice_status_to_draft' );
function change_xero_invoice_status_to_draft($xml) {
// Search the XML data for AUTHORISED and replace with DRAFT
$xml = str_replace( 'AUTHORISED' , 'DRAFT' , $xml);
// Return the modified data
return $xml;
@woogists
woogists / woocommerce-subscriptions-download-access-after-cancelled.php
Last active May 15, 2025 08:53
[WooCommerce Subscriptions]: Give access to downloadable files even if Subscription is cancelled
<?php
/*
* Access to downloadable files associated with a subscription will, by default, expire
* when the subscription is no longer "active" or "pending-cancel".
* https://woocommerce.com/document/subscriptions/faq/#section-39
* This snippet overrides that behavior to allow access as per the Download Expiry settng
* when the subscription status is "cancelled"
*/
@woogists
woogists / wc-brands-sortable-taxonomies.php
Created March 9, 2018 16:45
[WooCommerce Brands] order the brands on the front end as it is showcased on the Admin Panel
add_filter( 'woocommerce_sortable_taxonomies','wt_sort_brands' );
function wt_sort_brands( $sortable ) {
$sortable[] = 'product_brand';
return $sortable;
}
@woogists
woogists / wc-products-displayed-per-page.php
Last active April 24, 2025 20:12
[Theming Snippets] Change number of products displayed per page
/**
* Change number of products that are displayed per page (shop page)
*/
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;