get_type(); //Cogemos el valor de la variable de la bd y si no por defecto $texto_single = __('Add to cart', 'woocommerce'); $texto_externo = esc_attr (get_option ('add_to_cart_external', __('Buy product', 'woocommerce'))); $texto_agrupado = esc_attr (get_option ('add_to_cart_grouped', __('View products', 'woocommerce'))); $texto_simple = esc_attr (get_option ('add_to_cart_simple', __('Add to cart', 'woocommerce'))); $texto_variable = esc_attr (get_option ('add_to_cart_variable', __('Select options', 'woocommerce'))); $texto_bookable = esc_attr (get_option ('add_to_cart_bookable', __('Book now', 'woocommerce'))); $texto_externo_single = esc_attr (get_option ('add_to_cart_external_single', $texto_externo)); $texto_agrupado_single = esc_attr (get_option ('add_to_cart_grouped_single', $texto_single)); $texto_simple_single = esc_attr (get_option ('add_to_cart_simple_single', $texto_single)); $texto_variable_single = esc_attr (get_option ('add_to_cart_variable_single', $texto_single)); $texto_bookable_single = esc_attr (get_option ('add_to_cart_bookable_single', $texto_bookable)); if (is_product()) { //Para la página de producto switch ($product_type) { case 'external': return $texto_externo_single; break; case 'grouped': return $texto_agrupado_single; break; case 'simple': return $texto_simple_single; break; case 'variable': return $texto_variable_single; break; case 'booking': return $texto_bookable_single; break; default: return $texto_single; } } else { //Para las páginas de archivo switch ($product_type) { case 'external': return $texto_externo; break; case 'grouped': return $texto_agrupado; break; case 'simple': return $texto_simple; break; case 'variable': return $texto_variable; break; case 'booking': return $texto_bookable; break; default: return $texto_single; } } } add_filter ('add_to_cart_text', 'er_cambia_texto_boton'); //Compatibilidad para WooCommerce <2.1 add_filter ('woocommerce_product_add_to_cart_text', 'er_cambia_texto_boton'); add_filter ('woocommerce_product_single_add_to_cart_text', 'er_cambia_texto_boton'); add_filter ('woocommerce_booking_single_add_to_cart_text', 'er_cambia_texto_boton'); //WooCommerce Bookings single product //Creamos el menú de opciones function er_crea_menu_opciones () { add_options_page (__('Add to Cart Custom Text', 'add-to-cart-custom-text'), __('Add to Cart Button', 'add-to-cart-custom-text'), 'manage_options', 'add-to-cart', 'er_add_to_cart_opciones'); } //Registramos las opciones function er_registra_opciones () { $opciones = array('add_to_cart_external', 'add_to_cart_grouped', 'add_to_cart_simple', 'add_to_cart_variable', 'add_to_cart_external_single', 'add_to_cart_grouped_single', 'add_to_cart_simple_single', 'add_to_cart_variable_single'); if (post_type_exists ('bookable_resource')) array_push ($opciones, 'add_to_cart_bookable', 'add_to_cart_bookable_single'); foreach ($opciones as $opcion) register_setting ('addtocart-opciones', $opcion); } if (is_admin()) { add_action ('admin_menu', 'er_crea_menu_opciones'); add_action ('admin_init', 'er_registra_opciones'); } //Y creamos la página de opciones function er_add_to_cart_opciones () { current_user_can ('manage_options') or wp_die (__('Sorry, you are not allowed to access this page.')); ?>