Skip to content

Commit

Permalink
Versión 2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
artprojectgroup committed May 30, 2020
1 parent 69154df commit 9fe8cc8
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 176 deletions.
Binary file modified .DS_Store
Binary file not shown.
46 changes: 36 additions & 10 deletions apg-sms.php
@@ -1,15 +1,15 @@
<?php
/*
Plugin Name: WC - APG SMS Notifications
Version: 2.19
Version: 2.20
Plugin URI: https://wordpress.org/plugins/woocommerce-apg-sms-notifications/
Description: Add to WooCommerce SMS notifications to your clients for order status changes. Also you can receive an SMS message when the shop get a new order and select if you want to send international SMS. The plugin add the international dial code automatically to the client phone number.
Author URI: https://artprojectgroup.es/
Author: Art Project Group
Requires at least: 3.8
Tested up to: 5.4
Tested up to: 5.5
WC requires at least: 2.1
WC tested up to: 4.0.1
WC tested up to: 4.2
Text Domain: woocommerce-apg-sms-notifications
Domain Path: /languages
Expand Down Expand Up @@ -156,9 +156,9 @@ function apg_sms_procesa_estados( $pedido, $notificacion = false ) {
$campo_envio = ( isset( $campo_envio[0] ) ) ? $campo_envio[0] : '';
$telefono = apg_sms_procesa_el_telefono( $pedido, $billing_phone, $apg_sms_settings[ 'servicio' ] );
$telefono_envio = apg_sms_procesa_el_telefono( $pedido, $campo_envio, $apg_sms_settings[ 'servicio' ], false, true );
$enviar_envio = ( $telefono != $telefono_envio && isset( $apg_sms_settings[ 'envio' ] ) && $apg_sms_settings[ 'envio' ] == 1 ) ? true : false;
$internacional = ( $billing_country && ( WC()->countries->get_base_country() != $billing_country ) ) ? true : false;
$internacional_envio = ( $shipping_country && ( WC()->countries->get_base_country() != $shipping_country ) ) ? true : false;
$enviar_envio = ( !empty( $telefono_envio ) && $telefono != $telefono_envio && isset( $apg_sms_settings[ 'envio' ] ) && $apg_sms_settings[ 'envio' ] == 1 ) ? true : false;
$internacional = ( isset( $billing_country ) && ( WC()->countries->get_base_country() != $billing_country ) ) ? true : false;
$internacional_envio = ( isset( $shipping_country ) && ( WC()->countries->get_base_country() != $shipping_country ) ) ? true : false;

//Teléfono propietario
if ( strpos( $apg_sms_settings[ 'telefono' ], "|" ) ) {
Expand Down Expand Up @@ -213,8 +213,14 @@ function apg_sms_procesa_estados( $pedido, $notificacion = false ) {
//Limpia el temporizador para pedidos recibidos
wp_clear_scheduled_hook( 'apg_sms_ejecuta_el_temporizador' );

$mensaje = apg_sms_procesa_variables( $mensaje_recibido, $pedido, $apg_sms_settings[ 'variables' ] ); //Mensaje para el cliente

//Retardo para pedidos recibidos
if ( isset( $apg_sms_settings[ 'retardo' ] ) && $apg_sms_settings[ 'retardo' ] > 0 && ( ! intval( get_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', true ) ) == 1 ) ) {
wp_schedule_single_event( time() + ( absint( $apg_sms_settings[ 'retardo' ] ) * 60 ), 'apg_sms_ejecuta_el_retraso', [ $numero_de_pedido ] );
update_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', -1 );
} else { //Envío normal
$mensaje = apg_sms_procesa_variables( $mensaje_recibido, $pedido, $apg_sms_settings[ 'variables' ] ); //Mensaje para el cliente
}

//Temporizador para pedidos recibidos
if ( isset( $apg_sms_settings[ 'temporizador' ] ) && $apg_sms_settings[ 'temporizador' ] > 0 ) {
wp_schedule_single_event( time() + ( absint( $apg_sms_settings[ 'temporizador' ] ) * 60 * 60 ), 'apg_sms_ejecuta_el_temporizador' );
Expand Down Expand Up @@ -286,8 +292,6 @@ function apg_sms_procesa_estados( $pedido, $notificacion = false ) {
}
}
add_action( 'woocommerce_order_status_on-hold', 'apg_sms_procesa_estados', 10 ); //Funciona cuando el pedido es marcado como recibido
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', 'apg_sms_procesa_estados', 10 );
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', 'apg_sms_procesa_estados', 10 );
add_action( 'woocommerce_order_status_pending', 'apg_sms_procesa_estados', 10 ); //Funciona cuando el pedido es marcado como pendiente
add_action( 'woocommerce_order_status_failed', 'apg_sms_procesa_estados', 10 ); //Funciona cuando el pedido es marcado como fallido
add_action( 'woocommerce_order_status_processing', 'apg_sms_procesa_estados', 10 ); //Funciona cuando el pedido es marcado como procesando
Expand All @@ -300,6 +304,28 @@ function apg_sms_notificacion( $pedido ) {
}
add_action( 'woocommerce_order_status_pending_to_processing_notification', 'apg_sms_notificacion', 10 ); //Funciona cuando el pedido es marcado directamente como procesando

//Retraso
function apg_sms_retardo( $numero_de_pedido ) {
global $apg_sms_settings;

if ( $pedido = wc_get_order( intval( $numero_de_pedido ) ) ) {
$retraso_enviado = get_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', true );
$estado = is_callable( [ $pedido, 'get_status' ] ) ? $pedido->get_status() : $pedido->status;
if ( intval( $retraso_enviado ) == -1 ) { //Solo enviamos si no ha cambiado de estado
update_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', 1 );
if ( $estado == 'on-hold' ) {
apg_sms_procesa_estados( $numero_de_pedido, false );
$retraso_enviado = get_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', true );
if ( intval( $retraso_enviado ) == -1 ) {
update_post_meta( $numero_de_pedido, 'apg_sms_retardo_enviado', 1 );
apg_sms_procesa_estados( $numero_de_pedido, false );
}
}
}
}
}
add_action( 'apg_sms_ejecuta_el_retraso', 'apg_sms_retardo' );

//Temporizador
function apg_sms_temporizador() {
global $apg_sms_settings;
Expand Down
44 changes: 27 additions & 17 deletions includes/admin/funciones-formulario.php
Expand Up @@ -6,24 +6,29 @@

//WPML
if ( $apg_sms_settings ) {
$mensajes = [
'mensaje_pedido',
'mensaje_fallido',
'mensaje_recibido',
'mensaje_procesando',
'mensaje_completado',
'mensaje_devuelto',
'mensaje_cancelado',
'mensaje_nota'
];

if ( function_exists( 'icl_register_string' ) || !$wpml_activo ) { //Versión anterior a la 3.2
$mensaje_pedido = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_pedido', $apg_sms_settings[ 'mensaje_pedido' ] ) : $apg_sms_settings[ 'mensaje_pedido' ];
$mensaje_fallido = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_fallido', $apg_sms_settings[ 'mensaje_fallido' ] ) : $apg_sms_settings[ 'mensaje_fallido' ];
$mensaje_recibido = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_recibido', $apg_sms_settings[ 'mensaje_recibido' ] ) : $apg_sms_settings[ 'mensaje_recibido' ];
$mensaje_procesando = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_procesando', $apg_sms_settings[ 'mensaje_procesando' ] ) : $apg_sms_settings[ 'mensaje_procesando' ];
$mensaje_completado = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_completado', $apg_sms_settings[ 'mensaje_completado' ] ) : $apg_sms_settings[ 'mensaje_completado' ];
$mensaje_devuelto = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_devuelto', $apg_sms_settings[ 'mensaje_devuelto' ] ) : $apg_sms_settings[ 'mensaje_devuelto' ];
$mensaje_cancelado = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_cancelado', $apg_sms_settings[ 'mensaje_cancelado' ] ) : $apg_sms_settings[ 'mensaje_cancelado' ];
$mensaje_nota = ( $wpml_activo ) ? icl_translate( 'apg_sms', 'mensaje_nota', $apg_sms_settings[ 'mensaje_nota' ] ) : $apg_sms_settings[ 'mensaje_nota' ];
foreach( $mensajes as $mensaje ) {
if ( isset( $apg_sms_settings[ $mensaje ] ) ) {
$$mensaje = ( $wpml_activo ) ? icl_translate( 'apg_sms', $mensaje, $apg_sms_settings[ $mensaje ] ) : $apg_sms_settings[ $mensaje ];
}
}
} else if ( $wpml_activo ) { //Versión 3.2 o superior
$mensaje_pedido = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_pedido' ], 'apg_sms', 'mensaje_pedido' );
$mensaje_fallido = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_fallido' ], 'apg_sms', 'mensaje_fallido' );
$mensaje_recibido = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_recibido' ], 'apg_sms', 'mensaje_recibido' );
$mensaje_procesando = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_procesando' ], 'apg_sms', 'mensaje_procesando' );
$mensaje_completado = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_completado' ], 'apg_sms', 'mensaje_completado' );
$mensaje_devuelto = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_devuelto' ], 'apg_sms', 'mensaje_devuelto' );
$mensaje_cancelado = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_cancelado' ], 'apg_sms', 'mensaje_cancelado' );
$mensaje_nota = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ 'mensaje_nota' ], 'apg_sms', 'mensaje_nota' );
foreach( $mensajes as $mensaje ) {
if ( isset( $apg_sms_settings[ $mensaje ] ) ) {
$$mensaje = apply_filters( 'wpml_translate_single_string', $apg_sms_settings[ $mensaje ], 'apg_sms', $mensaje );
}
}
}
}

Expand Down Expand Up @@ -71,7 +76,8 @@
"usuario_bulkgate" => __( 'application ID', 'woocommerce-apg-sms-notifications' ),
"clave_bulkgate" => __( 'authentication Token', 'woocommerce-apg-sms-notifications' ),
"identificador_bulkgate" => __( 'sender ID', 'woocommerce-apg-sms-notifications' ),
],
"unicode_bulkgate" => __( 'unicode', 'woocommerce-apg-sms-notifications' ),
],
"bulksms" => [
"usuario_bulksms" => __( 'username', 'woocommerce-apg-sms-notifications' ),
"contrasena_bulksms" => __( 'password', 'woocommerce-apg-sms-notifications' ),
Expand Down Expand Up @@ -234,6 +240,10 @@
"api-asia-01.twizo.com" => __( 'Singapore', 'woocommerce-apg-sms-notifications' ),
"api-eu-01.twizo.com" => __( 'Germany', 'woocommerce-apg-sms-notifications' ),
],
"unicode_bulkgate" => [
1 => __( 'Yes', 'woocommerce-apg-sms-notifications' ),
0 => __( 'No', 'woocommerce-apg-sms-notifications' ),
],
];

//Listado de estados de pedidos
Expand Down
32 changes: 16 additions & 16 deletions includes/admin/funciones.php
Expand Up @@ -28,7 +28,7 @@ function apg_sms_prefijo( $servicio ) {
"voipbuster",
"voipbusterpro",
"voipstunt",
];
];

return in_array( $servicio, $prefijo );
}
Expand Down Expand Up @@ -126,7 +126,7 @@ function apg_sms_normaliza_mensaje( $mensaje ) {
"¡" => "",
"?" => ".",
"¿" => ""
];
];

$mensaje = str_replace( array_keys( $reemplazo ), array_values( $reemplazo ), $mensaje );

Expand Down Expand Up @@ -165,16 +165,16 @@ function apg_sms_procesa_el_telefono( $pedido, $telefono, $servicio, $propietari
$prefijo_internacional = apg_sms_dame_prefijo_pais( WC()->countries->get_base_country() );
}

preg_match( "/(\d{1,4})[0-9.\- ]+/", $telefono_procesado, $prefijo_telefonico );
preg_match( "/(\d{1,4})[0-9.\-]+/", $telefono_procesado, $prefijo_telefonico );
if ( empty( $prefijo_telefonico ) ) { //Control
return;
}
if ( isset( $prefijo_internacional ) ) {
if ( strpos( strval( $prefijo_telefonico[1] ) , strval( $prefijo_internacional ) ) === false ) {
if ( strpos( strval( $prefijo_telefonico[ 1 ] ) , strval( $prefijo_internacional ) ) === false ) {
$telefono_procesado = $prefijo_internacional . ltrim( $telefono_procesado, '0' );
}
}
if ( ( $servicio == "moreify" || $servicio == "twilio" ) && strpos( $prefijo[1], "+" ) === false ) {
if ( ( $servicio == "moreify" || $servicio == "twilio" ) && strpos( $prefijo[ 1 ], "+" ) === false ) {
$telefono_procesado = "+" . $telefono_procesado;
} else if ( $servicio == "isms" && isset( $prefijo_internacional ) ) {
$telefono_procesado = "00" . preg_replace( '/\+/', '', $telefono_procesado );
Expand Down Expand Up @@ -205,7 +205,7 @@ function apg_sms_procesa_variables( $mensaje, $pedido, $variables, $nota = '' )
"note",
"order_product",
"shipping_method",
];
];
$apg_sms_variables = [ //Hay que añadirles un guión
"order_key",
"billing_first_name",
Expand Down Expand Up @@ -237,18 +237,18 @@ function apg_sms_procesa_variables( $mensaje, $pedido, $variables, $nota = '' )
"order_shipping",
"order_shipping_tax",
"order_total"
];
];
$variables_personalizadas = explode( "\n", str_replace( [
"\r\n",
"\r"
], "\n", $variables ) );
], "\n", $variables ) );

$numero_de_pedido = is_callable( [ $pedido, 'get_id' ] ) ? $pedido->get_id() : $pedido->id;
$variables_de_pedido = get_post_custom( $numero_de_pedido ); //WooCommerce 2.1

preg_match_all( "/%(.*?)%/", $mensaje, $busqueda );

foreach ( $busqueda[1] as $variable ) {
foreach ( $busqueda[ 1 ] as $variable ) {
$variable = strtolower( $variable );

if ( !in_array( $variable, $apg_sms ) && !in_array( $variable, $apg_sms_variables ) && !in_array( $variable, $variables_personalizadas ) ) {
Expand All @@ -264,15 +264,15 @@ function apg_sms_procesa_variables( $mensaje, $pedido, $variables, $nota = '' )
"order_product",
"order_discount",
"shipping_method_title",
];
];

if ( !in_array( $variable, $especiales ) ) {
if ( in_array( $variable, $apg_sms ) ) {
$mensaje = str_replace( "%" . $variable . "%", is_callable( [ $pedido, 'get_' . $variable ] ) ? $pedido->{'get_' . $variable}() : $pedido->$variable, $mensaje ); //Variables estándar - Objeto
} else if ( in_array( $variable, $apg_sms_variables ) ) {
$mensaje = str_replace( "%" . $variable . "%", $variables_de_pedido["_" . $variable][0], $mensaje ); //Variables estándar - Array
} else if ( isset( $variables_de_pedido[$variable] ) || in_array( $variable, $variables_personalizadas ) ) {
$mensaje = str_replace( "%" . $variable . "%", $variables_de_pedido[$variable][0], $mensaje ); //Variables de pedido y personalizadas
$mensaje = str_replace( "%" . $variable . "%", $variables_de_pedido[ "_" . $variable ][ 0 ], $mensaje ); //Variables estándar - Array
} else if ( isset( $variables_de_pedido[ $variable ] ) || in_array( $variable, $variables_personalizadas ) ) {
$mensaje = str_replace( "%" . $variable . "%", $variables_de_pedido[ $variable ][ 0 ], $mensaje ); //Variables de pedido y personalizadas
}
} else if ( $variable == "order_date" || $variable == "modified_date" ) {
$mensaje = str_replace( "%" . $variable . "%", date_i18n( woocommerce_date_format(), strtotime( $pedido->$variable ) ), $mensaje );
Expand All @@ -290,7 +290,7 @@ function apg_sms_procesa_variables( $mensaje, $pedido, $variables, $nota = '' )
$nombre = '';
$productos = $pedido->get_items();
if ( !isset( $apg_sms_settings[ 'productos' ] ) || $apg_sms_settings[ 'productos' ] != 1 ) {
$nombre = $productos[key( $productos )][ 'name' ];
$nombre = $productos[ key( $productos ) ][ 'name' ];
if ( strlen( $nombre ) > 10 ) {
$nombre = substr( $nombre, 0, 10 ) . "...";
}
Expand Down Expand Up @@ -579,7 +579,7 @@ function apg_sms_dame_prefijo_pais( $pais = '' ) {
'ZA' => '27',
'ZM' => '260',
'ZW' => '263'
];
];

return ( $pais == '' ) ? $paises : ( isset( $paises[$pais] ) ? $paises[$pais] : '' );
return ( $pais == '' ) ? $paises : ( isset( $paises[ $pais ] ) ? $paises[ $pais ] : '' );
}
2 changes: 1 addition & 1 deletion includes/admin/proveedores.php
Expand Up @@ -19,7 +19,7 @@ function apg_sms_envia_sms( $apg_sms_settings, $telefono, $mensaje ) {
'application_token' => $apg_sms_settings[ 'clave_bulkgate' ],
'number' => $telefono,
'text' => apg_sms_codifica_el_mensaje( $mensaje ),
'unicode' => 1,
'unicode' => intval( $apg_sms_settings[ 'unicode_bulkgate' ] ),
'sender_id' => 'gText',
'sender_id_value' => $apg_sms_settings[ 'identificador_bulkgate' ],
], 'https://portal.bulkgate.com/api/1.0/simple/transactional' );
Expand Down
18 changes: 15 additions & 3 deletions includes/formulario.php
Expand Up @@ -150,11 +150,23 @@
$campo = !empty( $mensaje_recibido ) ? $mensaje_recibido : '';
apg_sms_campo_de_mensaje_personalizado( 'mensaje_recibido', $campo, $listado_de_mensajes );
?>
<tr valign="top" class="mensaje_recibido">
<tr valign="top" class="mensaje_recibido">
<th scope="row" class="titledesc">
<label for="apg_sms_settings[retardo]">
<?php _e( 'Order on-hold delay (minutes)', 'woocommerce-apg-sms-notifications' ); ?>:
<span class="woocommerce-help-tip" data-tip="<?php _e( 'Send this message after X minutes, if the order is still on-hold, instead of sending it immediately.', 'woocommerce-apg-sms-notifications' ); ?>"/>
</label>
</th>
<td class="forminp forminp-number"><input type="text" id="apg_sms_settings[retardo]" name="apg_sms_settings[retardo]" size="50" value="<?php echo ( isset( $apg_sms_settings[ 'retardo' ] ) ) ? $apg_sms_settings[ 'retardo' ] : ''; ?>" tabindex="<?php echo $tab++; ?>"/>
</td>
</tr>
<tr valign="top" class="mensaje_recibido">
<th scope="row" class="titledesc">
<label for="apg_sms_settings[temporizador]">
<?php _e( 'Order on-hold timer', 'woocommerce-apg-sms-notifications' ); ?>:
<span class="woocommerce-help-tip" data-tip="<?php _e( 'You can timer this message every X hours. Leave blank to disable.', 'woocommerce-apg-sms-notifications' ); ?>"/> </th>
<?php _e( 'Order on-hold timer (hours)', 'woocommerce-apg-sms-notifications' ); ?>:
<span class="woocommerce-help-tip" data-tip="<?php _e( 'You can timer this message every X hours. Leave blank to disable.', 'woocommerce-apg-sms-notifications' ); ?>"/>
</label>
</th>
<td class="forminp forminp-number"><input type="text" id="apg_sms_settings[temporizador]" name="apg_sms_settings[temporizador]" size="50" value="<?php echo ( isset( $apg_sms_settings[ 'temporizador' ] ) ) ? $apg_sms_settings[ 'temporizador' ] : ''; ?>" tabindex="<?php echo $tab++; ?>"/>
</td>
</tr>
Expand Down

0 comments on commit 9fe8cc8

Please sign in to comment.