Submit
Path:
~
/
/
var
/
softaculous
/
sitepad
/
editor
/
site-data
/
plugins
/
kkart-pro
/
includes
/
File Content:
class-kkart-cart-session.php
<?php /** * Cart session handling class. * * @package Kkart\Classes * @version 3.2.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * KKART_Cart_Session class. * * @since 3.2.0 */ final class KKART_Cart_Session { /** * Reference to cart object. * * @since 3.2.0 * @var KKART_Cart */ protected $cart; /** * Sets up the items provided, and calculate totals. * * @since 3.2.0 * @throws Exception If missing KKART_Cart object. * * @param KKART_Cart $cart Cart object to calculate totals for. */ public function __construct( &$cart ) { if ( ! is_a( $cart, 'KKART_Cart' ) ) { throw new Exception( 'A valid KKART_Cart object is required' ); } $this->cart = $cart; } /** * Register methods for this object on the appropriate WordPress hooks. */ public function init() { add_action( 'wp_loaded', array( $this, 'get_cart_from_session' ) ); add_action( 'kkart_cart_emptied', array( $this, 'destroy_cart_session' ) ); add_action( 'kkart_after_calculate_totals', array( $this, 'set_session' ) ); add_action( 'kkart_cart_loaded_from_session', array( $this, 'set_session' ) ); add_action( 'kkart_removed_coupon', array( $this, 'set_session' ) ); // Persistent cart stored to usermeta. add_action( 'kkart_add_to_cart', array( $this, 'persistent_cart_update' ) ); add_action( 'kkart_cart_item_removed', array( $this, 'persistent_cart_update' ) ); add_action( 'kkart_cart_item_restored', array( $this, 'persistent_cart_update' ) ); add_action( 'kkart_cart_item_set_quantity', array( $this, 'persistent_cart_update' ) ); // Cookie events - cart cookies need to be set before headers are sent. add_action( 'kkart_add_to_cart', array( $this, 'maybe_set_cart_cookies' ) ); add_action( 'wp', array( $this, 'maybe_set_cart_cookies' ), 99 ); add_action( 'shutdown', array( $this, 'maybe_set_cart_cookies' ), 0 ); } /** * Get the cart data from the PHP session and store it in class variables. * * @since 3.2.0 */ public function get_cart_from_session() { do_action( 'kkart_load_cart_from_session' ); $this->cart->set_totals( KKART()->session->get( 'cart_totals', null ) ); $this->cart->set_applied_coupons( KKART()->session->get( 'applied_coupons', array() ) ); $this->cart->set_coupon_discount_totals( KKART()->session->get( 'coupon_discount_totals', array() ) ); $this->cart->set_coupon_discount_tax_totals( KKART()->session->get( 'coupon_discount_tax_totals', array() ) ); $this->cart->set_removed_cart_contents( KKART()->session->get( 'removed_cart_contents', array() ) ); $update_cart_session = false; // Flag to indicate the stored cart should be updated. $order_again = false; // Flag to indicate whether this is a re-order. $cart = KKART()->session->get( 'cart', null ); $merge_saved_cart = (bool) get_user_meta( get_current_user_id(), '_kkart_load_saved_cart_after_login', true ); // Merge saved cart with current cart. if ( is_null( $cart ) || $merge_saved_cart ) { $saved_cart = $this->get_saved_cart(); $cart = is_null( $cart ) ? array() : $cart; $cart = array_merge( $saved_cart, $cart ); $update_cart_session = true; delete_user_meta( get_current_user_id(), '_kkart_load_saved_cart_after_login' ); } // Populate cart from order. if ( isset( $_GET['order_again'], $_GET['_wpnonce'] ) && is_user_logged_in() && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'kkart-order_again' ) ) { // WPCS: input var ok, sanitization ok. $cart = $this->populate_cart_from_order( absint( $_GET['order_again'] ), $cart ); // WPCS: input var ok. $order_again = true; } // Prime caches to reduce future queries. if ( is_callable( '_prime_post_caches' ) ) { _prime_post_caches( wp_list_pluck( $cart, 'product_id' ) ); } $cart_contents = array(); foreach ( $cart as $key => $values ) { if ( ! is_customize_preview() && 'customize-preview' === $key ) { continue; } $product = kkart_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] ); if ( empty( $product ) || ! $product->exists() || 0 >= $values['quantity'] ) { continue; } /** * Allow 3rd parties to validate this item before it's added to cart and add their own notices. * * @since 3.6.0 * * @param bool $remove_cart_item_from_session If true, the item will not be added to the cart. Default: false. * @param string $key Cart item key. * @param array $values Cart item values e.g. quantity and product_id. */ if ( apply_filters( 'kkart_pre_remove_cart_item_from_session', false, $key, $values ) ) { $update_cart_session = true; do_action( 'kkart_remove_cart_item_from_session', $key, $values ); } elseif ( ! $product->is_purchasable() ) { $update_cart_session = true; /* translators: %s: product name */ $message = sprintf( __( '%s has been removed from your cart because it can no longer be purchased. Please contact us if you need assistance.', 'kkart' ), $product->get_name() ); /** * Filter message about item removed from the cart. * * @since 3.8.0 * @param string $message Message. * @param KKART_Product $product Product data. */ $message = apply_filters( 'kkart_cart_item_removed_message', $message, $product ); kkart_add_notice( $message, 'error' ); do_action( 'kkart_remove_cart_item_from_session', $key, $values ); } elseif ( ! empty( $values['data_hash'] ) && ! hash_equals( $values['data_hash'], kkart_get_cart_item_data_hash( $product ) ) ) { // phpcs:ignore PHPCompatibility.PHP.NewFunctions.hash_equalsFound $update_cart_session = true; /* translators: %1$s: product name. %2$s product permalink */ kkart_add_notice( sprintf( __( '%1$s has been removed from your cart because it has since been modified. You can add it back to your cart <a href="%2$s">here</a>.', 'kkart' ), $product->get_name(), $product->get_permalink() ), 'notice' ); do_action( 'kkart_remove_cart_item_from_session', $key, $values ); } else { // Put session data into array. Run through filter so other plugins can load their own session data. $session_data = array_merge( $values, array( 'data' => $product, ) ); $cart_contents[ $key ] = apply_filters( 'kkart_get_cart_item_from_session', $session_data, $values, $key ); // Add to cart right away so the product is visible in kkart_get_cart_item_from_session hook. $this->cart->set_cart_contents( $cart_contents ); } } // If it's not empty, it's been already populated by the loop above. if ( ! empty( $cart_contents ) ) { $this->cart->set_cart_contents( apply_filters( 'kkart_cart_contents_changed', $cart_contents ) ); } do_action( 'kkart_cart_loaded_from_session', $this->cart ); if ( $update_cart_session || is_null( KKART()->session->get( 'cart_totals', null ) ) ) { KKART()->session->set( 'cart', $this->get_cart_for_session() ); $this->cart->calculate_totals(); } // If this is a re-order, redirect to the cart page to get rid of the `order_again` query string. if ( $order_again ) { wp_safe_redirect( kkart_get_cart_url() ); exit; } } /** * Destroy cart session data. * * @since 3.2.0 */ public function destroy_cart_session() { KKART()->session->set( 'cart', null ); KKART()->session->set( 'cart_totals', null ); KKART()->session->set( 'applied_coupons', null ); KKART()->session->set( 'coupon_discount_totals', null ); KKART()->session->set( 'coupon_discount_tax_totals', null ); KKART()->session->set( 'removed_cart_contents', null ); KKART()->session->set( 'order_awaiting_payment', null ); } /** * Will set cart cookies if needed and when possible. * * @since 3.2.0 */ public function maybe_set_cart_cookies() { if ( ! headers_sent() && did_action( 'wp_loaded' ) ) { if ( ! $this->cart->is_empty() ) { $this->set_cart_cookies( true ); } elseif ( isset( $_COOKIE['kkart_items_in_cart'] ) ) { // WPCS: input var ok. $this->set_cart_cookies( false ); } } } /** * Sets the php session data for the cart and coupons. */ public function set_session() { KKART()->session->set( 'cart', $this->get_cart_for_session() ); KKART()->session->set( 'cart_totals', $this->cart->get_totals() ); KKART()->session->set( 'applied_coupons', $this->cart->get_applied_coupons() ); KKART()->session->set( 'coupon_discount_totals', $this->cart->get_coupon_discount_totals() ); KKART()->session->set( 'coupon_discount_tax_totals', $this->cart->get_coupon_discount_tax_totals() ); KKART()->session->set( 'removed_cart_contents', $this->cart->get_removed_cart_contents() ); do_action( 'kkart_cart_updated' ); } /** * Returns the contents of the cart in an array without the 'data' element. * * @return array contents of the cart */ public function get_cart_for_session() { $cart_session = array(); foreach ( $this->cart->get_cart() as $key => $values ) { $cart_session[ $key ] = $values; unset( $cart_session[ $key ]['data'] ); // Unset product object. } return $cart_session; } /** * Save the persistent cart when the cart is updated. */ public function persistent_cart_update() { if ( get_current_user_id() && apply_filters( 'kkart_persistent_cart_enabled', true ) ) { update_user_meta( get_current_user_id(), '_kkart_persistent_cart_' . get_current_blog_id(), array( 'cart' => $this->get_cart_for_session(), ) ); } } /** * Delete the persistent cart permanently. */ public function persistent_cart_destroy() { if ( get_current_user_id() && apply_filters( 'kkart_persistent_cart_enabled', true ) ) { delete_user_meta( get_current_user_id(), '_kkart_persistent_cart_' . get_current_blog_id() ); } } /** * Set cart hash cookie and items in cart if not already set. * * @param bool $set Should cookies be set (true) or unset. */ private function set_cart_cookies( $set = true ) { if ( $set ) { $setcookies = array( 'kkart_items_in_cart' => '1', 'kkart_cart_hash' => KKART()->cart->get_cart_hash(), ); foreach ( $setcookies as $name => $value ) { if ( ! isset( $_COOKIE[ $name ] ) || $_COOKIE[ $name ] !== $value ) { kkart_setcookie( $name, $value ); } } } else { $unsetcookies = array( 'kkart_items_in_cart', 'kkart_cart_hash', ); foreach ( $unsetcookies as $name ) { if ( isset( $_COOKIE[ $name ] ) ) { kkart_setcookie( $name, 0, time() - HOUR_IN_SECONDS ); unset( $_COOKIE[ $name ] ); } } } do_action( 'kkart_set_cart_cookies', $set ); } /** * Get the persistent cart from the database. * * @since 3.5.0 * @return array */ private function get_saved_cart() { $saved_cart = array(); if ( apply_filters( 'kkart_persistent_cart_enabled', true ) ) { $saved_cart_meta = get_user_meta( get_current_user_id(), '_kkart_persistent_cart_' . get_current_blog_id(), true ); if ( isset( $saved_cart_meta['cart'] ) ) { $saved_cart = array_filter( (array) $saved_cart_meta['cart'] ); } } return $saved_cart; } /** * Get a cart from an order, if user has permission. * * @since 3.5.0 * * @param int $order_id Order ID to try to load. * @param array $cart Current cart array. * * @return array */ private function populate_cart_from_order( $order_id, $cart ) { $order = kkart_get_order( $order_id ); if ( ! $order->get_id() || ! $order->has_status( apply_filters( 'kkart_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! current_user_can( 'order_again', $order->get_id() ) ) { return; } if ( apply_filters( 'kkart_empty_cart_when_order_again', true ) ) { $cart = array(); } $inital_cart_size = count( $cart ); $order_items = $order->get_items(); foreach ( $order_items as $item ) { $product_id = (int) apply_filters( 'kkart_add_to_cart_product_id', $item->get_product_id() ); $quantity = $item->get_quantity(); $variation_id = (int) $item->get_variation_id(); $variations = array(); $cart_item_data = apply_filters( 'kkart_order_again_cart_item_data', array(), $item, $order ); $product = $item->get_product(); if ( ! $product ) { continue; } // Prevent reordering variable products if no selected variation. if ( ! $variation_id && $product->is_type( 'variable' ) ) { continue; } // Prevent reordering items specifically out of stock. if ( ! $product->is_in_stock() ) { continue; } foreach ( $item->get_meta_data() as $meta ) { if ( taxonomy_is_product_attribute( $meta->key ) ) { $term = get_term_by( 'slug', $meta->value, $meta->key ); $variations[ $meta->key ] = $term ? $term->name : $meta->value; } elseif ( meta_is_product_attribute( $meta->key, $meta->value, $product_id ) ) { $variations[ $meta->key ] = $meta->value; } } if ( ! apply_filters( 'kkart_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data ) ) { continue; } // Add to cart directly. $cart_id = KKART()->cart->generate_cart_id( $product_id, $variation_id, $variations, $cart_item_data ); $product_data = kkart_get_product( $variation_id ? $variation_id : $product_id ); $cart[ $cart_id ] = apply_filters( 'kkart_add_order_again_cart_item', array_merge( $cart_item_data, array( 'key' => $cart_id, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variations, 'quantity' => $quantity, 'data' => $product_data, 'data_hash' => kkart_get_cart_item_data_hash( $product_data ), ) ), $cart_id ); } do_action_ref_array( 'kkart_ordered_again', array( $order->get_id(), $order_items, &$cart ) ); $num_items_in_cart = count( $cart ); $num_items_in_original_order = count( $order_items ); $num_items_added = $num_items_in_cart - $inital_cart_size; if ( $num_items_in_original_order > $num_items_added ) { kkart_add_notice( sprintf( /* translators: %d item count */ _n( '%d item from your previous order is currently unavailable and could not be added to your cart.', '%d items from your previous order are currently unavailable and could not be added to your cart.', $num_items_in_original_order - $num_items_added, 'kkart' ), $num_items_in_original_order - $num_items_added ), 'error' ); } if ( 0 < $num_items_added ) { kkart_add_notice( __( 'The cart has been filled with the items from your previous order.', 'kkart' ) ); } return $cart; } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
abstracts
---
0755
admin
---
0755
cli
---
0755
customizer
---
0755
data-stores
---
0755
emails
---
0755
export
---
0755
gateways
---
0755
import
---
0755
integrations
---
0755
interfaces
---
0755
legacy
---
0755
libraries
---
0755
log-handlers
---
0755
payment-tokens
---
0755
queue
---
0755
rest-api
---
0755
shipping
---
0755
shortcodes
---
0755
theme-support
---
0755
tracks
---
0755
traits
---
0755
walkers
---
0755
wccom-site
---
0755
widgets
---
0755
body-props-settings.php
8379 bytes
0644
class-kkart-ajax.php
131339 bytes
0644
class-kkart-api.php
5090 bytes
0644
class-kkart-auth.php
11939 bytes
0644
class-kkart-autoloader.php
2842 bytes
0644
class-kkart-background-emailer.php
4703 bytes
0644
class-kkart-background-updater.php
3580 bytes
0644
class-kkart-breadcrumb.php
9692 bytes
0644
class-kkart-cache-helper.php
10967 bytes
0644
class-kkart-cart-fees.php
3498 bytes
0644
class-kkart-cart-session.php
14806 bytes
0644
class-kkart-cart-totals.php
28388 bytes
0644
class-kkart-cart.php
64753 bytes
0644
class-kkart-checkout.php
45656 bytes
0644
class-kkart-cli.php
1043 bytes
0644
class-kkart-comments.php
13305 bytes
0644
class-kkart-countries.php
43222 bytes
0644
class-kkart-coupon.php
33350 bytes
0644
class-kkart-customer-download-log.php
3458 bytes
0644
class-kkart-customer-download.php
10606 bytes
0644
class-kkart-customer.php
27894 bytes
0644
class-kkart-data-exception.php
1306 bytes
0644
class-kkart-data-store.php
6022 bytes
0644
class-kkart-datetime.php
2251 bytes
0644
class-kkart-deprecated-action-hooks.php
6697 bytes
0644
class-kkart-deprecated-filter-hooks.php
6413 bytes
0644
class-kkart-discounts.php
31706 bytes
0644
class-kkart-download-handler.php
23930 bytes
0644
class-kkart-emails.php
22698 bytes
0644
class-kkart-embed.php
4284 bytes
0644
class-kkart-form-handler.php
44776 bytes
0644
class-kkart-frontend-scripts.php
26623 bytes
0644
class-kkart-geo-ip.php
31165 bytes
0644
class-kkart-geolite-integration.php
2042 bytes
0644
class-kkart-geolocation.php
10586 bytes
0644
class-kkart-https.php
4397 bytes
0644
class-kkart-install.php
55130 bytes
0644
class-kkart-integrations.php
1316 bytes
0644
class-kkart-log-levels.php
2597 bytes
0644
class-kkart-logger.php
8405 bytes
0644
class-kkart-meta-data.php
2231 bytes
0644
class-kkart-order-factory.php
3212 bytes
0644
class-kkart-order-item-coupon.php
4118 bytes
0644
class-kkart-order-item-fee.php
8909 bytes
0644
class-kkart-order-item-meta.php
5939 bytes
0644
class-kkart-order-item-product.php
13366 bytes
0644
class-kkart-order-item-shipping.php
7933 bytes
0644
class-kkart-order-item-tax.php
6593 bytes
0644
class-kkart-order-item.php
10947 bytes
0644
class-kkart-order-query.php
2578 bytes
0644
class-kkart-order-refund.php
5009 bytes
0644
class-kkart-order.php
62493 bytes
0644
class-kkart-payment-gateways.php
5367 bytes
0644
class-kkart-payment-tokens.php
6047 bytes
0644
class-kkart-post-data.php
18242 bytes
0644
class-kkart-post-types.php
27128 bytes
0644
class-kkart-privacy-background-process.php
1734 bytes
0644
class-kkart-privacy-erasers.php
13603 bytes
0644
class-kkart-privacy-exporters.php
14458 bytes
0644
class-kkart-privacy.php
15212 bytes
0644
class-kkart-product-attribute.php
7052 bytes
0644
class-kkart-product-download.php
6159 bytes
0644
class-kkart-product-external.php
4889 bytes
0644
class-kkart-product-factory.php
3683 bytes
0644
class-kkart-product-grouped.php
5319 bytes
0644
class-kkart-product-query.php
2222 bytes
0644
class-kkart-product-simple.php
1899 bytes
0644
class-kkart-product-variable.php
21983 bytes
0644
class-kkart-product-variation.php
17610 bytes
0644
class-kkart-query.php
31129 bytes
0644
class-kkart-rate-limiter.php
2133 bytes
0644
class-kkart-regenerate-images-request.php
8365 bytes
0644
class-kkart-regenerate-images.php
15607 bytes
0644
class-kkart-register-wp-admin-settings.php
4990 bytes
0644
class-kkart-rest-authentication.php
19811 bytes
0644
class-kkart-rest-exception.php
273 bytes
0644
class-kkart-session-handler.php
10821 bytes
0644
class-kkart-shipping-rate.php
5388 bytes
0644
class-kkart-shipping-zone.php
13404 bytes
0644
class-kkart-shipping-zones.php
4169 bytes
0644
class-kkart-shipping.php
11607 bytes
0644
class-kkart-shortcodes.php
17618 bytes
0644
class-kkart-structured-data.php
17614 bytes
0644
class-kkart-tax.php
36697 bytes
0644
class-kkart-template-loader.php
18878 bytes
0644
class-kkart-tracker.php
23049 bytes
0644
class-kkart-validation.php
5975 bytes
0644
class-kkart-webhook.php
30567 bytes
0644
class-kkart.php
33477 bytes
0644
kkart-account-functions.php
12995 bytes
0644
kkart-attribute-functions.php
21083 bytes
0644
kkart-cart-functions.php
17683 bytes
0644
kkart-conditional-functions.php
12079 bytes
0644
kkart-core-functions.php
84228 bytes
0644
kkart-coupon-functions.php
2711 bytes
0644
kkart-formatting-functions.php
42607 bytes
0644
kkart-notice-functions.php
7623 bytes
0644
kkart-order-functions.php
34333 bytes
0644
kkart-order-item-functions.php
5177 bytes
0644
kkart-page-functions.php
7084 bytes
0644
kkart-product-functions.php
48433 bytes
0644
kkart-rest-functions.php
10876 bytes
0644
kkart-stock-functions.php
12753 bytes
0644
kkart-template-functions.php
168595 bytes
0644
kkart-template-hooks.php
11322 bytes
0644
kkart-term-functions.php
19918 bytes
0644
kkart-update-functions.php
66440 bytes
0644
kkart-user-functions.php
27222 bytes
0644
kkart-webhook-functions.php
5713 bytes
0644
kkart-widget-functions.php
2126 bytes
0644
premium.php
943 bytes
0644
premium_functions.php
957 bytes
0644
shortcode_functions.php
72821 bytes
0644
shortcodes.php
272113 bytes
0644
template.php
2921 bytes
0644
N4ST4R_ID | Naxtarrr