Otros plugins útiles para WordPress y WooCommerce Author: Enrique J. Ros Author URI: http://www.enriquejros.com/ Version: 1.3 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html */ /* Copyright 2016 Enrique J. Ros (email: enrique@enriquejros.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ //Cargamos la traducción load_plugin_textdomain ('add-to-cart-custom-text', false, dirname (plugin_basename ( __FILE__ ))); //Core function er_cambia_texto_boton () { global $product; $product_type = $product -> product_type; //Cogemos el valor de la variable de la bd y si no por defecto $texto_single = 'Add to cart'; //esc_attr (get_option ('add_to_cart_single', 'Add to cart'); $texto_externo = esc_attr (get_option ('add_to_cart_external', 'Buy product')); $texto_agrupado = esc_attr (get_option ('add_to_cart_grouped', 'View products')); $texto_simple = esc_attr (get_option ('add_to_cart_simple', 'Add to cart')); $texto_variable = esc_attr (get_option ('add_to_cart_variable', 'Select options')); $texto_bookable = esc_attr (get_option ('add_to_cart_bookable', 'Book now')); $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, 'woocommerce'); break; case 'grouped': return __($texto_agrupado_single, 'woocommerce'); break; case 'simple': return __($texto_simple_single, 'woocommerce'); break; case 'variable': return __($texto_variable_single, 'woocommerce'); break; // case 'booking': // return __($texto_bookable_single, 'woocommerce-bookings'); // break; default: return __($texto_single, 'woocommerce'); } } else { //Para las páginas de archivo switch ($product_type) { case 'external': return __($texto_externo, 'woocommerce'); break; case 'grouped': return __($texto_agrupado, 'woocommerce'); break; case 'simple': return __($texto_simple, 'woocommerce'); break; case 'variable': return __($texto_variable, 'woocommerce'); break; case 'booking': return __($texto_bookable, 'woocommerce-bookings'); break; default: return __($texto_single, 'woocommerce'); } } } 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'); //Creamos el menú de opciones function er_crea_menu_opciones () { add_options_page ('Add to Cart Custom Text', 'Add to Cart Button', 'manage_options', 'add-to-cart', 'er_add_to_cart_opciones'); } //Registramos las opciones function er_registra_opciones () { //register_setting ('addtocart-opciones', 'add_to_cart_single'); register_setting ('addtocart-opciones', 'add_to_cart_external'); register_setting ('addtocart-opciones', 'add_to_cart_grouped'); register_setting ('addtocart-opciones', 'add_to_cart_simple'); register_setting ('addtocart-opciones', 'add_to_cart_variable'); register_setting ('addtocart-opciones', 'add_to_cart_external_single'); register_setting ('addtocart-opciones', 'add_to_cart_grouped_single'); register_setting ('addtocart-opciones', 'add_to_cart_simple_single'); register_setting ('addtocart-opciones', 'add_to_cart_variable_single'); if (is_plugin_active ('woocommerce-bookings/woocommmerce-bookings.php')) { register_setting ('addtocart-opciones', 'add_to_cart_bookable'); // register_setting ('addtocart-opciones', 'add_to_cart_bookable_single'); } } 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 () { if (!is_plugin_active ('woocommerce/woocommerce.php')) //Comprobamos que WooCommerce está instalado y activo wp_die (__('This plugin has no sense without WooCommerce. Please, activate WooCommerce first.', 'add-to-cart-custom-text')); if (!current_user_can ('manage_options')) //Comprobamos si el usuario tiene permisos para acceder a las opciones wp_die (__('You do not have sufficient permissions to access this page.')); ?>