function commerce_wishlist_product_remove_line_item in Commerce Wishlist 7.3
Removes a product from a user's wish list.
If no wishlist is provided, it will grab the default wish list using commerce_wishlist_order_load(). If no account is provided, it will default to the logged in user.
Parameters
object $line_item: The product (line_item) to remove.
object|null $account: The user object of the owner of the wish list.
object|null $wishlist: The wishlist to remove the product from.
2 calls to commerce_wishlist_product_remove_line_item()
- commerce_wishlist_product_remove_ajax in ./
commerce_wishlist.module - Ajax callback to handle deletion of wish list item.
- commerce_wishlist_product_remove_page in ./
commerce_wishlist.module - Page callback: handle deletion of a wish list item.
File
- ./
commerce_wishlist.module, line 1089 - Provides a wish list for use in Drupal Commerce.
Code
function commerce_wishlist_product_remove_line_item($line_item, $account = NULL, $wishlist = NULL) {
if ($account === NULL) {
global $user;
$account = $user;
}
if ($account->uid === 0) {
return;
}
if ($wishlist === NULL) {
// Get the default wish list.
$wishlist = commerce_wishlist_order_load($account->uid);
}
if ($line_item->order_id != $wishlist->order_id) {
return;
}
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
rules_invoke_all('commerce_wishlist_product_remove', $line_item_wrapper->commerce_product
->value(), $account, $wishlist);
// Remove the line item from the line item reference field.
commerce_entity_reference_delete($wishlist, 'commerce_line_items', 'line_item_id', $line_item->line_item_id);
commerce_line_item_delete($line_item->line_item_id);
commerce_order_save($wishlist);
}