Skip to content

Update class-lp-cart.php #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions inc/cart/class-lp-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions inc/class-lp-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions inc/user/abstract-lp-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
30 changes: 18 additions & 12 deletions inc/user/class-lp-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -915,18 +915,24 @@ public function get_profile_picture( $type = '', $size = 96 ): string {
}
}

$avatar = apply_filters(
'learn-press/user-profile/avatar',
sprintf(
'<img alt="%s" class="avatar" src="%s" height="%d" width="%d">',
esc_attr__( 'User Avatar', 'learnpress' ),
if ( $src_only ) {
$avatar = $avatar_url;
}

else {
$avatar = apply_filters(
'learn-press/user-profile/avatar',
sprintf(
'<img alt="%s" class="avatar" src="%s" height="%d" width="%d">',
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() );
}
Expand Down