Skip to content

Instantly share code, notes, and snippets.

@xadapter
xadapter / functions.php
Last active December 20, 2023 15:36
Snippet to hide WooCommerce shipping methods based on order subtotal cost. Supports PluginHive Shipping Plugins : https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/. If you are looking for a plugin to do this job, visit https://elextensions.com/plugin/conditionally-hide-woocommerce-shipping-methods-plugin/
/**
* Snippet to hide shipping methods based on Order Subtotal cost.
* Created at : 07 May 2018
* Updated at : 07 May 2018
* PluginHive Plugins : https://www.pluginhive.com/product-category/woocommerce-plugin/
* Gist Link : https://gist.github.com/xadapter/a477c0ec1334e69426674b21f4b033c9
*/
add_filter( 'woocommerce_package_rates', 'xa_show_hide_shipping_based_on_order_subtotal', 10, 2 );
@xadapter
xadapter / functions.php
Last active December 20, 2023 15:35
Snippet to customize the “There are no shipping methods available..” message found on the WooCommerce cart or checkout page based on cart total weight. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
// For Cart Page.
add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message_if_weght_exceeds', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message_if_weght_exceeds', 10, 1 );
function wf_customize_default_message_if_weght_exceeds( $default_msg ) {
$weight_limit = 50;
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
global $woocommerce;
$cart_weight = $woocommerce->cart->get_cart_contents_weight();
@xadapter
xadapter / style.css
Created August 3, 2018 05:02
Snippet to override the calendar CSS of woocommerce-booking-and-appointments plugin https://www.pluginhive.com/product/woocommerce-booking-and-appointments/
//Change the color of text "pick Please a booking period" here.
.callender-msg{
color:white;
}
//Change the color of the calendar here.
.ph-calendar-month{
background:red;
}
@xadapter
xadapter / functions.php
Last active January 26, 2022 21:06
Set a default weight and dimensions for the products in your WooCommerce store. Useful for WooCommerce shipping plugins like https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/ Supports ELEX Shipping Plugins https://elextensions.com/product-category/shipping/
/**
* Snippet to set default weight and Dimension if it's not set for any product.
* Created at : 14 May 2018
* Updated at : 16 May 2018
* PluginHive Plugins : https://www.pluginhive.com/product-category/woocommerce-plugin/
* Gist Link : https://gist.github.com/xadapter/4fb8dbfc6c025630558e43488775eb7d
*/
// To set Default Length
add_filter( 'woocommerce_product_get_length', 'xa_product_default_length' );
@xadapter
xadapter / functions.php
Last active March 26, 2021 14:32
Snippet to round off the weight to one decimal(always higher) at package level. WooCommerce FedEx Shipping Plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter( 'wf_fedex_packages', 'wf_fedex_weight_round_off');
if( ! function_exists('wf_fedex_weight_round_off') ) {
function wf_fedex_weight_round_off($packages) {
foreach( $packages as $key => $package) {
$package['Weight']['Value'] = $package['Weight']['Value'] + 0.05; //For rounding up to higher
$weight = round( $package['Weight']['Value'], 1 );
$packages[$key]['Weight']['Value'] = !empty($weight) ? $weight : 0.1;
}
return $packages;
@xadapter
xadapter / functions.php
Last active March 10, 2021 04:48
Snippet to change the default WooCommerce shipping method. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
function wf_default_shipping_method( $method ) {
$the_cheapest_cost = 1000000;
$packages = WC()->shipping()->get_packages()[0]['rates'];
foreach ( array_keys( $packages ) as $key ) {
if ( ( $packages[$key]->cost > 0 ) && ( $packages[$key]->cost < $the_cheapest_cost ) ) {
$the_cheapest_cost = $packages[$key]->cost;
$method_id = $packages[$key]->id;
}
}
/**
* Title : Snippet to add Fixed amount of weight to the order.
* Created at : 25 June 2018
* Updated at : 25 June 2018
* PlugiHive Plugins : https://www.pluginhive.com/product-category/woocommerce-plugin/
* Gist Link : https://gist.github.com/xadapter/f330a6f529dfa9199a30ec2fa9fca3ef
*/
add_filter( 'wf_customize_package_on_cart_and_checkout', function( $package ) {
@xadapter
xadapter / functions.php
Last active September 16, 2020 16:56
Snippet to add extra cost per package to the WooCommerce UPS rate. WooCommerce UPS Shipping Plugin with Print Label - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
/**
* Snippet to add extra cost per package to the Woocommerce UPS rate.
* Created at : 12 July 2018
* Updated at : 12 July 2018
* PluginHive Plugins : https://www.pluginhive.com/plugins/
* Gist Link : https://gist.github.com/xadapter/5a6404c130dbc61883bda20c392933a4
*/
add_filter( 'wf_ups_rate', function( $response ) {
$cost_to_add_per_package = 10; // Add fixed cost to shipping rate per package
@xadapter
xadapter / functions.php
Last active September 8, 2020 21:29
Snippet to clear the default WooCommerce shipping methods/options on the cart and checkout pages. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
// To test this code, open a private/incognito window, add an item to the cart and then go to cart page.
// Once an option is choosen, it will be the default option from that moment onwards.
// Code to clear default shipping option.
add_filter( 'woocommerce_shipping_chosen_method', '__return_false', 99);
// Code to clear default payment option.
add_filter( 'pre_option_woocommerce_default_gateway' . '__return_false', 99 );
@xadapter
xadapter / functions.php
Last active September 3, 2020 11:34
Snippet to add one additional day to the estimated delivery date for FedEx shipping services. WooCommerce FedEx Shipping Plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter( 'wf_fedex_estimated_delivery', 'wf_add_delivery_time', 15, 20 );
function wf_add_delivery_time( $est_delivery_html, $est_delivery ) {
$days_to_add = 1;
if( isset($est_delivery['fedex_delivery_time']) ){
$new_date = strtotime( "+$days_to_add day", strtotime($est_delivery['fedex_delivery_time']) );
$new_date = date( apply_filters('wf_estimate_delivery_date_format', 'd-m-Y' ), $new_date );
$est_delivery_html = "<br /><small>".__('Est delivery: ', 'wf-shipping-fedex'). $new_date.'</small>';
}
return $est_delivery_html;