- This topic has 1 reply, 2 voices, and was last updated 4 years, 8 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The topic ‘Cart Icon – Number of items’ is closed to new replies.
Home › Forums › Lorina Pro › Cart Icon – Number of items
Tagged: cart icon
Hi.
I’m using Lorina Pro with Woocommerce in a Norwegian web-shop, and I’m trying to get the cart icon (in the “top-cart” section) to display the number of yunique items in the cart. We’re selling both fractions and whole units of a number of products, and the typical fraction of fabrics is below 0.5m. This amount shows up as 0 by the cart icon. I do not want the decimals to show up, but the total number of unique products in the cart.
Is there an easy way to do this?
The theme only displays the cart quantity provided by the WooCommerce get_cart_contents_count
function.
Looking at the WooCommerce php files, this is the full function:
public function get_cart_contents_count() {
return apply_filters( 'woocommerce_cart_contents_count', array_sum( wp_list_pluck( $this->get_cart(), 'quantity' ) ) );
}
This function is filterable with the woocommerce_cart_contents_count
filter, which means that you can create your own function to output a number based on your own formula, like so:
function tronds_cart_quantity() {
/* your formula/calculations of cart quantity here */
}
add_filter( 'woocommerce_cart_contents_count', 'tronds_cart_quantity' );
Any php functions such as this should be added to the functions.php file of a child theme.