Depending on your bank´s policies your order may be charged in USD. Should they choose to charge in USD the amount charged will be the equivalent to your order total in your local currency.
';
}
add_filter( 'woocommerce_cart_no_shipping_available_html', 'nszm_no_shipping_available_html' );
add_filter( 'woocommerce_no_shipping_available_html', 'nszm_no_shipping_available_html' );
function nszm_no_shipping_available_html( $message ) {
$country = WC()->customer->get_shipping_country();
if ( !empty( $country ) ) {
$all_countries = WC()->countries->get_countries();
return sprintf( "We don't ship to %s in this store, please change the actual store in the footer section.", $all_countries[ $country ] );
}
return "Change store.";
}
// Genera shortcode free-shipping [rey_shipping_bar]
add_shortcode( 'rey_shipping_bar', function(){
if( function_exists('reycore__get_module') && ($fb = reycore__get_module('mini-cart-shipping-bar')) ){
$fb->enqueue_scripts();
$fb->shipping_bar();
}
});
// Rename status completed to Shipped
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
if ( 'wc-completed' === $key )
$order_statuses['wc-completed'] = _x( 'Shipped', 'Order status', 'woocommerce' );
}
return $order_statuses;
}
//DHL Functions
add_filter( 'hitdhl_custom_fields', 'hitdhl_custom_fields', 10, 2 );
if ( ! function_exists( 'hitdhl_custom_fields' ) ) {
function hitdhl_custom_fields($value, $account) {
// General Notes
echo '
/
term_id, 'product_cat');
if (!empty($ancestors)) {
foreach (array_reverse($ancestors) as $ancestor) {
$ancestor_term = get_term($ancestor, 'product_cat');
echo '
' . $ancestor_term->name . '
/ ';
}
}
$category = get_queried_object();
echo '
/ ';
} elseif (is_single()) {
global $product;
$terms = get_the_terms($product->ID, 'product_cat');
if ($terms && !is_wp_error($terms)) {
$categories_with_timestamps = array();
foreach ($terms as $term) {
if ($term->slug !== 'printed-collections' && $term->slug !== 'super-bowl' && $term->slug !== 'access-trunks' && $term->slug !== 'crew-striped' && $term->slug !== 'sporty-designs' && $term->slug !== 'pride-collection' && $term->slug !== 'revealing-cuts' && $term->slug !== 'shorts') {
$categories_with_timestamps[$term->term_id] = $term->term_id;
}
}
asort($categories_with_timestamps);
$categories = array();
foreach ($categories_with_timestamps as $term_id) {
$term = get_term($term_id, 'product_cat');
$categories[] = '
/ ';
}
echo implode('', $categories);
}
?>
";
}
}
/**
* Add or modify States
*/
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['CN'] = array(
'CN1' => 'Yunnan',
'CN2' => 'Beijing',
'CN3' => 'Tianjin',
'CN4' => 'Hebei',
'CN5' => 'Shanxi',
'CN6' => 'Inner Mongolia',
'CN7' => 'Liaoning',
'CN8' => 'Jilin',
'CN9' => 'Heilongjiang',
'CN10' => 'Shanghai',
'CN11' => 'Jiangsu',
'CN12' => 'Zhejiang',
'CN13' => 'Anhui',
'CN14' => 'Fujian',
'CN15' => 'Jiangxi',
'CN16' => 'Shandong',
'CN17' => 'Henan',
'CN18' => 'Hubei',
'CN19' => 'Hunan',
'CN20' => 'Guangdong',
'CN21' => 'Guangxi Zhuang',
'CN22' => 'Hainan',
'CN23' => 'Chongqing',
'CN24' => 'Sichuan',
'CN25' => 'Guizhou',
'CN26' => 'Shaanxi',
'CN27' => 'Gansu',
'CN28' => 'Qinghai',
'CN29' => 'Ningxia Hui',
'CN30' => 'Macao',
'CN31' => 'Tibet',
'CN32' => 'Xinjiang'
);
return $states;
}
// add custom fields register form woo
///////////////////////////////
// 1. ADD FIELDS
add_action( 'woocommerce_register_form_start', 'bbloomer_add_name_woo_account_registration' );
function bbloomer_add_name_woo_account_registration() {
?>
*
*
*
'country',
'class' => array('chzn-drop'),
'label' => __('Country'),
'placeholder' => __('Choose your country.'),
'required' => true,
'clear' => true,
'default' => 'BE'
));
?>
add( 'billing_first_name_error', __( '
Error : First name is required!', 'woocommerce' ) );
}
if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
$errors->add( 'billing_last_name_error', __( '
Error : Last name is required!.', 'woocommerce' ) );
}
if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
$errors->add( 'billing_phone_error', __( '
Error : Phone is required!.', 'woocommerce' ) );
}
if ( isset( $_POST['billing_country'] ) && empty( $_POST['billing_country'] ) ) {
$errors->add( 'billing_country_error', __( '
Error : Country is required!.', 'woocommerce' ) );
}
return $errors;
}
///////////////////////////////
// 3. SAVE FIELDS
add_action( 'woocommerce_created_customer', 'bbloomer_save_name_fields' );
function bbloomer_save_name_fields( $customer_id ) {
if ( isset( $_POST['billing_first_name'] ) ) {
update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
update_user_meta( $customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']) );
}
if ( isset( $_POST['billing_last_name'] ) ) {
update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
update_user_meta( $customer_id, 'last_name', sanitize_text_field($_POST['billing_last_name']) );
}
if ( isset( $_POST['billing_phone'] ) ) {
update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
update_user_meta( $customer_id, 'phone', sanitize_text_field($_POST['billing_phone']) );
}
if ( isset( $_POST['billing_country'] ) ) {
update_user_meta( $customer_id, 'billing_country', sanitize_text_field( $_POST['billing_country'] ) );
update_user_meta( $customer_id, 'country', sanitize_text_field($_POST['billing_country']) );
}
}
/*Agregar mensaje en Checkout y Mini-cart*/
function agregar_mensaje_al_mini_cart() {
?>
customer->get_shipping_country();
if (in_array($selected_country, $country_high_risk)) {
WC()->cart->add_fee(__('High Risk Surcharge', 'txtdomain'), 35);
}
if (in_array($selected_country, $country_restricted_destination)) {
WC()->cart->add_fee(__('Restricted destination Surcharge', 'txtdomain'), 45.50);
}
// Validar si cliente España aplica a SOIVRE
$cart_total = WC()->cart->get_cart_contents_total();
$country_soivre = ['ES'];
if (in_array($selected_country, $country_soivre) && $cart_total >= 160){
WC()->cart->add_fee(__('SOIVRE', 'txtdomain'), 31.50);
}
});
// Aviso sobre impuestos
function mensaje_impuestos() {
$selected_country = WC()->customer->get_shipping_country();
?>
customer->get_shipping_country();
$cart_total = WC()->cart->get_total('raw');
?>
get_id() ) ) {
echo '
Every second pair of Classics 50% off ';
}
}
// Excluir la categoría "Classics" de todos los cupones
function exclude_classics_from_coupons( $excluded_categories ) {
// Comprobar si estamos en el área de administración y si el usuario actual es un administrador
if ( is_admin() && current_user_can( 'manage_woocommerce' ) ) {
// No excluir la categoría "Classics" para los administradores
return $excluded_categories;
}
// Obtener el ID de la categoría "Classics"
$classics_category_id = get_term_by( 'slug', 'classics', 'product_cat' )->term_id;
// Añadir el ID de la categoría "Classics" a la lista de categorías excluidas
$excluded_categories[] = $classics_category_id;
return $excluded_categories;
}
add_filter( 'woocommerce_coupon_get_excluded_product_categories', 'exclude_classics_from_coupons' );
//Fedex Functions
add_filter( 'shipi_fedex_custom_fields', 'shipi_fedex_custom_fields', 10, 2 );
if ( ! function_exists( 'shipi_fedex_custom_fields' ) ) {
function shipi_fedex_custom_fields($value, $account) {
// General Notes
echo '
General Notes: ';
}
}
add_filter( 'shipi_fedex_custom_values', 'shipi_fedex_custom_values', 10, 2 );
if ( ! function_exists( 'shipi_fedex_custom_values' ) ) {
function shipi_fedex_custom_values($return, $val_arr) {
// General Notes
$custom_order_number = get_post_meta(get_the_ID(), "_order_number", true);
$return['order_no'] = $custom_order_number;
if(isset($val_arr['shipi_fedex_custom_notes'. $val_arr['hitshippo_fedex_create_label']])){
$return['notes'] = $val_arr['shipi_fedex_custom_notes'. $val_arr['hitshippo_fedex_create_label']];
}
return $return;
}
}
// This code set the Product name to fedex from DHL configuration
add_filter( 'shipi_product_name_change', 'shipi_product_name_change', 10, 2 );
if ( ! function_exists( 'shipi_product_name_change' ) ) {
function shipi_product_name_change($name, $product_id) {
$custom_name = get_post_meta($product_id, "hit_dhl_prod_variation_desc", true);
if($custom_name){
return $custom_name;
}else{
$custom_name = get_post_meta($product_id, "hits_dhl_desc", true);
if($custom_name){
return $custom_name;
}else{
return $name;
}
return $name;
}
}
}
function mm_add_hreflang_attribute() {
$current_url = get_permalink();
$path = parse_url($current_url, PHP_URL_PATH);
$path = preg_replace('/\/(fr|es)\//', '/', $path);
echo '
';
}
add_action('wp_head', 'mm_add_hreflang_attribute', 1);
function my_custom_language_attributes( $output ) {
$lang = get_bloginfo('language');
$new_lang = 'en';
$output = str_replace('lang="' . $lang . '"', 'lang="' . $new_lang . '"', $output);
return $output;
}
add_filter( 'language_attributes', 'my_custom_language_attributes');
/*Agregar mensaje Cooldowns 2x1 en Mini-cart
function agregar_mensaje_al_mini_cart_cooldowns_2x1() {
?>
$current_user->user_email));
wp_die();
}
/*campo id en checkout para alemania, brasil y mexico*/
add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta', 10, 2);
function custom_checkout_field_update_order_meta($order_id, $data) {
$billing_country = isset($data['billing_country']) ? $data['billing_country'] : '';
$billing_id = isset($data['billing_id']) ? $data['billing_id'] : '';
$shipping_last_name = get_post_meta($order_id, '_shipping_last_name', true);
if ($billing_country === 'DE' && $billing_id !== '' && $billing_id !== 'N/A') {
$updated_last_name = $shipping_last_name . ' ID# ' . $billing_id;
update_post_meta($order_id, '_shipping_last_name', $updated_last_name);
}else if ($billing_country === 'BR' && $billing_id !== '' && $billing_id !== 'N/A') {
$updated_last_name = $shipping_last_name . ' CPF# ' . $billing_id;
update_post_meta($order_id, '_shipping_last_name', $updated_last_name);
}else if ($billing_country === 'MX' && $billing_id !== '' && $billing_id !== 'N/A') {
$updated_last_name = $shipping_last_name . ' RFC/CURP# ' . $billing_id;
update_post_meta($order_id, '_shipping_last_name', $updated_last_name);
}
}
/** Desactivar cupones*/
// add_filter('woocommerce_coupons_enabled', 'deshabilitar_cupones_front');
// function deshabilitar_cupones_front($enabled) {
// if (is_admin()) {
// return true;
// } else {
// return false;
// }
// }
/*agregar mensaje sobre los cupones*/
// add_action( 'woocommerce_before_checkout_form', 'wnd_checkout_code', 10 );
// function wnd_checkout_code( ) {
// echo '*Discount codes not applicable on Sale items*';
// }
/************ Condicionales Cover Category ************/
add_filter('reycore/elementor/hide_element/pump_show_title', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_title = get_field('show_title', 'product_cat_' . $category_id);
if ($show_title!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_second_title', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_title = get_field('show_title', 'product_cat_' . $category_id);
if ($show_title==1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_category = get_field('show_category', 'product_cat_' . $category_id);
if ($show_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_boxers_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_boxers_category = get_field('show_boxers_category', 'product_cat_' . $category_id);
if ($show_boxers_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_brief_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_brief_category = get_field('show_brief_category', 'product_cat_' . $category_id);
if ($show_brief_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_backless_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_backless_category = get_field('show_backless_category', 'product_cat_' . $category_id);
if ($show_backless_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_jockstrap_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_backless_category = get_field('show_jockstrap_category', 'product_cat_' . $category_id);
if ($show_backless_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
add_filter('reycore/elementor/hide_element/pump_show_thong_category', function( $status, $element ){
$category = get_queried_object();
if ($category && is_a($category, 'WP_Term') && $category->taxonomy === 'product_cat') {
$category_id = $category->term_id;
$show_backless_category = get_field('show_thong_category', 'product_cat_' . $category_id);
if ($show_backless_category!=1) {
return true; // Ocultar este elemento
}
}
return $status;
}, 10, 2);
/*Cambiar select size por add to cart para las socks*/
add_action('woocommerce_after_shop_loop_item_title', 'add_to_cart_socks', 10);
function add_to_cart_socks() {
global $product;
// Verificar si el producto tiene la categoría "classics"
if ( has_term( 'socks', 'product_cat', $product->get_id() ) ) {
add_filter('woocommerce_product_add_to_cart_text', 'change_add_to_cart_text', 10, 2);
}
}
function change_add_to_cart_text($text, $product) {
// Cambiar el texto solo si el producto es de la categoría "socks"
if ( has_term( 'socks', 'product_cat', $product->get_id() ) ) {
$text = __('Add to cart', 'woocommerce');
}
return $text;
}
// Ordenes Mexico en On Hold
add_action( 'woocommerce_thankyou', 'set_order_on_hold_for_mexico', 10, 1 );
function set_order_on_hold_for_mexico( $order_id ) {
$order = wc_get_order( $order_id );
// Verificar si el país de destino es México
$shipping_country = $order->get_shipping_country();
if ( $shipping_country === 'MX' ) {
// Cambiar el estado de la orden a "on hold"
$order->update_status( 'on-hold', 'Order placed from Mexico, status changed to on hold.' );
}
}
//Cambiar mensaje cuando no se selecciona una talla
add_filter('gettext', 'custom_woocommerce_alert_text', 20, 3);
function custom_woocommerce_alert_text($translated_text, $text, $domain) {
if ($text === 'Please select some product options before adding this product to your cart.') {
$translated_text = 'Please select a size before adding this to your cart.';
}
return $translated_text;
}
// YayCommerce sale tag personalizacion
add_action('template_redirect', function () {
ob_start('reemplazar_yaydp_sale_tag');
});
function reemplazar_yaydp_sale_tag($html) {
return preg_replace_callback(
'#
-' . esc_html($percent) . '% OFF
';
},
$html
);
}
// Gif Beach bags
add_filter('woocommerce_loop_add_to_cart_link', 'ocultar_boton_add_to_cart_catalogo_beach_bags', 10, 2);
function ocultar_boton_add_to_cart_catalogo_beach_bags($button, $product) {
$categoria_beach_bags = 'beach-bags';
$product_cats = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'slugs']);
if (in_array($categoria_beach_bags, $product_cats)) {
return '';
}
return $button;
}
add_action('woocommerce_single_product_summary', 'deshabilitar_boton_producto_individual_beach_bags', 1);
function deshabilitar_boton_producto_individual_beach_bags() {
global $product;
$product_cats = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'slugs']);
if (in_array('beach-bags', $product_cats)) {
// Elimina el formulario de añadir al carrito
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
}
}
// Añade el popup HTML y overlay en footer
add_action('wp_footer', function() {
if (!is_cart() && !is_checkout()) {
?>
admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('beach_bag_nonce'),
]);
}
});
// Función que cuenta swimwear y detecta beach bags en carrito
function check_swimwear_and_free_beach_bag() {
$categoria_swimwear = 'swimwear';
$categoria_beach_bags = 'beach-bags';
$swimwear_count = 0;
$beach_bag_cart_keys = [];
foreach (WC()->cart->get_cart() as $cart_item_key => $item) {
$product_id = $item['product_id'];
$quantity = $item['quantity'];
$cats = wp_get_post_terms($product_id, 'product_cat', ['fields' => 'slugs']);
if (in_array($categoria_swimwear, $cats)) {
$swimwear_count += $quantity;
}
if (in_array($categoria_beach_bags, $cats)) {
$beach_bag_cart_keys[] = $cart_item_key;
}
}
return ['swimwear_count' => $swimwear_count, 'has_beach_bag' => !empty($beach_bag_cart_keys), 'beach_bag_keys' => $beach_bag_cart_keys];
}
// Eliminar beach bag gratis si swimwear < 2 en cada cálculo de totales
add_action('woocommerce_before_calculate_totals', 'remove_beach_bag_if_swimwear_less_than_two', 10, 1);
function remove_beach_bag_if_swimwear_less_than_two($cart) {
if (is_admin() && !defined('DOING_AJAX')) return;
$check = check_swimwear_and_free_beach_bag();
if ($check['swimwear_count'] < 2 && $check['has_beach_bag']) {
foreach ($check['beach_bag_keys'] as $key) {
$cart->remove_cart_item($key);
}
if (!is_admin()) {
wc_add_notice('Your free Beach Bag has been removed because you no longer have enough swimwear items.', 'notice');
}
}
}
// AJAX: check swimwear count & if popup should show
add_action('wp_ajax_check_swimwear_count', 'ajax_check_swimwear_count');
add_action('wp_ajax_nopriv_check_swimwear_count', 'ajax_check_swimwear_count');
function ajax_check_swimwear_count() {
check_ajax_referer('beach_bag_nonce', 'nonce');
$check = check_swimwear_and_free_beach_bag();
wp_send_json(['show_popup' => ($check['swimwear_count'] >= 2 && !$check['has_beach_bag'])]);
}
// AJAX: get list of beach bags
add_action('wp_ajax_get_beach_bags', 'ajax_get_beach_bags');
add_action('wp_ajax_nopriv_get_beach_bags', 'ajax_get_beach_bags');
function ajax_get_beach_bags() {
check_ajax_referer('beach_bag_nonce', 'nonce');
$query = new WP_Query([
'post_type' => 'product',
'posts_per_page' => 20,
'tax_query' => [[
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'beach-bags',
]],
'meta_query' => [[
'key' => '_stock_status',
'value' => 'instock'
]]
]);
$products = [];
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$product_id = get_the_ID();
$products[] = [
'id' => $product_id,
'name' => get_the_title(),
'image' => get_the_post_thumbnail_url($product_id, 'full') // puede cambiar a 'medium' si preferís
];
}
}
wp_reset_postdata();
wp_send_json_success($products);
}
// AJAX: add selected beach bag for free
add_action('wp_ajax_add_free_beach_bag', 'ajax_add_free_beach_bag');
add_action('wp_ajax_nopriv_add_free_beach_bag', 'ajax_add_free_beach_bag');
function ajax_add_free_beach_bag() {
check_ajax_referer('beach_bag_nonce', 'nonce');
$product_id = intval($_POST['product_id']);
if (!$product_id) wp_send_json_error('Invalid product.');
$cats = wp_get_post_terms($product_id, 'product_cat', ['fields' => 'slugs']);
if (!in_array('beach-bags', $cats)) wp_send_json_error('Selected product is not in the Beach Bags category.');
$check = check_swimwear_and_free_beach_bag();
if ($check['has_beach_bag']) wp_send_json_error('You already have a Beach Bag in your cart.');
$added = WC()->cart->add_to_cart($product_id);
if ($added) {
// Apply price zero to the free beach bag
add_action('woocommerce_before_calculate_totals', function($cart) use ($product_id) {
foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
if ($cart_item['product_id'] == $product_id) {
$cart_item['data']->set_price(0);
}
}
});
wp_send_json_success();
} else {
wp_send_json_error('Failed to add product to cart.');
}
}
/* umbral mínimo out of stock para productos individuales*/
add_filter('woocommerce_product_is_in_stock', 'force_in_stock_for_specific_skus', 10, 2);
function force_in_stock_for_specific_skus($is_in_stock, $product) {
$custom_skus = array(
'11048-01', '11048-02', '11048-03', '11048-04',
'11078-01', '11078-02', '11078-03', '11078-04',
'14018-01', '14018-02', '14018-03', '14018-04',
'15038-01', '15038-02', '15038-03', '15038-04'
);
if ($product->is_type('variation') && in_array($product->get_sku(), $custom_skus)) {
$stock_quantity = $product->get_stock_quantity();
if ($stock_quantity !== null && $stock_quantity > 0) {
return true; // Forzar como disponible
}
}
return $is_in_stock;
}