Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Crear shortcode para el item del carrito de WooCommerce
- add_shortcode ('ov_boton_carrito', 'ov_boton_carrito' );
- function ov_boton_carrito() {
- ob_start();
- $cart_count = WC()->cart->cart_contents_count; // Variable del recuento del carrito
- ?>
- <li class="cart-sc"><a class="cart-contents" title="Mi carrito">
- <?php
- if ( $cart_count > 0 ) {
- ?>
- <span class="cart-contents-count"><?php echo $cart_count; ?></span>
- <?php
- }
- ?>
- </a></li>
- <?php
- return ob_get_clean();
- }
- // Agregar contador de productos mediante ajax
- add_filter( 'woocommerce_add_to_cart_fragments', 'ov_carrito_contador' );
- function ov_carrito_contador( $fragments ) {
- ob_start();
- $cart_count = WC()->cart->cart_contents_count;
- ?>
- <a class="cart-contents" title="<?php _e( 'Ver carrito de compras' ); ?>">
- <?php
- if ( $cart_count > 0 ) {
- ?>
- <span class="cart-contents-count"><?php echo $cart_count; ?></span>
- <?php
- }
- ?></a>
- <?php
- $fragments['a.cart-contents'] = ob_get_clean();
- return $fragments;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement