Cart implements Registerable

Provides integration with the cart.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

Registerable

Table of Contents

display_cart_notice()  : void
Display the cart notice.
display_discounted_price_in_cart()  : string
Display the discounted price in the cart.
force_mini_cart_calculation()  : void
Workaround - https://github.com/woocommerce/woocommerce/issues/26422
get_applicable_discounts()  : array<string|int, Discount>
Returns a list of discounts matching the conditions and content of the cart.
get_products_in_categories()  : array<string|int, mixed>
Get the products in specific categories in the cart but maintain the cart structure.
get_specific_products()  : array<string|int, mixed>
Get the specific products in the cart.
has_products_in_categories()  : bool
Determines if the cart has products in specific categories.
has_specific_products()  : bool
Determines if the cart has specific products.
preserve_shipping_methods()  : void
Preserves the chosen shipping methods during cart calculations to prevent them from being reset. This is needed because WooCommerce sometimes resets shipping methods when recalculating cart totals, which can cause issues with shipping costs and available methods.
register()  : void
register_discounts()  : void
Get applicable discounts and register the first one.
show_total_discount_cart_checkout()  : void
Displays the total amount of savings in the cart.
mark_discounted_products()  : void
Mark the discounted products in the cart.

Methods

display_cart_notice()

Display the cart notice.

public display_cart_notice() : void
Return values
void

display_discounted_price_in_cart()

Display the discounted price in the cart.

public display_discounted_price_in_cart(string $price, array<string|int, mixed> $values, string $cart_item_key) : string
Parameters
$price : string

The price.

$values : array<string|int, mixed>

The cart item values.

$cart_item_key : string

The cart item key.

Return values
string

force_mini_cart_calculation()

Workaround - https://github.com/woocommerce/woocommerce/issues/26422

public force_mini_cart_calculation() : void
Return values
void

get_applicable_discounts()

Returns a list of discounts matching the conditions and content of the cart.

public get_applicable_discounts(WC_Cart $cart[, bool $should_calculate = true ]) : array<string|int, Discount>
Parameters
$cart : WC_Cart
$should_calculate : bool = true

Whether to calculate the totals.

Return values
array<string|int, Discount>

get_products_in_categories()

Get the products in specific categories in the cart but maintain the cart structure.

public static get_products_in_categories(WC_Cart $cart, array<string|int, mixed> $categories) : array<string|int, mixed>
Parameters
$cart : WC_Cart

The cart object.

$categories : array<string|int, mixed>

The categories to get.

Return values
array<string|int, mixed>

The products.

get_specific_products()

Get the specific products in the cart.

public static get_specific_products(WC_Cart $cart, array<string|int, mixed> $products) : array<string|int, mixed>
Parameters
$cart : WC_Cart

The cart object.

$products : array<string|int, mixed>

The products to get.

Return values
array<string|int, mixed>

The products.

has_products_in_categories()

Determines if the cart has products in specific categories.

public static has_products_in_categories(WC_Cart $cart, array<string|int, mixed> $categories) : bool
Parameters
$cart : WC_Cart

The cart object.

$categories : array<string|int, mixed>

The categories to check for.

Return values
bool

True if the cart has the products, false otherwise.

has_specific_products()

Determines if the cart has specific products.

public static has_specific_products(WC_Cart $cart, array<string|int, mixed> $products) : bool
Parameters
$cart : WC_Cart

The cart object.

$products : array<string|int, mixed>

The products to check for.

Return values
bool

True if the cart has the products, false otherwise.

preserve_shipping_methods()

Preserves the chosen shipping methods during cart calculations to prevent them from being reset. This is needed because WooCommerce sometimes resets shipping methods when recalculating cart totals, which can cause issues with shipping costs and available methods.

public preserve_shipping_methods() : void

This method stores the currently chosen shipping methods before calculations and restores them afterwards if they have changed.

Return values
void

register()

public register() : void
Tags
inheritdoc
Return values
void

register_discounts()

Get applicable discounts and register the first one.

public register_discounts(WC_Cart $cart) : void
Parameters
$cart : WC_Cart
Return values
void

show_total_discount_cart_checkout()

Displays the total amount of savings in the cart.

public show_total_discount_cart_checkout() : void
Return values
void

mark_discounted_products()

Mark the discounted products in the cart.

private mark_discounted_products(WC_Cart &$cart) : void

This adds a flag to the cart items to indicate that they have been discounted.

Parameters
$cart : WC_Cart
Return values
void

Search results