Malin revisó este gist . Ir a la revisión
1 file changed, 33 insertions
unique-product-count-in-cart.php(archivo creado)
@@ -0,0 +1,33 @@ | |||
1 | + | /* START Unique product count in cart */ | |
2 | + | // Shortcode to display the number of unique products in the cart with styling | |
3 | + | function display_unique_cart_product_count_styled() { | |
4 | + | // Initialize an empty array to store unique product IDs | |
5 | + | $unique_product_ids = array(); | |
6 | + | ||
7 | + | // Get the cart contents | |
8 | + | $cart_contents = WC()->cart->get_cart(); | |
9 | + | ||
10 | + | // Loop through each item in the cart | |
11 | + | foreach ($cart_contents as $cart_item) { | |
12 | + | // Get the product ID | |
13 | + | $product_id = $cart_item['product_id']; | |
14 | + | ||
15 | + | // Check if the product ID is not already in the array | |
16 | + | if (!in_array($product_id, $unique_product_ids)) { | |
17 | + | // If not, add it to the array | |
18 | + | $unique_product_ids[] = $product_id; | |
19 | + | } | |
20 | + | } | |
21 | + | ||
22 | + | // Count the number of unique products | |
23 | + | $unique_product_count = count($unique_product_ids); | |
24 | + | ||
25 | + | // Style the output | |
26 | + | $output = '<span style="color: #21201E; font-family: Nexa-Bold, sans-serif; font-size: 24px; line-height: 32px;">Tu pedido (' . $unique_product_count . ' productos)</span>'; | |
27 | + | ||
28 | + | // Return the styled output | |
29 | + | return $output; | |
30 | + | } | |
31 | + | add_shortcode('unique_cart_product_count_styled', 'display_unique_cart_product_count_styled'); | |
32 | + | ||
33 | + | /* END Unique product count in cart */ |
Siguiente
Anterior