Última atividade 1715589642

Malin's Avatar Malin revisou este gist 1715589642. Ir para a revisão

1 file changed, 58 insertions

empty-mini-cart-button.php(arquivo criado)

@@ -0,0 +1,58 @@
1 + // for QRh
2 +
3 + function add_empty_cart_message_sitewide() {
4 + // Check if WooCommerce is active before proceeding
5 + if ( class_exists('WooCommerce') ) {
6 + ?>
7 + <script type="text/javascript">
8 + jQuery(document).ready(function($) {
9 + var cartContainer = $('.elementor-menu-cart__main'); // Ensure this targets your specific menu cart container
10 +
11 + // This function updates the message based on cart contents
12 + function updateEmptyCartMessage() {
13 + var cartCount = <?php echo WC()->cart->get_cart_contents_count(); ?>;
14 +
15 + if (cartCount === 0) {
16 + if (cartContainer.find('.empty-cart-message').length === 0) { // Check if the message is not already there
17 + cartContainer.append('<div class="empty-cart-message">No hay productos en su carrito. <a href="/tienda" class="shop-link">Haga clic aquí para ir a la tienda.</a></div>');
18 + }
19 + } else {
20 + cartContainer.find('.empty-cart-message').remove(); // Remove the message if the cart is not empty
21 + }
22 + }
23 +
24 + // Initial call to set the right message
25 + updateEmptyCartMessage();
26 +
27 + // Re-check when AJAX requests complete in case the cart is updated dynamically
28 + $(document).ajaxComplete(function() {
29 + updateEmptyCartMessage();
30 + });
31 + });
32 + </script>
33 + <style>
34 + .empty-cart-message {
35 + padding: 20px;
36 + text-align: center;
37 + font-size: 16px;
38 + }
39 + .shop-link {
40 + font-family: 'Roboto', Sans-serif;
41 + font-size: 16px;
42 + line-height: 24px;
43 + color: #FFFFFF;
44 + background-color: #21210E;
45 + text-decoration: none;
46 + padding: 10px 20px;
47 + display: inline-block;
48 + border-radius: 4px;
49 + transition: background-color 0.3s ease;
50 + }
51 + .shop-link:hover {
52 + background-color: #E50913;
53 + }
54 + </style>
55 + <?php
56 + }
57 + }
58 + add_action('wp_footer', 'add_empty_cart_message_sitewide');
Próximo Anterior