Created
July 4, 2017 06:42
-
-
Save bhavik-kiri/6f29c152f8a4992d764a0df2f6bcda0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the cart data from the PHP session and store it in class variables. | |
*/ | |
public function get_cart_from_session() { | |
// Load cart session data from session | |
foreach ( $this->cart_session_data as $key => $default ) { | |
$this->$key = WC()->session->get( $key, $default ); | |
} | |
$update_cart_session = false; | |
$this->removed_cart_contents = array_filter( WC()->session->get( 'removed_cart_contents', array() ) ); | |
$this->applied_coupons = array_filter( WC()->session->get( 'applied_coupons', array() ) ); | |
/** | |
* Load the cart object. This defaults to the persistent cart if null. | |
*/ | |
$cart = WC()->session->get( 'cart', null ); | |
if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart', true ) ) ) { | |
$cart = $saved_cart['cart']; | |
$update_cart_session = true; | |
} elseif ( is_null( $cart ) ) { | |
$cart = array(); | |
} | |
/* rest of code */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment