Skip to content

Instantly share code, notes, and snippets.

@JeroenSormani
JeroenSormani / hide-shipping-if-free-shipping-is-available.php
Last active October 20, 2022 09:36
New - Hide paid shipping rates when free is available. DOES show Local Pickup. Considered ANY shipping rate that is $0 as free (so the 'Free shipping' shipping method is not a requirement)
<?php
/**
* Copy from here to your (child) themes functions.php
* Recommended to do so via FTP.
*/
/**
* Hide all but the free shipping options when free is available.
*
@JeroenSormani
JeroenSormani / wc-advanced-fees-custom-subtotal.php
Created February 10, 2016 17:48
WC Advanced Fees - custom subtotal
<?php
function custom_wcaf_fee_amount_subtotal( $subtotal ) {
$subtotal = 0;
$category_id = '61'; // Your category ID here.
$cart_items = WC()->cart->get_cart();
foreach ( $cart_items as $key => $item ) {
@JeroenSormani
JeroenSormani / woocommerce-store-wide-disable-sales.php
Last active December 14, 2023 18:29
WC disable sale on all products.
<?php
/**
* Disable all sales.
*
* A simple function to disable all the sales in the shop.
* Uncomment the line of code to disable the sale price on products.
*/
function custom_wc_get_sale_price( $sale_price, $product ) {
@JeroenSormani
JeroenSormani / woocommerce-dont-apply-discount-on-sale-items.php
Created February 2, 2016 12:50
Don't apply coupon codes to sale products
<?php
function custom_wc_coupon_validity( $valid, $product, $this, $values ) {
if ( $product->is_on_sale() ) {
return false;
}
return $valid;
}
@JeroenSormani
JeroenSormani / advanced-product-labels--dynamic-pricing-compatibility.php
Last active June 13, 2021 16:44
A compatibility function to make Advanced Product Labels and Dynamic Pricing work nicely together (percentage discount)
<?php
/**
* WooCommerce Advanced Product Labels / Dynamic Pricing smart labels
*/
function dynamic_pricing_advanced_product_labels_compat( $label ) {
global $product;
if ( ! $product ) :
$product_posts = get_posts( array( 'post_type' => 'product', 'posts_per_page' => 1 ) );
@JeroenSormani
JeroenSormani / woocommerce-custom-order-action.php
Last active September 11, 2023 17:02
Add a new action to the order action drop down
add_action('woocommerce_order_actions', 'custom_wc_order_action', 10, 1 );
function custom_wc_order_action( $actions ) {
if ( is_array( $actions ) ) {
$actions['custom_action'] = __( 'My custom action' );
}
return $actions;
}
@JeroenSormani
JeroenSormani / woocommerce-custom-no-shipping-available-message.php
Last active July 4, 2021 08:44
Add a custom 'No shipping methods available' message
<?php
add_filter( 'woocommerce_no_shipping_available_html', 'my_custom_no_shipping_message' );
add_filter( 'woocommerce_cart_no_shipping_available_html', 'my_custom_no_shipping_message' );
function my_custom_no_shipping_message( $message ) {
return __( 'A minimum of 6 products is required. Add more products to complete your purchase' );
}
@JeroenSormani
JeroenSormani / wc-redirect-after-add-to-cart.php
Created May 30, 2015 08:39
WooCommerce redirect after add to cart
/**
* Redirect to checkout at add-to-cart action.
*/
function redirect_to_checkout() {
return WC()->cart->get_checkout_url();
}
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout' );
------------------------------------
@JeroenSormani
JeroenSormani / wapl-change-existing-label-color.css
Created December 30, 2014 14:28
WAPL - Change existing label color
.wapl-label .label-yellow {
background-color: #f1c40f;
}