Created
September 2, 2021 16:26
-
-
Save GustavoNapa/e9923ca522ebf47632e982a544156a62 to your computer and use it in GitHub Desktop.
Mostrar aviso de valor minimo em loja Woocommerce em condições especificas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(is_user_logged_in()){ | |
if(WC()->customer->get_state() == "RJ" || (WC()->customer->get_state() == "SP" && WC()->customer->get_city() == "São Paulo")){ | |
if( $total <= $minimum_cart_total ) { | |
$saldo = $minimum_cart_total - $total; | |
$saldo_dec = number_format((float)$saldo, 2, ',', ''); | |
$singular = '<br />Falta <strong>R$ %s</strong> para atingir o valor mínimo.</div>'; | |
$plural = '<br />Faltam <strong>R$ %s</strong> para atingir o valor mínimo.</div>'; | |
if ( $saldo > 1 || $saldo < 1 ) { | |
$msg = $plural; | |
} else { | |
$msg = $singular; | |
} | |
if ( $total != 0 ) { | |
wc_add_notice( sprintf( '<div style="font-size: 15px;"><strong>O Pedido deve ter o valor mínimo de R$ %s.</strong>' | |
.'<br />O Valor total do seu pedido agora é de <strong>R$ %s</strong>.' | |
.$msg, | |
number_format((float)$minimum_cart_total, 2, ',', ''), | |
number_format((float)$total, 2, ',', ''), | |
$saldo_dec ), | |
'error' ); | |
} | |
remove_action( ‘woocommerce_proceed_to_checkout’,’woocommerce_button_proceed_to_checkout’, 20); | |
}else add_action( ‘woocommerce_proceed_to_checkout’,’woocommerce_button_proceed_to_checkout’, 20); | |
} | |
}else{ | |
wc_add_notice( sprintf( '<div style="font-size: 15px;"><strong>O Pedido deve ter o valor mínimo de R$ %s nas regiões do Rio de Janeiro e São Paulo.</strong>' | |
.'<br />O Valor total do seu pedido agora é de <strong>R$ %s</strong>.' | |
.'<br />Caso você pertença a estas regiões pode ser impedido de continuar na tela de Finalização de compra caso não atenda o pedido minimo' | |
.$msg, | |
number_format((float)$minimum_cart_total, 2, ',', ''), | |
number_format((float)$total, 2, ',', ''), | |
$saldo_dec ), | |
'success' ); | |
add_action( ‘woocommerce_proceed_to_checkout’,’woocommerce_button_proceed_to_checkout’, 20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment