Last active
April 2, 2023 18:07
-
-
Save fernandoacosta/f42f9da7d995483a88b4 to your computer and use it in GitHub Desktop.
WooCommerce -- limitar venda em determinado CEP
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
<?php | |
add_filter( 'woocommerce_package_rates', 'wc_restrict_sales_by_postcode', 10, 2 ); | |
function wc_restrict_sales_by_postcode( $rates, $package ) { | |
$cep = WC()->customer->get_shipping_postcode(); | |
$cep = preg_replace( "/[^0-9]/", "",$cep ); | |
if ( '95555000' !== $cep ) { | |
$rates = array(); | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Opa.
Sobre a linha 8 ($rates = array();) é correto retornar apenas este array vazio? Você poderia me ajudar a entender este trecho? Estou tentando limitar para Cep's apenas da Grande BH então teria de mudar a condição para algo como:
if ( $cep > 30000 && $cep < 35000 ) { $rates = array(); }
estou correto?
Agradeço por compartilhar!