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; } //Añadir Important information despues del boton de pago add_action( 'woocommerce_review_order_before_submit', 'add_after_checkout_button' ); function add_after_checkout_button() { echo '
Click here to see shipping information
'; } //disable search bar for reviews function my_cr_ajaxreviews_show_search( $show_search ) { return false; } add_filter( 'cr_ajaxreviews_show_search', 'my_cr_ajaxreviews_show_search', 10, 1 ); //change position price single product remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 ); //Add Breadcrumbs //codigo en el header del tema padre /** */ function migas_de_pan() { if (!is_front_page()) { ?>
Home
/ 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 '
' . $category->name . '
/ '; } 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[] = '
' . $term->name . '
/ '; } echo implode('', $categories); } ?>
"; } } // 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() { ?> 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' ); /*traducciones manuales*/ // function custom_text_replace( $translated_text, $untranslated_text, $domain ) { // if ( function_exists( 'weglot_get_current_language' ) ) { // $currentLang = weglot_get_current_language(); // if ( $currentLang == "fr" ) { // switch ( $untranslated_text ) { // case 'Clear': // $translated_text = __( 'Clair', $domain ); // break; // case 'Add to cart': // $translated_text = __( 'Ajouter au panier', $domain ); // break; // default: // $translated_text = $untranslated_text; // break; // } // } else { // $translated_text = $untranslated_text; // } // } // return $translated_text; // } // add_filter( 'gettext', 'custom_text_replace', 20, 3 ); // function mm_add_hreflang_attribute() { // $currentLang = function_exists( 'weglot_get_current_language' ) ? weglot_get_current_language() : ''; // $current_url = get_permalink(); // $path = parse_url( $current_url, PHP_URL_PATH ); // $path = preg_replace( '/\/(fr|es)\//', '/', $path ); // if ( $currentLang == "fr" ) { // echo ' // // // // // // // // '; // } else { // echo ' // // // // // // // // '; // } // } // add_action( 'wp_head', 'mm_add_hreflang_attribute', 1 ); // function prefix_weglot_render_dom( $dom ) { // if ( function_exists( 'weglot_get_current_language' ) ) { // $currentLang = weglot_get_current_language(); // if ( $currentLang == "fr" ) { // $new_lang = 'fr-CA'; // $dom = str_replace( 'lang="fr"', 'lang="' . $new_lang . '"', $dom ); // } else { // $lang = get_bloginfo( 'language' ); // $new_lang = 'en-CA'; // $dom = str_replace( 'lang="' . $lang . '"', 'lang="' . $new_lang . '"', $dom ); // } // } // return $dom; // } // add_filter( 'weglot_render_dom', 'prefix_weglot_render_dom' ); // Eliminar el atributo nofollow de los enlaces de productos add_filter( 'woocommerce_loop_add_to_cart_args', 'add_to_cart_args_remove_nofollow' ); function add_to_cart_args_remove_nofollow( $args ) { unset($args['attributes']['rel']); return $args; } /*Sesion actual para pasar email a Update Info*/ add_action('wp_ajax_get_current_user_info', 'get_current_user_info'); add_action('wp_ajax_nopriv_get_current_user_info', 'get_current_user_info'); function get_current_user_info() { $current_user = wp_get_current_user(); echo json_encode(array('user_email' => $current_user->user_email)); wp_die(); } /*Establece la cantidad de productos por página*/ add_filter('loop_shop_per_page', 'custom_products_per_page', 20); function custom_products_per_page($products) { $products = 18; return $products; } /** 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; } //Cambiar mensaje cuando no se selecciona una talla function custom_woocommerce_alert_text( $translated_text, $text, $domain ) { if ( function_exists( 'weglot_get_current_language' ) ) { $currentLang = weglot_get_current_language(); if ( $text === 'Please select some product options before adding this product to your cart.' ) { if ( $currentLang == "fr" ) { $translated_text = "Veuillez sélectionner une taille avant d'ajouter ce produit à votre panier."; } else { $translated_text = 'Please select a size before adding this to your cart.'; } } } return $translated_text; } add_filter( 'gettext', 'custom_woocommerce_alert_text', 20, 3 ); // 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 ); } // 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') ]; } } 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.'); } } /* traducción de descripciones largas y cortas a francés */ add_action('woocommerce_before_single_product', 'custom_handle_short_description_by_language', 1); function custom_handle_short_description_by_language() { if (!is_product()) { return; } global $post; // Detectar idioma desde GTranslate Premium $current_lang = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : ''; $is_french = ($current_lang === 'fr'); if ($is_french) { $short_description_fr = get_post_meta($post->ID, 'short_description_fr', true); if (!empty($short_description_fr)) { // Eliminar la descripción corta por defecto remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20); // Agregar nuestra descripción corta personalizada add_action('woocommerce_single_product_summary', function() use ($short_description_fr) { echo '
'; echo wp_kses_post($short_description_fr); echo '
'; }, 20); } // Si el campo está vacío, no hacemos nada: WooCommerce mostrará la descripción por defecto } } add_filter('the_content', 'custom_product_description_content_by_language'); function custom_product_description_content_by_language($content) { if (!is_product()) { return $content; } global $post; // Detectar idioma desde GTranslate Premium $current_lang = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : ''; $is_french = ($current_lang === 'fr'); if ($is_french) { $description_fr = get_post_meta($post->ID, 'description_fr', true); if (!empty($description_fr)) { return wp_kses_post($description_fr); } } return $content; // contenido por defecto si no es francés o está vacío } /* 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; }