cart_extension
extends abstract_extension
in package
Extension: cart_extension - extended cart/payment plans - ATP Custom Plugin for WordPress
Tags
Table of Contents
- VERSION = '24.0626.1'
- $wcCart : object
- $wcOrder : object
- __construct() : void
- constructor method
- add_to_cart() : bool
- When adding to cart (woocommerce_add_to_cart)
- add_to_cart_data() : bool
- When adding to cart - item data (woocommerce_add_cart_item_data)
- add_to_cart_individually() : bool
- When adding to cart, check individuality rules (woocommerce_add_to_cart_sold_individually_found_in_cart)
- addActionsAndFilters() : void
- Add filters and actions - called from main plugin
- addLinkedItem() : void
- for external use - add chained/linked item
- addShortcodes() : void
- Add shortcodes - called from main plugin
- admin_enqueue_scripts() : void
- admin enqueue scripts.
- admin_options_settings() : void
- register options on options_settings_page
- after_calculate_cart_totals() : void
- called after calculating cart totals and payment plans (woocommerce_after_calculate_totals)
- ajax_update_deposit_container() : void
- Get updated payment/fullpay button and message html on product pages
- applied_coupon() : void
- when a coupon is applied (woocommerce_applied_coupon)
- before_add_to_cart() : mixed
- before_add_to_cart_button() : void
- Add payment option select before add-to-cart button (woocommerce_before_add_to_cart_button)
- before_calculate_cart_totals() : void
- called before calculating cart totals (woocommerce_before_calculate_totals)
- calculate_first_payment_total() : float
- Calculates order first payment (woocommerce_deposits_cart_deposit_amount)
- calculate_item_payments() : array<string|int, mixed>
- Override payment data for item (wc_deposits_cart_item_deposit_data)
- calculate_next_payment_total() : array<string|int, mixed>
- Calculates order payment totals (wc_deposits_cart_payment_schedule)
- calculate_payment_plan() : void
- filter for external access to payment plan calculator
- cart() : object
- Calculates and extends the WC Cart
- cart_calculate_fees() : void
- Calculates fees/discounts (woocommerce_cart_calculate_fees)
- cart_checkout_item_detail() : string
- Set the item payment plan details on cart/checkout (woocommerce_get_item_data)
- cart_checkout_order_total() : void
- After order totals, display payment breakdown (woocommerce_cart_totals_after_order_total woocommerce_review_order_after_order_total)
- cart_clear_session() : void
- clear the session once the confirmation page completes
- cart_fullpay_upgrade() : void
- After cart items, show full-pay upgrade option from coupon (woocommerce_cart_collaterals)
- cart_fullpay_upgrade_refresh() : void
- Ajax refresh of full-pay upgrade option (woocommerce_add_to_cart_fragments())
- cart_fullpay_upgrade_total() : string
- When displaying the coupon in totals... (woocommerce_cart_totals_coupon_label & woocommerce_cart_totals_coupon_html)
- cart_item_price() : float
- Get an item price from the cart (woocommerce_cart_item_price)
- cart_load_from_session() : void
- when WC Cart is loaded from session (woocommerce_cart_loaded_from_session)
- cart_save_to_session() : void
- when WC Cart is saved to the session (woocommerce_cart_updated & woocommerce_checkout_init)
- confirmation_order_total() : array<string|int, mixed>
- After order totals, display first and future payment breakdown (woocommerce_get_order_item_totals)
- coupon_fullpay_upgrade_with_individual() : array<string|int, mixed>
- When adding a fullpay upgrade coupoon, allow with individual use coupons (woocommerce_apply_with_individual_use_coupon)
- coupon_individual_with_fullpay_upgrade() : array<string|int, mixed>
- When adding an individual use coupon, keep the fullpay upgrade if it is there (woocommerce_apply_individual_use_coupon)
- deposit_item_detail() : string
- Override the item deposit details on cart/checkout (woocommerce_get_item_data)
- deposits_tooltip_html() : string
- Override the "To Pay" popup for wc-deposits (woocommerce_deposits_tooltip_html) or "Due Today" details ($this->cart_checkout_order_total())
- enqueue_scripts() : void
- enqueue scripts
- get_discount_tax() : float
- get order discount tax either from saved cart calculation
- get_discount_total() : float
- get order discounts either from saved cart calculation
- get_first_subtotal() : float
- get order first payment either from saved cart calculation or order
- get_first_total() : float
- get order first payment either from saved cart calculation or order
- get_option_deposit_button() : string
- Override payment pay button html (option_wc_deposits_button_deposit).
- get_option_fullpay_button() : string
- Override full pay button html (option_wc_deposits_button_full_amount).
- get_order_value() : float|mixed|null
- get order value either from saved cart calculation or order
- get_payments() : int
- get order payments either from saved cart calculation
- get_product_available_plans() : array<string|int, mixed>|bool
- Filter available payment plans (wc_deposits_product_deposit_available_plans).
- get_shipping_tax() : float
- get order shipping tax either from saved cart calculation or order
- get_shipping_total() : float
- get order shipping either from saved cart calculation or order
- get_subtotal() : float
- get order sub-total either from saved cart calculation or order
- get_total() : float
- get order total either from saved cart calculation or order
- get_total_tax() : float
- get order tax either from saved cart calculation or order
- initialize() : void
- initialize method - called from main plugin
- order() : order
- Extends the WC Order with (previously) calculated cart values
- override_force_deposit() : string
- Override deposit enabled (wc_deposits_product_enable_deposit / wc_deposits_product_force_deposit)
- remove_from_cart() : void
- Before removing from cart (woocommerce_remove_cart_item)
- removed_coupon() : void
- when a coupon is removed (woocommerce_removed_coupon)
- validate_coupon() : void
- is a coupon valid (woocommerce_coupon_is_valid_for_product)
- wcd_enqueue_scripts() : void
- enqueue scripts for wc-deposits
Constants
VERSION
public
string
VERSION
= '24.0626.1'
extension version
Properties
$wcCart
public
object
$wcCart
the current cart
$wcOrder
public
object
$wcOrder
the current order
Methods
__construct()
constructor method
public
__construct(object $plugin) : void
Parameters
- $plugin : object
-
main plugin object
Return values
void —add_to_cart()
When adding to cart (woocommerce_add_to_cart)
public
add_to_cart(string $cart_item_key, int $product_id, int $quantity, int $variation_id, object $variation, array<string|int, mixed> $cart_item_data) : bool
Parameters
- $cart_item_key : string
- $product_id : int
- $quantity : int
- $variation_id : int
- $variation : object
- $cart_item_data : array<string|int, mixed>
Return values
bool —add_to_cart_data()
When adding to cart - item data (woocommerce_add_cart_item_data)
public
add_to_cart_data(array<string|int, mixed> $cart_item_data, int $product_id, int $variation_id, int $quantity) : bool
Parameters
- $cart_item_data : array<string|int, mixed>
- $product_id : int
- $variation_id : int
- $quantity : int
Return values
bool —add_to_cart_individually()
When adding to cart, check individuality rules (woocommerce_add_to_cart_sold_individually_found_in_cart)
public
add_to_cart_individually(bool $isInCart, int $product_id, int $variation_id, array<string|int, mixed> $cart_item_data, mixed $cart_id) : bool
Parameters
- $isInCart : bool
- $product_id : int
- $variation_id : int
- $cart_item_data : array<string|int, mixed>
- $cart_id : mixed
Return values
bool —true (found in cart) to disallow add
addActionsAndFilters()
Add filters and actions - called from main plugin
public
addActionsAndFilters() : void
Return values
void —addLinkedItem()
for external use - add chained/linked item
public
addLinkedItem(object|int|string $ifItem, int|string $addItem[, int|null $discount = null ][, float|null $price = null ]) : void
Parameters
- $ifItem : object|int|string
-
parent product or coupon
- $addItem : int|string
-
child item id or sku
- $discount : int|null = null
-
discount percentage
- $price : float|null = null
-
child item price override
Tags
Return values
void —addShortcodes()
Add shortcodes - called from main plugin
public
addShortcodes() : void
Return values
void —admin_enqueue_scripts()
admin enqueue scripts.
public
admin_enqueue_scripts() : void
fixes some issues with wc-deposits
Return values
void —admin_options_settings()
register options on options_settings_page
public
admin_options_settings() : void
Tags
Return values
void —after_calculate_cart_totals()
called after calculating cart totals and payment plans (woocommerce_after_calculate_totals)
public
after_calculate_cart_totals(object $wcCart) : void
Parameters
- $wcCart : object
-
woocommercce cart
Return values
void —ajax_update_deposit_container()
Get updated payment/fullpay button and message html on product pages
public
ajax_update_deposit_container(mixed $data) : void
Parameters
- $data : mixed
Return values
void —applied_coupon()
when a coupon is applied (woocommerce_applied_coupon)
public
applied_coupon(string $coupon_code) : void
Parameters
- $coupon_code : string
-
the coupon code
Return values
void —before_add_to_cart()
public
before_add_to_cart(mixed $quantity, mixed $product_id) : mixed
Parameters
- $quantity : mixed
- $product_id : mixed
Return values
mixed —before_add_to_cart_button()
Add payment option select before add-to-cart button (woocommerce_before_add_to_cart_button)
public
before_add_to_cart_button() : void
- Not used with wc-deposits *
Return values
void —before_calculate_cart_totals()
called before calculating cart totals (woocommerce_before_calculate_totals)
public
before_calculate_cart_totals(object $wcCart) : void
Parameters
- $wcCart : object
-
woocommercce cart
Return values
void —calculate_first_payment_total()
Calculates order first payment (woocommerce_deposits_cart_deposit_amount)
public
calculate_first_payment_total(float $deposit, float $total, object $wcCart) : float
Parameters
- $deposit : float
-
first payment
- $total : float
-
order total
- $wcCart : object
-
WC_Cart
Return values
float —first payment
calculate_item_payments()
Override payment data for item (wc_deposits_cart_item_deposit_data)
public
calculate_item_payments(array<string|int, mixed> $deposit_meta, array<string|int, mixed> $cart_item) : array<string|int, mixed>
Parameters
- $deposit_meta : array<string|int, mixed>
-
item payment array
- $cart_item : array<string|int, mixed>
-
item array
Return values
array<string|int, mixed> —calculate_next_payment_total()
Calculates order payment totals (wc_deposits_cart_payment_schedule)
public
calculate_next_payment_total(array<string|int, mixed> $schedule, array<string|int, mixed> $remaining, object $wcCart) : array<string|int, mixed>
Parameters
- $schedule : array<string|int, mixed>
-
payment schedule
- $remaining : array<string|int, mixed>
-
remaining details
- $wcCart : object
-
WC_Cart
Return values
array<string|int, mixed> —payment schedule
calculate_payment_plan()
filter for external access to payment plan calculator
public
calculate_payment_plan(mixed $plan, mixed $payments, mixed $price[, mixed $first = null ][, mixed $qty = 1 ]) : void
Parameters
- $plan : mixed
- $payments : mixed
- $price : mixed
- $first : mixed = null
- $qty : mixed = 1
Return values
void —cart()
Calculates and extends the WC Cart
public
cart([int|object $order = null ][, bool $savedCart = false ]) : object
Parameters
- $order : int|object = null
-
WC_Order
- $savedCart : bool = false
-
get saved cart
Return values
object —WC_Cart extended
cart_calculate_fees()
Calculates fees/discounts (woocommerce_cart_calculate_fees)
public
cart_calculate_fees() : void
Tags
Return values
void —cart_checkout_item_detail()
Set the item payment plan details on cart/checkout (woocommerce_get_item_data)
public
cart_checkout_item_detail(array<string|int, mixed> $item_data, array<string|int, mixed> $cart_data) : string
- Not used with wc-deposits *
Parameters
- $item_data : array<string|int, mixed>
-
cart details for item
- $cart_data : array<string|int, mixed>
-
current product
Return values
string —cart_checkout_order_total()
After order totals, display payment breakdown (woocommerce_cart_totals_after_order_total woocommerce_review_order_after_order_total)
public
cart_checkout_order_total() : void
Return values
void —cart_clear_session()
clear the session once the confirmation page completes
public
cart_clear_session() : void
Return values
void —cart_fullpay_upgrade()
After cart items, show full-pay upgrade option from coupon (woocommerce_cart_collaterals)
public
cart_fullpay_upgrade() : void
Return values
void —cart_fullpay_upgrade_refresh()
Ajax refresh of full-pay upgrade option (woocommerce_add_to_cart_fragments())
public
cart_fullpay_upgrade_refresh(string $fragments) : void
Parameters
- $fragments : string
-
cart page html fragments
Return values
void —cart_fullpay_upgrade_total()
When displaying the coupon in totals... (woocommerce_cart_totals_coupon_label & woocommerce_cart_totals_coupon_html)
public
cart_fullpay_upgrade_total(string $html, object $coupon) : string
Parameters
- $html : string
-
cart coupon label or discount/description
- $coupon : object
Return values
string —cart_item_price()
Get an item price from the cart (woocommerce_cart_item_price)
public
cart_item_price(string $price, array<string|int, mixed> $cart_item, string $cart_item_key) : float
Parameters
- $price : string
-
(formated)
- $cart_item : array<string|int, mixed>
- $cart_item_key : string
Return values
float —price
cart_load_from_session()
when WC Cart is loaded from session (woocommerce_cart_loaded_from_session)
public
cart_load_from_session(object $wcCart) : void
Parameters
- $wcCart : object
-
WC_Cart
Return values
void —cart_save_to_session()
when WC Cart is saved to the session (woocommerce_cart_updated & woocommerce_checkout_init)
public
cart_save_to_session() : void
Return values
void —confirmation_order_total()
After order totals, display first and future payment breakdown (woocommerce_get_order_item_totals)
public
confirmation_order_total(mixed $total_rows, mixed $order, mixed $tax_display) : array<string|int, mixed>
Parameters
- $total_rows : mixed
- $order : mixed
- $tax_display : mixed
Return values
array<string|int, mixed> —coupon_fullpay_upgrade_with_individual()
When adding a fullpay upgrade coupoon, allow with individual use coupons (woocommerce_apply_with_individual_use_coupon)
public
coupon_fullpay_upgrade_with_individual(bool $allowed, obect $the_coupon, obect $coupon, array<string|int, mixed> $applied_coupons) : array<string|int, mixed>
Parameters
- $allowed : bool
-
this coupon is allowed (false)
- $the_coupon : obect
-
the coupon being added
- $coupon : obect
-
applied individual use coupon
- $applied_coupons : array<string|int, mixed>
-
coupons already applied
Return values
array<string|int, mixed> —coupon_individual_with_fullpay_upgrade()
When adding an individual use coupon, keep the fullpay upgrade if it is there (woocommerce_apply_individual_use_coupon)
public
coupon_individual_with_fullpay_upgrade(array<string|int, mixed> $allowed, obect $the_coupon, array<string|int, mixed> $applied_coupons) : array<string|int, mixed>
Parameters
- $allowed : array<string|int, mixed>
-
allowed coupon codes
- $the_coupon : obect
-
the coupon being added
- $applied_coupons : array<string|int, mixed>
-
coupons already applied
Return values
array<string|int, mixed> —deposit_item_detail()
Override the item deposit details on cart/checkout (woocommerce_get_item_data)
public
deposit_item_detail(array<string|int, mixed> $item_data, array<string|int, mixed> $cart_data) : string
Parameters
- $item_data : array<string|int, mixed>
-
cart details for item
- $cart_data : array<string|int, mixed>
-
current product
Return values
string —deposits_tooltip_html()
Override the "To Pay" popup for wc-deposits (woocommerce_deposits_tooltip_html) or "Due Today" details ($this->cart_checkout_order_total())
public
deposits_tooltip_html([string $html = '' ]) : string
Parameters
- $html : string = ''
-
set by wc-deposits
Return values
string —enqueue_scripts()
enqueue scripts
public
enqueue_scripts() : void
Return values
void —get_discount_tax()
get order discount tax either from saved cart calculation
public
get_discount_tax([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_discount_total()
get order discounts either from saved cart calculation
public
get_discount_total([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_first_subtotal()
get order first payment either from saved cart calculation or order
public
get_first_subtotal([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_first_total()
get order first payment either from saved cart calculation or order
public
get_first_total([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_option_deposit_button()
Override payment pay button html (option_wc_deposits_button_deposit).
public
get_option_deposit_button(string $html) : string
$html may be set in offer_manager taxonomy
Parameters
- $html : string
Return values
string —get_option_fullpay_button()
Override full pay button html (option_wc_deposits_button_full_amount).
public
get_option_fullpay_button(string $html) : string
$html may be set in offer_manager taxonomy
Parameters
- $html : string
Return values
string —get_order_value()
get order value either from saved cart calculation or order
public
get_order_value(object $order, string $name) : float|mixed|null
Parameters
- $order : object
-
WC_Order or order id
- $name : string
-
the name of the value ('order_total',
Return values
float|mixed|null —get_payments()
get order payments either from saved cart calculation
public
get_payments([mixed $order = null ]) : int
Parameters
- $order : mixed = null
Return values
int —get_product_available_plans()
Filter available payment plans (wc_deposits_product_deposit_available_plans).
public
get_product_available_plans(array<string|int, mixed> $availablePlans, int $product_id) : array<string|int, mixed>|bool
wc-deposits may default to the first plan in the $availablePlans array
Parameters
- $availablePlans : array<string|int, mixed>
-
available plan ids
- $product_id : int
-
product id
Return values
array<string|int, mixed>|bool —get_shipping_tax()
get order shipping tax either from saved cart calculation or order
public
get_shipping_tax([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_shipping_total()
get order shipping either from saved cart calculation or order
public
get_shipping_total([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_subtotal()
get order sub-total either from saved cart calculation or order
public
get_subtotal([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_total()
get order total either from saved cart calculation or order
public
get_total([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —get_total_tax()
get order tax either from saved cart calculation or order
public
get_total_tax([mixed $order = null ]) : float
Parameters
- $order : mixed = null
Return values
float —initialize()
initialize method - called from main plugin
public
initialize() : void
Return values
void —order()
Extends the WC Order with (previously) calculated cart values
public
order(int|object $order[, bool $savedCart = false ]) : order
Parameters
- $order : int|object
-
WC_Order
- $savedCart : bool = false
-
get saved cart
Return values
order —object
override_force_deposit()
Override deposit enabled (wc_deposits_product_enable_deposit / wc_deposits_product_force_deposit)
public
override_force_deposit(bool|string $forced, int $product_id) : string
Parameters
- $forced : bool|string
-
force payment plan
- $product_id : int
-
product or variation id
Return values
string —remove_from_cart()
Before removing from cart (woocommerce_remove_cart_item)
public
remove_from_cart(string $cart_item_key, object $wcCart) : void
Parameters
- $cart_item_key : string
- $wcCart : object
Return values
void —removed_coupon()
when a coupon is removed (woocommerce_removed_coupon)
public
removed_coupon(string $coupon_code) : void
Parameters
- $coupon_code : string
-
the coupon code
Return values
void —validate_coupon()
is a coupon valid (woocommerce_coupon_is_valid_for_product)
public
validate_coupon(bool $isValid, object $product, object $coupon, array<string|int, mixed> $cart_item) : void
Parameters
- $isValid : bool
-
true
- $product : object
-
WC_Product
- $coupon : object
-
WC_Coupon
- $cart_item : array<string|int, mixed>
Return values
void —wcd_enqueue_scripts()
enqueue scripts for wc-deposits
public
wcd_enqueue_scripts() : void