Skip to content

Instantly share code, notes, and snippets.

View WooForce's full-sized avatar

WooForce WooForce

View GitHub Profile
@WooForce
WooForce / functions.php
Last active April 30, 2021 09:38
Split cart into multiple packages based on shipping classes
add_filter( 'woocommerce_cart_shipping_packages', 'wf_split_cart_by_shipping_class_group' );
function wf_split_cart_by_shipping_class_group($packages){
//Reset packages
$packages = array();
//Init splitted package
$splitted_packages = array();
// Group of shipping class ids
$class_groups = array(
@WooForce
WooForce / functions.php
Last active September 24, 2020 21:46
Introduce vendor names along with standard labels across shipping packages
define("PV_ATTRIBUTE", "vendor");
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if ( ! class_exists( 'TH_Shipping_Options' ) ) {
class TH_Shipping_Options {
/**
@WooForce
WooForce / functions.php
Created August 19, 2016 10:52
WooCommerce - Customize Cart / Checkout Page No Shipping Methods Available message based on Zip Code.
// For Cart Page.
add_filter( 'woocommerce_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
// For Checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'wf_customize_default_message', 10, 1 );
function wf_customize_default_message( $default_msg ) {
$zip_array = array(
'30031',
);
if ( in_array( WC()->customer->get_shipping_postcode() , $zip_array) ) {
@WooForce
WooForce / my-custom-shipping-cost.php
Created June 8, 2016 05:08
Plugin to calculate My Custom Shipping Cost
<?php
/*
Plugin Name: My Custom Shipping
Description: Plugin to calculate My Custom Shipping Cost
Version: 1.0.0
Author: WooForce
Author URI: http://www.wooforce.com
*/
function my_custom_shipping_init() {
@WooForce
WooForce / functions.php
Last active September 6, 2018 13:11
DHL Express - Change currency conversion rate with live data
add_filter( 'wf_dhl_conversion_rate', 'alter_conversion_rate',10,2);
function alter_conversion_rate($rate, $dhl_currency){
if( !function_exists('get_woocommerce_currency')){
return;
}
$from_currency = urlencode($dhl_currency);
$to_currency = urlencode(get_woocommerce_currency());
try {
@WooForce
WooForce / functions.php
Last active December 1, 2017 05:10
Hide shipping method based on shipping class
add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_based_on_shipping_class', 10, 2);
function wf_hide_shipping_method_based_on_shipping_class($available_shipping_methods, $package)
{
$hide_when_shipping_class_exist = array(
42 => array(
'free_shipping'
)
);
@WooForce
WooForce / functions.php
Last active November 29, 2017 05:12
Add additional fee to shipping options based on Shipping Class
add_filter( 'woocommerce_package_rates', 'adjustment_in_rates_of_product_with_shipping_class', 10, 2 );
function adjustment_in_rates_of_product_with_shipping_class( $available_shipping_methods, $package ) {
// Shipping class IDs that need to add extra cost
$shipping_class_ids = array(
0,
1,
);
// Give here extra cost you want add
@WooForce
WooForce / functions.php
Created April 6, 2016 09:51
Change the default "no available shipping methods" message on cart/checkout page
add_filter( 'woocommerce_cart_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1 );
add_filter( 'woocommerce_no_shipping_available_html', 'change_msg_no_available_shipping_methods', 10, 1 );
function change_msg_no_available_shipping_methods( $default_msg ) {
$custom_msg = "Call us for quotation - 1-800-XXX-XXXX";
if( empty( $custom_msg ) ) {
return $default_msg;
}
return $custom_msg;
}
@WooForce
WooForce / functions.php
Created August 16, 2016 05:03
Adjusting puerto rico as state
function wf_remove_puerto_rico_country( $country ) {
if(array_key_exists('PR', $country))
{
unset($country['PR']);
}
return $country;
}
add_filter( 'woocommerce_countries', 'wf_remove_puerto_rico_country', 10, 1 );
function wf_add_puerto_to_us_states( $states ) {
@WooForce
WooForce / functions.php
Created May 18, 2016 14:25
Hide methods based on destination zip code
add_filter('woocommerce_package_rates', 'wf_hide_shipping_methods_based_on_zipcode', 10, 2);
function wf_hide_shipping_methods_based_on_zipcode($available_shipping_methods, $package){
$destination = $package['destination'];
$postcode = $destination['postcode'];
// Array of zipcodes with shipping methods to hide
$hide_methods = array(
'90002' => array(
'free_shipping',