Created
September 14, 2017 12:25
-
-
Save webdados/d1f1c4f71a69a34c6084d573b8a40862 to your computer and use it in GitHub Desktop.
New "apg_sms_procesa_el_telefono" function with filters to override processing Raw
This file contains 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 | |
function apg_sms_procesa_el_telefono( $pedido, $telefono, $servicio, $propietario = false, $envio = false ) { | |
if ( apply_filters( 'apg_sms_procesa_el_telefono_processar', true, $pedido, $telefono, $servicio, $propietario, $envio ) ) { //Filter added by Marco Almeida - Should return false if no processing should be done | |
$numero_de_pedido = is_callable( array( $pedido, 'get_id' ) ) ? $pedido->get_id() : $pedido->id; | |
$billing_country = is_callable( array( $pedido, 'get_billing_country' ) ) ? $pedido->get_billing_country() : $pedido->billing_country; | |
$shipping_country = is_callable( array( $pedido, 'get_shipping_country' ) ) ? $pedido->get_shipping_country() : $pedido->shipping_country; | |
$prefijo = apg_sms_prefijo( $servicio ); | |
$telefono = str_replace( array( '+','-' ), '', filter_var( $telefono, FILTER_SANITIZE_NUMBER_INT ) ); | |
if ( !$propietario ) { | |
if ( ( !$envio && $billing_country && ( WC()->countries->get_base_country() != $billing_country ) || $prefijo ) ) { | |
$prefijo_internacional = apg_sms_dame_prefijo_pais( $billing_country ); //Teléfono de facturación | |
} else if ( ( $envio && $shipping_country && ( WC()->countries->get_base_country() != $shipping_country ) || $prefijo ) ) { | |
$prefijo_internacional = apg_sms_dame_prefijo_pais( $shipping_country ); //Teléfono de envío | |
} | |
} else if ( $propietario && $prefijo ) { | |
$prefijo_internacional = apg_sms_dame_prefijo_pais( WC()->countries->get_base_country() ); | |
} | |
preg_match( "/(\d{1,4})[0-9.\- ]+/", $telefono, $prefijo_telefonico ); | |
if ( empty( $prefijo_telefonico ) ) { | |
return; | |
} | |
if ( isset( $prefijo_internacional ) ) { | |
if ( strpos( $prefijo_telefonico[1], $prefijo_internacional ) === false ) { | |
$telefono = $prefijo_internacional . $telefono; | |
} | |
} | |
if ( ( $servicio == "moreify" || $servicio == "twilio" ) && strpos( $prefijo[1], "+" ) === false ) { | |
$telefono = "+" . $telefono; | |
} else if ( $servicio == "isms" && isset( $prefijo_internacional ) ) { | |
$telefono = "00" . preg_replace( '/\+/', '', $telefono ); | |
} | |
} //Added by Marco Almeida | |
return apply_filters( 'apg_sms_procesa_el_telefono_return', $telefono, $pedido, $telefono, $servicio, $propietario, $envio ); //Filter added by Marco Almeida - Should return the phone number using the developer own rules | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment