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 un mensaje con el número de usuarios que están viendo un producto es esos momentos. | |
| add_action( 'woocommerce_single_product_summary', 'show_num_of_users_are_viewing_products', 25 ); | |
| function show_num_of_users_are_viewing_products(){ | |
| global $post; | |
| $list_of_products = array( 92, 95, 83 ); // Indica aquí los IDs de los productos donde quieras mostrar el mensaje (separados por coma). Si vas a mostrarlo en todos los productos, entonces no hagas nada. | |
| $num_of_users = rand( 1, 10 ); | |
| if ( empty( $list_of_products ) || in_array( $post->ID , $list_of_products ) ) { | |
| ?> |
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_action( 'wp_head', 'add_ga_tracking_code' ); | |
| function add_ga_tracking_code(){ | |
| ?> | |
| <!-- Pega tu código de Analytics aquí --> | |
| <script> | |
| (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
| (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
| m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
| })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | |
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 ) { | |
| $new_rates = $rates; | |
| if ( isset( $rates ) ) { | |
| foreach ( $rates as $key => $value ) { | |
| if ( $value->method_id == 'free_shipping' ) { |
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 determinados métodos de pago en función de la categoría del producto | |
| add_filter( 'woocommerce_available_payment_gateways', 'show_payment_gateways_based_on_products_categories', 1, 1 ); | |
| function show_payment_gateways_based_on_products_categories( $methods ){ | |
| $new_methods = $methods; | |
| $products_categories_list = array( '' ); //---- Aquí debes introducir el listado de slugs de categorías de productos separados por coma. | |
| $payment_gateways_list = array( '' ); //---- Aquí debes introducir el listado de IDs de métodos de pago permitidos para estos productos, por ejemplo; array( 'paypal', 'cod' ) | |
| $cart_content = WC()->cart->cart_contents; |
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 determinados métodos de pago en función del producto que haya en el carro | |
| add_filter( 'woocommerce_available_payment_gateways', 'show_payment_gateways_based_on_products', 1, 1 ); | |
| function show_payment_gateways_based_on_products( $methods ){ | |
| $new_methods = $methods; | |
| $product_list = array( ); //---- Aquí debes introducir el listado de IDs de productos, por ejemplo; array( 95, 112, 114 ) | |
| $payment_gateways_list = array( ); //---- Aquí debes introducir el listado de IDs de métodos de pago permitidos para estos productos, por ejemplo; array( 'paypal', 'cod' ) | |
| $cart_content = WC()->cart->cart_contents; |
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
| // Inserta el pixel de Facebook en todas las páginas y añade el evento de conversión de compra para medir las compras finalizadas | |
| if ( in_array( 'woocommerce/woocommerce.php', get_option( 'active_plugins' ) ) && version_compare( WC()->version , '3.0.0', '>' ) ){ | |
| add_action( 'wp_head', 'fb_pixel_purchases_traking' ); | |
| function fb_pixel_purchases_traking() { | |
| $fb_pixel_id = '<FB_PIXEL_ID>'; // Debes reemplazar el texto <FB_PIXEL_ID> por tu código identificador del pixel manteniendo las comillas | |
| ob_start() | |
| ?> | |
| <!-- Start FB Tracking --> |
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
| // Deshabilita la opción de pago contra-reembolso cuando el pedido supera los X€ | |
| add_filter( 'woocommerce_available_payment_gateways', 'disable_cod_gateway_by_cart_total_amount', 1 ); | |
| function disable_cod_gateway_by_cart_total_amount( $gateways ){ | |
| $total_amount = 100; // Indica aquí el coste del carrito a partir del cual se deshabilita el pago contra-reembolso | |
| if( ( WC()->cart->total > $total_amount ) && ( array_key_exists( 'cod', $gateways ) ) ) { | |
| unset( $gateways[ 'cod' ] ); | |
| } | |
| return $gateways; |
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
| // Limpia el carro y solo muestra el último producto añadido | |
| add_action( 'woocommerce_before_checkout_form', 'allow_only_the_last_product_added' ); | |
| function allow_only_the_last_product_added() { | |
| // Remove all products except the lastone | |
| if ( WC()->cart->get_cart_contents_count() > 1 ) { | |
| // Get the key of the last product added | |
| $cart_content = WC()->cart->get_cart(); | |
| $lastone_key = key( array_slice( $cart_content, -1, 1, TRUE ) ); |