Add free shipping notices on WooCommerce product price

By | March 21, 2021

Here is the custom code for adding free shipping notices based on the WooCommerce product price

  • 1 free shipping notice if the price is lower than 25 €
  • 1 free shipping notice if the price is higher than 25 €

you need to add the below code in the functons.php file of the website’s child theme.

 

add_action( ‘woocommerce_single_product_summary’, ‘custom_single_product_summary_text’, 15 );
function custom_single_product_summary_text() {
global $product;

$price_threshold = 25;

// Avoid ‘cadeaux’ product category
if( has_term( array(‘Cadeaux’), ‘product_cat’, $product->get_id() ) ) {
return;
}

if( $product->is_type(‘variable’) ) {
$price = $product->get_variation_price( ‘min’, true ); // Min price
} else {
$price = wc_get_price_to_display( $product );
}

// If price is lower than 25
if ( $price < $price_threshold ) {
$message = __(“+ livraison gratuite jusqu’à 25€(Belgique, France, Pays-Bas)”, “text_domain”);
}
// If price is up to 25
else {
$message = __(“+ livraison gratuite à partir de 25 € (Belgique, France, Pays-Bas)”, “text_domain”);
}
echo ‘

‘ . $message . ‘

‘;
}

Leave a Reply

Your email address will not be published. Required fields are marked *