Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@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-add-currency-symbol.php
Last active May 12, 2024 17:38
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-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' );
@woogists
woogists / wc-core-adjust-non-base-location-prices.php
Last active March 25, 2024 19:36
Customers everywhere pay the same price and the difference in taxes is absorbed by adjusting the product price relative to the tax.
<?php
add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false' );
@woogists
woogists / wc-core-apply-tax-based-on-subtotal.php
Last active March 15, 2024 17:02
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-override-checkout-fields.php
Created March 11, 2018 15:11
[Customizing checkout fields using actions and filters] Add new shipping fields to WooCommerce
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder' => _x('Phone', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),