Prevent infinite recursion by calling get_cart_from_session once
Closes #7852 A check was aded to prevent get_cart() usage before wp_loaded so all WC components have a chance to load prior to the cart. This should solve the edge-case recursion bug by first checking if the woocommerce_cart_loaded_from_session action has already run. This is triggered when loading the cart for the first time.
This commit is contained in:
parent
0cff7e57cd
commit
1f3365f206
|
@ -681,9 +681,11 @@ class WC_Cart {
|
|||
*/
|
||||
public function get_cart() {
|
||||
if ( ! did_action( 'wp_loaded' ) ) {
|
||||
$this->get_cart_from_session();
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Get cart should not be called before the wp_loaded action.', 'woocommerce' ), '2.3' );
|
||||
}
|
||||
if ( ! did_action( 'woocommerce_cart_loaded_from_session' ) ) {
|
||||
$this->get_cart_from_session();
|
||||
}
|
||||
return array_filter( (array) $this->cart_contents );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue