WooCommerce::initialize_cart()
Initialize the customer and cart objects and setup customer saving on shutdown.
Method of the class: WooCommerce{}
No Hooks.
Return
null
. Nothing.
Usage
$WooCommerce = new WooCommerce(); $WooCommerce->initialize_cart();
Changelog
Since 3.6.4 | Introduced. |
WooCommerce::initialize_cart() WooCommerce::initialize cart code WC 7.7.0
public function initialize_cart() { // Cart needs customer info. if ( is_null( $this->customer ) || ! $this->customer instanceof WC_Customer ) { $this->customer = new WC_Customer( get_current_user_id(), true ); // Customer should be saved during shutdown. add_action( 'shutdown', array( $this->customer, 'save' ), 10 ); } if ( is_null( $this->cart ) || ! $this->cart instanceof WC_Cart ) { $this->cart = new WC_Cart(); } }