This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Discount shipping cost based on number of items being purchased | |
* Further narrowed down to only run on BE Table Rate options | |
* Code snippets should be added to the functions.php file of your child theme | |
* | |
* @return array | |
*/ | |
add_filter( 'woocommerce_package_rates', 'add_shipping_percentage_discount', 10, 2 ); | |
function add_shipping_percentage_discount( $rates, $package ) { | |
// get number of items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Show the word "FREE" when shipping is free from third party shipping plugins | |
* Code snippets should be added to the functions.php file of your child theme | |
* (Updated for WooCommerce 3.5) | |
* | |
* @return string | |
*/ | |
add_filter( 'woocommerce_cart_shipping_method_full_label', function( $label, $method ) { | |
// only update for Free shipping methods | |
$has_cost = 0 < $method->cost; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hide a specific Table Rate option when the given shipping option is available to choose | |
* Code snippets should be added to the functions.php file of your child theme | |
* | |
* @return array | |
*/ | |
function hide_shipping_when_option_is_available( $rates, $package ) { | |
// setup the option IDs | |
$option_needed = 'betrs_shipping:8-1'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add ability to find and compare the stock status of items in Table Rate shipping | |
* Intended for Use with Per Order setups and Method Conditions | |
* https://codecanyon.net/item/table-rate-shipping-for-woocommerce/3796656?ref=bolderelements | |
* | |
* Code should be added to theme's functions.php file | |
*/ | |
function betrs_add_stock_status_cond( $conditions ) { | |
// add new option to list | |
$conditions['stock_status'] = 'Stock Status'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add the longest length to Cost types in Table Rate shipping | |
* Longest Length is a custom condition added in tutorial: | |
* https://www.bolderelements.net/support/knowledgebase/adding-new-condition/ | |
* | |
* Code should be added to theme's functions.php file | |
*/ | |
function betrs_modify_cost_every( $cost_units_every ) { | |
// add new condition's value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function betrs_add_longest_length_calc_class( $data, $items ) { | |
$item_lengths = array(); | |
// cycle through cart items | |
foreach( $items as $item_ar ) { | |
// only count the ones that apply to shipping | |
if( isset( $item_ar['data'] ) && $item_ar['data']->needs_shipping() ) { | |
// initialize necessary variables | |
$item = $item_ar['data']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Recalculate the order's length to ignore multiple quantities. | |
* | |
* Requires Table Rate Shipping 4.2+ | |
*/ | |
function betrs_modify_calculated_length( $calculated_totals, $items ){ | |
// ensure there are items in the cart | |
if( is_array( $items ) ) { | |
$length = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Adds the <img> tag to allowed tags in fields sanitized using the wp_kses_data function. | |
* | |
* This particularly helps with adding images to Compare Table Features for individual products | |
*/ | |
add_filter( 'wp_kses_allowed_html', 'my_kses_allowed_html_hook', 23, 2 ); | |
function my_kses_allowed_html_hook( $allowed_tags, $context = null ){ | |
if ( 'post' == $context && ! isset( $allowed_tags['img'] ) ) { | |
$allowed_tags['img'] = array( | |
'alt' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adjust the calculated quantity of items in the cart based on a specific product | |
* Code snippets should be added to the functions.php file of your child theme | |
* | |
* @return array | |
*/ | |
function adjust_item_qty_for_shipping( $data, $items ) { | |
// the Product ID of the product that needs to be adjusted | |
$item_to_change = 13; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hide a shipping option when the given shipping option is in the cart based on their titles | |
* Code snippets should be added to the functions.php file of your child theme | |
* | |
* @return array | |
*/ | |
function hide_shipping_when_option_is_available( $rates ) { | |
// shipping option titles to be removed and the requirement, respectively | |
$option_removed = 'Super Saver Shipping'; | |
$option_needed = 'Free Super Saver Shipping'; |