Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / wc-add-currency-symbol.php
Last active July 7, 2024 14:50
Add a custom currency / symbol
/**
* Custom currency and currency symbol
*/
add_filter( 'woocommerce_currencies', 'add_my_currency' );
function add_my_currency( $currencies ) {
$currencies['ABC'] = __( 'Currency name', 'woocommerce' );
return $currencies;
}
@woogists
woogists / wc-core-apply-tax-based-on-subtotal.php
Last active July 5, 2024 16:51
Apply WooCommerce tax based on the subtotal
<?php
add_filter( 'woocommerce_product_get_tax_class', 'big_apple_get_tax_class', 1, 2 );
function big_apple_get_tax_class( $tax_class, $product ) {
if ( WC()->cart->subtotal <= 110 )
$tax_class = 'Zero Rate';
return $tax_class;
}
@woogists
woogists / wc-custom-tab.php
Last active July 1, 2024 14:20
[Frontend Snippets][Editing product data tabs] Customize a tab
/**
* Customize product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {
$tabs['description']['callback'] = 'woo_custom_description_tab_content'; // Custom description callback
return $tabs;
}
@woogists
woogists / wc-show-free-shipping-for-states-not-on-the-exclusion-list.php
Last active June 19, 2024 18:11
[General Snippets][Hide other shipping methods when “Free Shipping” is available] Show only free shipping in all states except exclusion list.
/**
* Hide ALL shipping options when free shipping is available and customer is NOT in certain states
*
* Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping
*/
add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 2 );
/**
* Hide ALL Shipping option when free shipping is available
*
@woogists
woogists / wc-hide-all-shipping-if-free-shipping-is-available.php
Last active May 14, 2024 12:47
[General Snippets][Hide other shipping methods when “Free Shipping” is available] Hides all other shipping methods but free_shipping if it’s available. Compatible with Shipping zones.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@woogists
woogists / wc-product-addons-set-default-value.js
Last active May 14, 2024 12:41
[Product Addons] Set default input values for addons.
// Set default value to 0 for Custom price input
jQuery(document).ready(function(){
jQuery('.wc-pao-addon-custom-price').val("0");
});
@woogists
woogists / wc-change-currency-symbol.php
Last active April 18, 2024 08:10
Change a currency symbol
/**
* Change a currency symbol
*/
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'AUD': $currency_symbol = 'AUD$'; break;
}
return $currency_symbol;
@woogists
woogists / wc-sample-products-loop.php
Last active April 17, 2024 19:18
[Theming Snippets] Sample products loop
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
@woogists
woogists / wc-customize-breadcrumb.php
Last active April 13, 2024 05:42
[Frontend Snippets][Customize the WooCommerce breadcrumb] Customize home text
/**
* Rename "home" in breadcrumb
*/
add_filter( 'woocommerce_breadcrumb_defaults', 'wcc_change_breadcrumb_home_text' );
function wcc_change_breadcrumb_home_text( $defaults ) {
// Change the breadcrumb home text from 'Home' to 'Apartment'
$defaults['home'] = 'Apartment';
return $defaults;
}
@woogists
woogists / wc-core-show-empty-taxes.php
Last active March 25, 2024 19:37
Show empty taxes
<?php
add_filter( 'woocommerce_order_hide_zero_taxes', '__return_false' );