diff --git a/inc/cart/class-lp-cart.php b/inc/cart/class-lp-cart.php index c427497e4..522af8233 100644 --- a/inc/cart/class-lp-cart.php +++ b/inc/cart/class-lp-cart.php @@ -203,24 +203,25 @@ public function add_to_cart( int $item_id = 0, int $quantity = 1, array $item_da /** * Remove an item from cart * - * @param $item_id + * @param $cart_id * * @return bool */ - public function remove_item( $item_id ) { - if ( isset( $this->_cart_content['items'][ $item_id ] ) ) { + public function remove_item( $cart_id ) { + + if ( isset( $this->_cart_content[ $cart_id ] ) ) { + + do_action( 'learn_press_remove_cart_item', $cart_id, $this ); - do_action( 'learn_press_remove_cart_item', $item_id, $this ); + unset( $this->_cart_content[$cart_id] ); - unset( $this->_cart_content['items'][ $item_id ] ); - - do_action( 'learn_press_cart_item_removed', $item_id, $this ); + do_action( 'learn_press_cart_item_removed', $cart_id, $this ); $this->update_session( $this->_cart_content ); return true; } - + return false; } diff --git a/inc/class-lp-session-handler.php b/inc/class-lp-session-handler.php index 6c2f89bae..e38eb65ba 100644 --- a/inc/class-lp-session-handler.php +++ b/inc/class-lp-session-handler.php @@ -383,6 +383,11 @@ public function get( string $key, $default = null ) { * @param bool $force_change */ public function set( string $key, $value, bool $force_change = false ) { + // if customer id is not set then run $this->init() once. It is necessary when this function is invoked while doing ajax. While doing ajax $this->_customer_id is always '' + if (strlen( $this->_customer_id ) ===0 ) { + $this->init(); + } + $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); if ( $force_change ) { diff --git a/inc/user/abstract-lp-user.php b/inc/user/abstract-lp-user.php index 72201a5f8..980490a6e 100644 --- a/inc/user/abstract-lp-user.php +++ b/inc/user/abstract-lp-user.php @@ -1236,8 +1236,8 @@ public function get_upload_profile_src( $size = '' ) { * * @return false|string */ - public function get_profile_picture( $type = '', $size = 96, $src_only = false ) { - return LP_Profile::instance( $this->get_id() )->get_profile_picture( $type, $size ); + public function get_profile_picture( $src_only = false, $type = '', $size = 96 ) { + return LP_Profile::instance( $this->get_id() )->get_profile_picture( $src_only, $type, $size ); } /** diff --git a/inc/user/class-lp-profile.php b/inc/user/class-lp-profile.php index 60769a557..d3c6dea0b 100644 --- a/inc/user/class-lp-profile.php +++ b/inc/user/class-lp-profile.php @@ -892,7 +892,7 @@ public function get_upload_profile_src( $size = '' ) { * * @return string */ - public function get_profile_picture( $type = '', $size = 96 ): string { + public function get_profile_picture($src_only = false, $type = '', $size = 96 ): string { $avatar = ''; try { @@ -915,18 +915,24 @@ public function get_profile_picture( $type = '', $size = 96 ): string { } } - $avatar = apply_filters( - 'learn-press/user-profile/avatar', - sprintf( - '%s', - esc_attr__( 'User Avatar', 'learnpress' ), + if ( $src_only ) { + $avatar = $avatar_url; + } + + else { + $avatar = apply_filters( + 'learn-press/user-profile/avatar', + sprintf( + '%s', + esc_attr__( 'User Avatar', 'learnpress' ), + $avatar_url, + $args['width'] ?? 96, + $args['height'] ?? 96 + ), $avatar_url, - $args['width'] ?? 96, - $args['height'] ?? 96 - ), - $avatar_url, - $args - ); + $args + ); + } } catch ( Throwable $e ) { error_log( $e->getMessage() ); }