Skip to content

Instantly share code, notes, and snippets.

@bporcelli
bporcelli / functions.php
Last active March 20, 2019 19:36
Shows how to register a custom pickup shipping method using the wootax_local_pickup_methods filter.
/**
* Register the Local Pickup Plus method with WooTax
*/
function wootax_add_local_pickup_method( $methods ) {
$methods[] = 'local_pickup_plus'; // Detected on frontend
$methods[] = 'Local Pickup Plus'; // Detected on backend
return $methods;
}
@bporcelli
bporcelli / functions.php
Created March 24, 2015 19:12
Shows how the wootax_origin_address filter can be used to change the Shipping Origin Address for a product.
/**
* Searches for a business address in NV and returns its key
*/
function wootax_use_nv_address( $address_key, $customer_state, $object ) {
$all_addresses = fetch_business_addresses();
foreach ( $all_addresses as $key => $address ) {
if ( $address['state'] = 'NV' )
return $key;
}
@bporcelli
bporcelli / functions.php
Created March 24, 2015 19:20
Uses the wootax_pickup_address filter to add support for the Local Pickup Plus shipping method.
/**
* Determine which address to use as the "destination address" based on the customer's Local Pickup selection
*/
function wootax_maybe_swap_dest_address( $address_index, $addresses, $order_id ) {
global $woocommerce, $wpdb;
$local_pickup_locations = get_option( 'woocommerce_pickup_locations' );
$location_id = -1; // Local Pickup Plus location ID
@bporcelli
bporcelli / functions.php
Last active March 20, 2019 19:35
Shows how to use the wootax_local_delivery_methods filter to register a custom delivery method.
/**
* Register the Custom Local Delivery method with WooTax
*/
function wootax_add_local_delivery_method( $methods ) {
$methods[] = 'custom_local_delivery'; // Detected on frontend
$methods[] = 'Custom Local Delivery'; // Detected on backend
return $methods;
}
@bporcelli
bporcelli / functions.php
Created March 30, 2015 16:46
Demonstrates the usage of the wootax_shipping_tic filter
/**
* Set shipping TIC to 90022
*/
function wootax_change_shipping_tic( $tic ) {
return 90022;
}
add_filter( 'wootax_shipping_tic', 'wootax_change_shipping_tic' );
@bporcelli
bporcelli / functions.php
Created March 30, 2015 16:49
Demonstrates the usage of the wootax_fee_tic filter
/**
* Change WooTax fee TIC to 11000
*/
function wootax_change_fee_tic( $tic ) {
return 11000;
}
add_filter( 'wootax_fee_tic', 'wootax_change_fee_tic' );
/**
* Substitute WooTax rate code with SALES-TAX
*/
function change_wootax_rate_code( $rate_code ) {
return "SALES-TAX";
}
add_filter( 'wootax_rate_code', 'change_wootax_rate_code' );
/**
* Change the taxable amount for product with ID 25 to 5 dollars
*/
function change_wootax_taxable_price( $price, $is_checkout, $item_id ) {
if ( $is_checkout && $item_id == 25 ) {
return 5;
} else {
return $price;
}
}
@bporcelli
bporcelli / functions.php
Created June 5, 2015 20:02
Demonstrates the usage of the wootax_rate_label filter.
/**
* Change the WooTax rate label to "Tax"
*/
function change_wootax_rate_label( $rate_label ) {
return "Tax";
}
add_filter( 'wootax_rate_label', 'change_wootax_rate_label', 10, 1 );
function hide_cart_taxes( $enabled ) {
if ( is_checkout() ) {
return true;
} else {
return false;
}
}
add_filter( 'wc_tax_enabled', 'hide_cart_taxes' );