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
/** | |
* Añade el campo NIF a la página de checkout de WooCommerce | |
*/ | |
add_action( 'woocommerce_after_order_notes', 'agrega_mi_campo_personalizado' ); | |
function agrega_mi_campo_personalizado( $checkout ) { | |
echo '<div id="additional_checkout_field"><h2>' . __('Información adicional') . '</h2>'; | |
woocommerce_form_field( 'nif', array( |
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
/** | |
* Actualiza la información del pedido con el nuevo campo | |
*/ | |
add_action( 'woocommerce_checkout_update_order_meta', 'actualizar_info_pedido_con_nuevo_campo' ); | |
function actualizar_info_pedido_con_nuevo_campo( $order_id ) { | |
if ( ! empty( $_POST['nif'] ) ) { | |
update_post_meta( $order_id, 'NIF', sanitize_text_field( $_POST['nif'] ) ); | |
} | |
} |
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
/** | |
* Muestra el valor del nuevo campo NIF en la página de edición del pedido | |
*/ | |
add_action( 'woocommerce_admin_order_data_after_billing_address', 'mostrar_campo_personalizado_en_admin_pedido', 10, 1 ); | |
function mostrar_campo_personalizado_en_admin_pedido($order){ | |
echo '<p><strong>'.__('NIF').':</strong> ' . get_post_meta( $order->id, 'NIF', true ) . '</p>'; | |
} |
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
/** | |
* Incluye el campo NIF en el email de notificación del cliente | |
*/ | |
add_filter('woocommerce_email_order_meta_keys', 'muestra_campo_personalizado_email'); | |
function muestra_campo_personalizado_email( $keys ) { | |
$keys[] = 'nif'; | |
return $keys; | |
} |
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
//* Oculta resto de métodos de envío cuando envío gratuito está disponible | |
add_filter( 'woocommerce_package_rates', 'mostrar_solo_envio_gratis', 10, 2 ); | |
function mostrar_solo_envio_gratis( $rates, $package ) { | |
global $woocommerce; | |
if ( isset( $rates[ 'free_shipping' ] ) ) { | |
// Sólo muestra la opción de envío gratuito | |
$free_shipping = $rates[ 'free_shipping' ]; | |
$rates = array(); |
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
/* Only one single product may be in the cart */ | |
add_action( 'wafs_match_condition_single_product', 'wafs_match_condition_single_product', 10, 3 ); | |
/* Match single category | |
* | |
* @param bool $match | |
* @param string $operator | |
* @param mixed $value | |
* @return bool |
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
//Arreglamos la dirección predeterminada | |
function agrega_campo_nif_formularios( $fields ) { | |
$fields['nif'] = array( | |
'label' => __('<abbr lang="es" title="Número de Identificación Fiscal">NIF</abbr>', 'woocommerce'), | |
'placeholder' => _x('Ej: 99999999E', 'placeholder', 'woocommerce'), | |
'required' => false, | |
'class' => array('form-row-first'), | |
); |
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
//* Habilita cupón sólo usuarios registrados | |
/* Añade checkbox para habilitar opción */ | |
add_action( 'woocommerce_coupon_options_usage_restriction', 'add_custom_field_meta_box_coupon' ); | |
function add_custom_field_meta_box_coupon(){ | |
echo '<div class="option_group">'; | |
woocommerce_wp_checkbox( array( 'id' => 'register_users_use', 'label' => __( 'Solo usuarios registrados', 'woocommerce' ), 'description' => __( 'Marca esta opción si quieres permitir el uso de este cupón solo a usuarios registrados.', 'woocommerce' ) ) ); | |
echo '</div>'; | |
} |
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
//* Crea rol empleado de tienda | |
add_action( 'init', 'add_shop_staff_rol' ); | |
function add_shop_staff_rol(){ | |
$shop_role = get_role( 'shop_manager' ); | |
add_role( 'shop_staff', __( 'Empleado de tienda', 'woocommerce' ), $shop_role->capabilities ); | |
} | |
//* Oculta algunas secciones del panel de ajustes de WooCommerce al rol de usuario 'shop_staff' | |
function hide_wc_menu_items() { |
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
//* Add spent column to the WordPress Users Table | |
add_filter( 'manage_users_columns', 'add_customer_spent_column' ); | |
function add_customer_spent_column($columns) { | |
$columns[ 'customer_spent' ] = __( 'Money Spent', 'woocommerce' ); | |
return $columns; | |
} | |
add_action( 'manage_users_custom_column', 'show_customer_spent_column_content', 10, 3 ); | |
function show_customer_spent_column_content( $value, $column_name, $user_id ) { |
OlderNewer