Skip to content

Instantly share code, notes, and snippets.

@PluginHive
PluginHive / functions.php
Last active August 16, 2021 07:10
Snippet to define a custom date format to show Estimated delivery using the PluginHive's Estimated Delivery Date plugin for WooCommerce : https://www.pluginhive.com/product/estimated-delivery-date-plugin-woocommerce/
/**
* Snippet to define a custom date format to show Estimated Delivery Date
* Created at : 16 Aug 2021
* PluginHive Plugins : Estimated Delivery Date Plugin For WooCommerce
* Gist Link : https://gist.github.com/PluginHive/7fb8f48c6b6f1d30d33ad50cb1a37c2b
**/
add_filter( 'xa_change_estimated_delivery_date_format', 'ph_change_estimated_delivery_date_format' );
if( ! function_exists('ph_change_estimated_delivery_date_format') ) {
@PluginHive
PluginHive / functions.php
Last active December 16, 2020 06:16
Snippet to switch UPS Account Based on Shipping Class. WooCommerce UPS Shipping Plugin with Print Label - https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
/**
* Snippet to switch UPS Account Based on Shipping Class
* Created at : 16 December 2020
* PluginHive Plugins : Switch UPS Account Based on Shipping Class
* Gist Link : https://gist.github.com/PluginHive/a7cf9e022e34dc71c5f678d3bf7cb147
**/
add_filter( 'wf_ups_shipment_settings', 'ph_ups_modify_settings_datas', 10, 2 );
function ph_ups_modify_settings_datas( $settings, $order ) {
@PluginHive
PluginHive / gist:50f2e4a8ee142864dfab2a93368b6813
Created July 14, 2020 06:10
Code snippet to hide non-UPS shipping services if a customer selects an Access Point at Checkout. Work with PluginHive WooCommerce UPS Shipping Plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_if_accesspoint', 10, 2);
function wf_hide_shipping_method_if_accesspoint( $available_shipping_methods, $package ){
global $woocommerce;
$shipping_accesspoint = WC()->customer->__get('shipping_accesspoint');
if( !empty($shipping_accesspoint) ){
$decoded_accesspoint = json_decode($shipping_accesspoint);
if(isset($decoded_accesspoint->AddressKeyFormat)){
if( !empty( $decoded_accesspoint->AddressKeyFormat->AddressLine ) ){
@PluginHive
PluginHive / gist:da2ec389d120a886a0333cf094eba2d2
Created July 14, 2020 06:08
Code snippet to skip certain WooCommerce products from final packaging. Works only with WooCommerce Shipping Plugins from PluginHive: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
add_filter('wf_shipping_skip_product','skip_my_products',10,3);
function skip_my_products($skip = false, $product, $package){
$shipping_free_classes = array(16); // array of shipping class ids to exclude from cart
$shipping_class = $product['data']->get_shipping_class_id();
if(in_array($shipping_class, $shipping_free_classes)){
$skip = true;
}
@PluginHive
PluginHive / gist:6663f8aa7cfa993a9c803141a59c5928
Created April 24, 2020 12:02
Code snippet to Add extra costs based on box sizes using WooCommerce UPS Shipping Plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
add_filter('wf_ups_rate', 'wf_modify_ups_rate', 10, 2);
function wf_modify_ups_rate($xml, $packages){
//Config this array with box dimensions and rate to be added.
$extra_coast = array(
'7,9,8' => 10,
'10,6,8' => 15,
);
if($xml){
foreach ($extra_coast as $extra_coast_dim => $amount_to_add) {
@PluginHive
PluginHive / gist:1437b2fac7d9ca56ed0f9cc89239df59
Created April 23, 2020 15:20
Code snippet for UPS shipment tracking numbers to be included in the order export CSV/XML. Supported PluginHive plugin: https://www.pluginhive.com/product/woocommerce-ups-shipping-plugin-with-print-label/
// BEGIN export PluginHive WooCommerce UPS Shipping plugin tracking code. */
add_filter('hf_alter_csv_header', 'hf_csv_order_add_more_columns', 10, 1);
function hf_csv_order_add_more_columns($csv_columns) {
$csv_columns['ups_created_shipments_details_array'] = 'UPS Tracking Number';
return $csv_columns;
}
add_filter('hf_alter_csv_order_data', 'hf_csv_order_add_more_data', 10, 1);
function hf_csv_order_add_more_data($order_data) {
@PluginHive
PluginHive / gist:10f4cf617fdfb170c0b1c0f39b27d8e6
Created April 22, 2020 09:54
Code snippet to split the cart when both WooCommerce shipping classes of the products exist in the cart. Supported plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
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 {
/**
@PluginHive
PluginHive / gist:2b1814a49763026f9067e57de6e22cdd
Created April 22, 2020 09:52
Code snippet to assign a particular WooCommerce Shipping method based on your Product ID. Supported Plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter('woocommerce_package_rates', 'hide_shipping_method_if_particular_product_available_in_cart', 10, 2);
function hide_shipping_method_if_particular_product_available_in_cart($available_shipping_methods)
{
global $woocommerce;
// products_array should be filled with all the products ids
// for which shipping method (stamps) to be restricted.
$products_array = array(
@PluginHive
PluginHive / gist:78ca24fde27bf33a4824aceb4f55a4e1
Created April 22, 2020 09:47
Code snippet to display the Shipping phone number in the FedEx Shipping label in place of the billing phone number. Required plugin: https://www.pluginhive.com/product/woocommerce-fedex-shipping-plugin-with-print-label/
add_filter('wf_fedex_request','my_call_back', 10, 2 );
function my_call_back($request,$order){
$phone = !empty($order->shipping_phone) ? $order->shipping_phone : $order->billing_phone;
$request['RequestedShipment']['Recipient']['Contact']['PhoneNumber'] = $phone;
return $request;
}
@PluginHive
PluginHive / function.php
Created February 8, 2020 04:28
Customize recurrent bookings price display message.
add_filter('phive_booking_booked_price_details','phive_booking_booked_price_details',11,3);
function phive_booking_booked_price_details($price_details,$product_id,$post_details)
{
$custom_messages="This is a recurrent booking. Your upcoming bookings are : ";
$new_message = "This class series meets at the green date above, and:";
if(isset($price_details['custom_messages']) )
{
$price_details['custom_messages'] = str_replace($custom_messages, $new_message, $price_details['custom_messages']);