Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / hide-trailing-zeros-on-prices.php
Last active August 2, 2023 02:25
[General Snippets][Hide trailing zeros on prices]
/**
* Trim zeros in price decimals
**/
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );

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 / hide-all-shipping-keep-local-free.php
Created July 4, 2018 11:19
[General Snippets][Hide other shipping methods, but keep "Local pickup" when “Free Shipping” is available]
/**
* Hide shipping rates when free shipping is available, but keep "Local pickup"
* Updated to support WooCommerce 2.6 Shipping Zones
*/
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
foreach ( $rates as $rate_id => $rate ) {
// Only modify rates if free_shipping is present.
if ( 'free_shipping' === $rate->method_id ) {
@woogists
woogists / wc-change-default-country-non-existing.php
Last active July 9, 2018 19:25
[Frontend Snippets] Change the default country on the checkout (non-existing users only)
/**
* Change the default country on the checkout for non-existing users only
*/
add_filter( 'default_checkout_billing_country', 'change_default_checkout_country', 10, 1 );
function change_default_checkout_country( $country ) {
// If the user already exists, don't override country
if ( WC()->customer->get_is_paying_customer() ) {
return $country;
}
@woogists
woogists / wc-query-woocommerce-active.php
Last active March 1, 2023 14:02
[Theming Snippets] Query whether WooCommerce is activated
/**
* Check if WooCommerce is activated
*/
if ( ! function_exists( 'is_woocommerce_activated' ) ) {
function is_woocommerce_activated() {
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
}
}
@woogists
woogists / wc-checkout-validation-styles-third-party-theme.css
Created March 12, 2018 13:55
[Theming Snippets] Add checkout validation styles to a third party or custom theme
.form-row.woocommerce-invalid .chzn-single,
.form-row.woocommerce-invalid .chzn-drop,
.form-row.woocommerce-invalid input.input-text,
.form-row.woocommerce-invalid select {
border:1px solid red;
}
.form-row.woocommerce-validated .chzn-single,
.form-row.woocommerce-validated .chzn-drop,
.form-row.woocommerce-validated input.input-text,
.form-row.woocommerce-validated select {
@woogists
woogists / wc-remove-related-products.php
Last active December 29, 2023 16:55
[Theming Snippets] Remove related products output
@woogists
woogists / wc-show-product-categories-wooframework-breadcrumbs.php
Last active November 26, 2021 23:24
[Theming Snippets] Show product categories in WooFramework breadcrumbs
/**
* Show product categories in Woorramework breadcrumbs
*/
// Get breadcrumbs on product pages that read: Home > Shop > Product category > Product Name
add_filter( 'woo_breadcrumbs_trail', 'woo_custom_breadcrumbs_trail_add_product_categories', 20 );
function woo_custom_breadcrumbs_trail_add_product_categories ( $trail ) {
if ( ( get_post_type() == 'product' ) && is_singular() ) {
global $post;
@woogists
woogists / wc-change-placeholder-image.php
Last active October 2, 2023 08:26
[Theming Snippets] Change the placeholder image
/**
* Change the placeholder image
*/
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
// replace with path to your image
$src = $uploads . '/2012/07/thumb1.jpg';
@woogists
woogists / wc-change-number-of-upsells.php
Last active November 26, 2021 23:25
[Theming Snippets] Change number of upsells output
/**
* Change number of upsells output
*/
add_filter( 'woocommerce_upsell_display_args', 'wc_change_number_related_products', 20 );
function wc_change_number_related_products( $args ) {
$args['posts_per_page'] = 1;
$args['columns'] = 4; //change number of upsells here
return $args;