Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@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'),
@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-add-currency-symbol.php
Last active February 28, 2024 05:36
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-pdf-watermark-adding-more-tags-watermarks.php
Created March 9, 2018 15:08
[WooCommerce PDF Watermark] Adding More Tags To Text Watermarks
/*
* Snippet to add more tags to text watermarks.
* Code goes in the functions.php file in your theme.
*/
function wc_pdf_watermark_extend_template_tags( $parsed_text, $unparsed_text, $order, $product ) {
// Look for {product_title} in text and replace it with the product title
$parsed_text = str_replace( '{product_title}', $product->get_title(), $parsed_text );
return $parsed_text;
}
add_filter( 'woocommerce_pdf_watermark_parse_template_tags', 'wc_pdf_watermark_extend_template_tags', 10, 4 );