Skip to content

Instantly share code, notes, and snippets.

@luizbills
Last active July 14, 2017 14:24
Show Gist options
  • Save luizbills/c1dc8e653a3bd246527de40cc54b893e to your computer and use it in GitHub Desktop.
Save luizbills/c1dc8e653a3bd246527de40cc54b893e to your computer and use it in GitHub Desktop.
Mostra uma notificação informando quanto precisa comprar a mais para ter frete grátis
<?php
add_action( 'woocommerce_check_cart_items', 'lpb_free_shipping_cart_notice' );
function lpb_free_shipping_cart_notice () {
if ( ! is_cart() ) return;
// mude o valor 150 para o valor mínimo do frete grátis
$free_shipping_amount = 150;
// modelo da mensagem (não remova o "%s")
$message = 'Compre mais %s para ter frete grátis!';
$cart_amount = WC()->cart->cart_contents_total;
$diff = $free_shipping_amount - $cart_amount;
if ( $diff > 0 ) {
wc_print_notice( sprintf( __( $message, 'lpb-free-shipping-cart-notice' ), wc_price( $diff ) ), 'notice' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment