cart, 'WC_Cart' ); if ( ! $has_cart ) { $session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); WC()->session = new $session_class(); WC()->session->init(); WC()->cart = new \WC_Cart(); WC()->customer = new \WC_Customer( get_current_user_id(), true ); } } public function pa_add_mini_cart_fragments( $fragments ) { $product_count = WC()->cart->get_cart_contents_count(); $fragments['.pa-woo-mc__outer-container .pa-woo-mc__badge'] = '' . $product_count . ''; $fragments['.pa-woo-mc__cart-footer .pa-woo-mc__cart-count'] = '' . $product_count . ''; $fragments['.pa-woo-mc__outer-container .pa-woo-mc__text-wrapper .pa-woo-mc__subtotal'] = '' . WC()->cart->get_cart_subtotal() . ''; $fragments['.pa-woo-mc__cart-footer .pa-woo-mc__subtotal'] = '' . WC()->cart->get_cart_subtotal() . ''; return $fragments; } public function pa_update_mc_qty() { check_ajax_referer( 'pa-mini-cart-nonce', 'nonce' ); if ( ! isset( $_POST['itemKey'] ) || ! isset( $_POST['quantity'] ) ) { return; } $item_key = sanitize_text_field( $_POST['itemKey'] ); $quantity = absint( $_POST['quantity'] ); if ( $quantity > 0 && WC()->cart->get_cart_item( $_POST['itemKey'] ) ) { WC()->cart->set_quantity( $_POST['itemKey'], $_POST['quantity'], true ); } \WC_AJAX::get_refreshed_fragments(); wp_send_json_success(); } public function pa_delete_cart_item() { check_ajax_referer( 'pa-mini-cart-nonce', 'nonce' ); if ( ! isset( $_POST['itemKey'] ) ) { return; } $item_key = sanitize_text_field( $_POST['itemKey'] ); if ( WC()->cart->get_cart_item( $_POST['itemKey'] ) ) { WC()->cart->remove_cart_item( $_POST['itemKey'] ); } \WC_AJAX::get_refreshed_fragments(); wp_send_json_success(); } }