Created
April 30, 2019 18:12
-
-
Save manchumahara/bcdb7bd4f4e2f1c6f9744da16cbb8d24 to your computer and use it in GitHub Desktop.
WC()->cart null or such error fix for wc 3.6.0 or higher
This file contains 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
if ( version_compare( WC_VERSION, '3.6.0', '>=' )) { | |
require_once( WC_ABSPATH . 'includes/wc-cart-functions.php' ); | |
require_once( WC_ABSPATH . 'includes/wc-notice-functions.php' ); | |
if ( null === WC()->session ) { | |
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' ); | |
// Prefix session class with global namespace if not already namespaced | |
if ( false === strpos( $session_class, '\\' ) ) { | |
$session_class = '\\' . $session_class; | |
} | |
WC()->session = new $session_class(); | |
WC()->session->init(); | |
} | |
/** | |
* For logged in customers, pull data from their account rather than the | |
* session which may contain incomplete data. | |
*/ | |
if ( null === WC()->customer ) { | |
if ( is_user_logged_in() ) { | |
WC()->customer = new WC_Customer( get_current_user_id() ); | |
} else { | |
WC()->customer = new WC_Customer( get_current_user_id(), true ); | |
} | |
} | |
// Load Cart. | |
if ( null === WC()->cart ) { | |
WC()->cart = new WC_Cart(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment