Skip to content

Instantly share code, notes, and snippets.

@PierreNodles
PierreNodles / woocommerce-force-free-shipping-specific-class.php
Created February 24, 2019 23:04
Activate the free shipping option only when the products in the cart all contain the same specific shipping class
<?php
// Replace 'shippingClass' with the specific class upon which you wish to make the free shipping option available
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'free_shipping_based_on_cart_shipping_class' );
function free_shipping_based_on_cart_shipping_class( $is_available ) {
$cart_items = WC()->cart->get_cart();
$found = false;
@PierreNodles
PierreNodles / woocommerce-force-local-pickup-specific-class.php
Created February 24, 2019 23:01
Force local pick up if a product containing a specific shipping class is in the cart
<?php
// Replace 'shipping-class' with the specific shipping class you want to force the local pick up upon
// To make it more readable, replace $shippingClass with your class name, eg : $hugeProducts
function my_hide_shipping_when_local_is_available( $rates ) {
$cart_items = WC()->cart->get_cart();
$shippingClass = false;
foreach ( $cart_items as $cart_item ) {
@PierreNodles
PierreNodles / vatdetailsanddiscountwoocommercepdfinvoice
Created October 22, 2018 22:37
Show VAT Details & Discount - Woocommerce PDF Invoice
add_filter( 'pdf_template_order_totals' , 'coupon_pdf_template_order_totals', 10, 2 );
function coupon_pdf_template_order_totals( $output, $order_id ) {
global $woocommerce;
if ( !$order_id ) {
return;
}
$order = new WC_Order( $order_id );