Allow (or prevent) Free Shipping when a gift card is redeemed
1. Download the free Code Snippets plugin: https://wordpress.org/plugins/code-snippets/
2. Create a Snippet with the following code:
Allow Free Shipping when a gift card is redeemed:
function custom_woocommerce_shipping_free_shipping_is_available( $is_available, $package, $wc_shipping_method ) {
if ( true !== $is_available ) {
$session_data = (array) WC()->session->get( PWGC_SESSION_KEY );
if ( isset( $session_data['gift_cards'] ) && count( $session_data['gift_cards'] ) > 0 ) {
$is_available = true;
}
}
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'custom_woocommerce_shipping_free_shipping_is_available', 10, 3 );
Do not allow Free Shipping when a gift card is redeemed:
function custom_woocommerce_shipping_free_shipping_is_available( $is_available, $package, $wc_shipping_method ) {
if ( true === $is_available ) {
$session_data = (array) WC()->session->get( PWGC_SESSION_KEY );
if ( isset( $session_data['gift_cards'] ) && count( $session_data['gift_cards'] ) > 0 ) {
$is_available = false;
}
}
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'custom_woocommerce_shipping_free_shipping_is_available', 99, 3 );