Hola! debido al alto tráfico de este plugin, te mostraremos como tomar ventaja de sus funcionalidades a través de los filtros que el plugin provee.
1. Cambia el valor por defecto.
En la página de checkout el plugin muestra un mensaje «Elige zona1/zona2» y cuando no hay zonas para mostrar, el mensaje es «No hay zona1/zona2»
Estos son los valores por defecto, pero puedes cambiarlo usando el filtro «woocommerce_shipping_gowoo_shiplace_{instance_id}_settings«, aquí un ejemplo:
add_filter('woocommerce_shipping_gowoo_shiplace_29_settings','gowooship_customize_label',10,1);
function gowooship_customize_label($array_settings) {
$array_settings['places_info']['label_textdefault'] = 'No hay zonas';
$array_settings['places_info']['label_choise'] = 'Elige tu zona';
<?php
add_filter('woocommerce_shipping_gowoo_shiplace_29_settings','gowooship_customize_label',10,1);
function gowooship_customize_label($array_settings) {
$array_settings['places_info']['label_textdefault'] = 'No hay zonas';
$array_settings['places_info']['label_choise'] = 'Elige tu zona';
return $array_settings;
}
?>
<?php
add_filter('woocommerce_shipping_gowoo_shiplace_29_settings','gowooship_customize_label',10,1);
function gowooship_customize_label($array_settings) {
$array_settings['places_info']['label_textdefault'] = 'No hay zonas';
$array_settings['places_info']['label_choise'] = 'Elige tu zona';
return $array_settings;
}
?>
2. Agregar atributo al campo zona del plugin
Si deseas cambiar algunos atributos del campo zona del plugin, puedes usar el hook «gowoo_checkout_fields«. Por ejemplo, si queremos agregar una clase llamado «custom-class»
add_filter('gowoo_checkout_fields','gowooship_add_class',10,1);
function gowooship_add_class($array_fields) {
$array_fields['billing']['billing_gowoo_place']['class'][] = 'custom-class';
<?php
add_filter('gowoo_checkout_fields','gowooship_add_class',10,1);
function gowooship_add_class($array_fields) {
$array_fields['billing']['billing_gowoo_place']['class'][] = 'custom-class';
return $array_fields;
}
?>
<?php
add_filter('gowoo_checkout_fields','gowooship_add_class',10,1);
function gowooship_add_class($array_fields) {
$array_fields['billing']['billing_gowoo_place']['class'][] = 'custom-class';
return $array_fields;
}
?>
3. Quitar método de envío.
Si necesitas quitar este método de pago debido a algunas reglas de negocio, necesitas usar el filtro «woocommerce_shipping_gowoo_shiplace_{instance_id}_is_available«. Por ejemplo, si el costo total del pedido es mayor que 1000, entonces quitarlo.
add_filter('woocommerce_shipping_gowoo_shiplace_29_is_available','gowooship_is_available',10,1);
function gowooship_is_available($package) {
if( $package['contents_cost'] > 1000 )
<?php
add_filter('woocommerce_shipping_gowoo_shiplace_29_is_available','gowooship_is_available',10,1);
function gowooship_is_available($package) {
if( $package['contents_cost'] > 1000 )
return false;
return true;
}
?>
<?php
add_filter('woocommerce_shipping_gowoo_shiplace_29_is_available','gowooship_is_available',10,1);
function gowooship_is_available($package) {
if( $package['contents_cost'] > 1000 )
return false;
return true;
}
?>
4. Quitar algún método de pago cuando eliges una zona de este método de envío
Algunas veces necesitamos quitar algún método de pago cuando realizamos una acción, en este caso cuando elegimos una zona usando este plugin. Woocommerce tiene un filtro que puede ayudarnos, es llamado «woocommerce_available_payment_gateways«.
Por ejemplo si queremos quitar «Contraentrega» cuando elegimos alguna zona, debemos conocer la instance_id, el ID de la zona y el código del método de pago en este caso el código es COD.
add_filter('woocommerce_available_payment_gateways','gowooship_addremove_payments',10,1);
function gowooship_addremove_payments($array_payments) {
//This is the current method shipping
$current_payment = WC()->session->get('chosen_shipping_methods');
$data_payment = explode(':',$current_payment[0]);
//This fields you can modfify.
$payment_to_remove = 'cod';
/**********************************************
WE SEARCH THE ZONE2 CHOISE FOR THE USER
***********************************************/
//$_POST['post_data'] Contain all values of checkout form
//field1=val1&field2=val2&field3&val3&field4=val4
if( isset($_POST['post_data']) && $data_payment[0] == 'gowoo_shiplace' && $data_payment[1] == $instance_id ) {
//Split by & and save it in a array
$array_form = explode('&',$_POST['post_data']);
if(is_array($array_form)) {
//Split by = and save it in other array
foreach($array_form as $array_fields) {
$array_values = explode('=',$array_fields);
if( $array_values[0] == 'billing_gowoo_place' && !empty($array_values[1]) ) {
$data_select = $array_values[1];
/**********************************************
***********************************************/
//$data_select in the key of the level2_id
if( isset($data_select) && $data_select == $level2_id ) {
unset($array_payments[$payment_to_remove]);
add_filter('woocommerce_available_payment_gateways','gowooship_addremove_payments',10,1);
function gowooship_addremove_payments($array_payments) {
//This is the current method shipping
$current_payment = WC()->session->get('chosen_shipping_methods');
$data_payment = explode(':',$current_payment[0]);
//This fields you can modfify.
$level2_id = 2;
$instance_id = 29;
$payment_to_remove = 'cod';
/**********************************************
STEP1
WE SEARCH THE ZONE2 CHOISE FOR THE USER
***********************************************/
//$_POST['post_data'] Contain all values of checkout form
//field1=val1&field2=val2&field3&val3&field4=val4
if( isset($_POST['post_data']) && $data_payment[0] == 'gowoo_shiplace' && $data_payment[1] == $instance_id ) {
//Split by & and save it in a array
$array_form = explode('&',$_POST['post_data']);
if(is_array($array_form)) {
//Split by = and save it in other array
foreach($array_form as $array_fields) {
$array_values = explode('=',$array_fields);
if( $array_values[0] == 'billing_gowoo_place' && !empty($array_values[1]) ) {
$data_select = $array_values[1];
break;
}
}
}
/**********************************************
STEP2:
REMOVE THE PAYMENT
***********************************************/
//$data_select in the key of the level2_id
if( isset($data_select) && $data_select == $level2_id ) {
unset($array_payments[$payment_to_remove]);
}
}
return $array_payments;
}
add_filter('woocommerce_available_payment_gateways','gowooship_addremove_payments',10,1);
function gowooship_addremove_payments($array_payments) {
//This is the current method shipping
$current_payment = WC()->session->get('chosen_shipping_methods');
$data_payment = explode(':',$current_payment[0]);
//This fields you can modfify.
$level2_id = 2;
$instance_id = 29;
$payment_to_remove = 'cod';
/**********************************************
STEP1
WE SEARCH THE ZONE2 CHOISE FOR THE USER
***********************************************/
//$_POST['post_data'] Contain all values of checkout form
//field1=val1&field2=val2&field3&val3&field4=val4
if( isset($_POST['post_data']) && $data_payment[0] == 'gowoo_shiplace' && $data_payment[1] == $instance_id ) {
//Split by & and save it in a array
$array_form = explode('&',$_POST['post_data']);
if(is_array($array_form)) {
//Split by = and save it in other array
foreach($array_form as $array_fields) {
$array_values = explode('=',$array_fields);
if( $array_values[0] == 'billing_gowoo_place' && !empty($array_values[1]) ) {
$data_select = $array_values[1];
break;
}
}
}
/**********************************************
STEP2:
REMOVE THE PAYMENT
***********************************************/
//$data_select in the key of the level2_id
if( isset($data_select) && $data_select == $level2_id ) {
unset($array_payments[$payment_to_remove]);
}
}
return $array_payments;
}
Si quieres adquirir este plugin, puedes seguir estos enlaces:
Descargar Plugin
Demo
Hola, cómo puedo mostrar Provincia y Distrito en campos separados. Utilizo WooCommerce Checkout Field Editor de ThemeHigh.
Hola Samir.
Creo que en 2 campos separados vas a tener que desarrollarlo porque no veo algún plugin que haga eso en este momento.