Skip to content

Commit

Permalink
Prevent infinite recursion by calling get_cart_from_session once
Browse files Browse the repository at this point in the history
Closes woocommerce#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.
  • Loading branch information
mikejolley committed Apr 9, 2015
1 parent 0cff7e5 commit 1f3365f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion includes/class-wc-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,11 @@ public function get_undo_url( $cart_item_key ) {
*/
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 );
}

Expand Down

0 comments on commit 1f3365f

Please sign in to comment.