{"id":122843,"date":"2021-01-03T04:27:10","date_gmt":"2021-01-03T04:27:10","guid":{"rendered":"https:\/\/phppot.com\/?p=12293"},"modified":"2021-01-03T04:27:10","modified_gmt":"2021-01-03T04:27:10","slug":"better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2021\/01\/03\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/","title":{"rendered":"Better Customer Engagement with eCommerce wishlist implementation for shopping cart"},"content":{"rendered":"<p>Last modified on January 5th, 2021.<\/p>\n<p>Increase user engagement with your eCommerce website to see your sales leap forward. There are multiple tools like rating, comments, queries, and wishlist to increase user engagement.<\/p>\n<p>A persistent shopping cart (over different user sessions) allows user\u2019s to store and earmark products for future purchase. A wishlist helps to do that in a better organized way.<\/p>\n<p>A wishlist is an eCommerce website feature that helps the users to manage list of products that the user wants to purchase later. It also allows maintaining a \u201cyet to purchase\u201d list of items. This feature will increase your eCommerce business conversion rate.<\/p>\n<p>The eCommerce application providers follow types of mechanisms to implement this feature. The terminology may differ from application to application. Example: Save for future, wishlist, favorites and more.<\/p>\n<p>This example uses a simple way of implementation with a straight-forward code. It user database to manage users wishlist.<\/p>\n<p>You can integrate the wishlist module of this example for your online shopping cart software.<\/p>\n<h2><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-12297\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-wishlist-screenshot-550x314.jpg\" alt=\"eCommerce Wishlist Screenshot\" width=\"550\" height=\"314\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-wishlist-screenshot-550x314.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-wishlist-screenshot-300x171.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-wishlist-screenshot.jpg 600w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/h2>\n<h2>What is inside?<\/h2>\n<ol>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#about-this-example\">About this example<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#file-structure\">File structure<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#ecommerce-wishlist-view-in-html\">eCommerce wishlist view in HTML<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#jquery-ajax-to-add-remove-wishlist-items\">jQuery AJAX to add\/remove wishlist items<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#php-code-to-create-and-manage-ecommerce-wishlist\">PHP code to create and manage eCommerce wishlist<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#database-script\">Database script<\/a><\/li>\n<li><a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#e-commerce-wishlist-example-output\">E-Commerce wishlist example output<\/a><\/li>\n<\/ol>\n<h2 id=\"about-this-example\">About this example<\/h2>\n<p>This example code is with the feature to create users\u2019 wishlist for eCommerce software. It will give a clean and simple code to add the eCommerce wishlist feature.<\/p>\n<p>I have created a <a href=\"https:\/\/phppot.com\/php\/simple-php-shopping-cart\/\">simple php shopping cart script<\/a> before in a previous tutorial. This example is an enhanced version of the simple shopping cart with a wishlist.<\/p>\n<p>This code will allow users to add products to their wishlist from the product gallery. Also, it allows to unset an item to remove from the wishlist.<\/p>\n<p>The wishlist gallery items are dynamic from the database. The add\/remove actions will change the wishlist data in the database.<\/p>\n<h2 id=\"file-structure\">File Structure<\/h2>\n<p>This diagram shows the files created for this example. It has an organized structured code of eCommerce wishlist implementation.<\/p>\n<p>It shows the view files, libraries and application assets separated in a proper manner.<\/p>\n<p>The image folder contains application icons. Also, it includes images to display the product and wishlist gallery.<\/p>\n<p>This tutorial has a downloadable source at the end with the database script.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-12321\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/wishlist-file-structure.jpg\" alt=\"Wishlist File Structure\" width=\"257\" height=\"408\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/wishlist-file-structure.jpg 257w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/wishlist-file-structure-189x300.jpg 189w\" sizes=\"auto, (max-width: 257px) 100vw, 257px\"><\/p>\n<h2 id=\"ecommerce-wishlist-view-in-html\">eCommerce wishlist view in HTML<\/h2>\n<p>This example has two types of galleries. One is a <a href=\"https:\/\/phppot.com\/php\/top-10-factors-in-ecommerce-shopping-cart-software-gallery-design\/\">regular eCommerce product gallery<\/a> and the other is a users\u2019 wishlist gallery.<\/p>\n<p>This example uses a hard-coded member id to get the users\u2019 wishlist from the database. It may adopt a <a href=\"https:\/\/phppot.com\/php\/php-login-script-with-session\/\">login module to get the id from the session<\/a>.<\/p>\n<p>The product gallery is on the landing page, below the shopping cart list view. This page includes the navigation link to go to the eCommerce application wishlist.<\/p>\n<p>The product gallery has the line heart icon in each tile. It will add the items to the wishlist on its click event. After adding, the wishlist gallery shows the filled heart on the particular tile.<\/p>\n<p>The filled heart icon on-click event will remove the items from the wishlist.<\/p>\n<p class=\"code-heading\">index.php<\/p>\n<pre class=\"prettyprint lang-php\">&lt;?php\nsession_start();\nrequire_once __DIR__ . \"\/lib\/DataSource.php\";\n$db_handle = new DataSource(); $query = 'SELECT * FROM tbl_whish_list JOIN tblproduct ON tblproduct.id = tbl_whish_list.product_id ORDER BY tbl_whish_list.product_id ASC'; $whish_array = $db_handle-&gt;select($query);\n$whish_array_pid = array();\nif (! empty($whish_array)) { foreach ($whish_array as $z =&gt; $value) { $whish_array_pid[] = $whish_array[$z]['product_id']; }\n}\nif (! empty($_GET[\"action\"])) { switch ($_GET[\"action\"]) { case \"add\": if (! empty($_POST[\"quantity\"])) { $query = 'SELECT * FROM tblproduct WHERE code= ? '; $paramType = 's'; $paramValue = array( $_GET[\"code\"] ); $productByCode = $db_handle-&gt;select($query, $paramType, $paramValue); $itemArray = array( $productByCode[0][\"code\"] =&gt; array( 'name' =&gt; $productByCode[0][\"name\"], 'code' =&gt; $productByCode[0][\"code\"], 'quantity' =&gt; $_POST[\"quantity\"], 'price' =&gt; $productByCode[0][\"price\"], 'image' =&gt; $productByCode[0][\"image\"] ) ); if (! empty($_SESSION[\"cart_item\"])) { if (in_array($productByCode[0][\"code\"], array_keys($_SESSION[\"cart_item\"]))) { foreach ($_SESSION[\"cart_item\"] as $k =&gt; $v) { if ($productByCode[0][\"code\"] == $k) { if (empty($_SESSION[\"cart_item\"][$k][\"quantity\"])) { $_SESSION[\"cart_item\"][$k][\"quantity\"] = 0; } $_SESSION[\"cart_item\"][$k][\"quantity\"] += $_POST[\"quantity\"]; } } } else { $_SESSION[\"cart_item\"] = array_merge($_SESSION[\"cart_item\"], $itemArray); } } else { $_SESSION[\"cart_item\"] = $itemArray; } } break; case \"remove\": if (! empty($_SESSION[\"cart_item\"])) { foreach ($_SESSION[\"cart_item\"] as $k =&gt; $v) { if ($_GET[\"code\"] == $k) unset($_SESSION[\"cart_item\"][$k]); if (empty($_SESSION[\"cart_item\"])) unset($_SESSION[\"cart_item\"]); } } break; case \"empty\": unset($_SESSION[\"cart_item\"]); break; }\n}\n?&gt;\n&lt;HTML&gt;\n&lt;HEAD&gt;\n&lt;TITLE&gt;Simple PHP Shopping Cart&lt;\/TITLE&gt;\n&lt;link href=\"css\/style.css\" type=\"text\/css\" rel=\"stylesheet\" \/&gt;\n&lt;\/HEAD&gt;\n&lt;BODY&gt; &lt;div id=\"shopping-cart\"&gt; &lt;div class=\"txt-heading\"&gt;Shopping Cart&lt;\/div&gt; &lt;a id=\"btnEmpty\" href=\"index.php?action=empty\"&gt;Empty Cart&lt;\/a&gt;\n&lt;?php\nif (isset($_SESSION[\"cart_item\"])) { $total_quantity = 0; $total_price = 0; ?&gt;\n&lt;table class=\"tbl-cart\" cellpadding=\"10\" cellspacing=\"1\"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th class=\"text-left\"&gt;Name&lt;\/th&gt; &lt;th class=\"text-left\"&gt;Code&lt;\/th&gt; &lt;th class=\"text-right\"&gt;Quantity&lt;\/th&gt; &lt;th class=\"text-right\"&gt;Unit Price&lt;\/th&gt; &lt;th class=\"text-right\"&gt;Price&lt;\/th&gt; &lt;th class=\"text-center\"&gt;Remove&lt;\/th&gt; &lt;\/tr&gt;\n&lt;?php foreach ($_SESSION[\"cart_item\"] as $item) { $item_price = $item[\"quantity\"] * $item[\"price\"]; ?&gt; &lt;tr&gt; &lt;td&gt;&lt;img src=\"&lt;?php echo $item[\"image\"]; ?&gt;\" class=\"cart-item-image\" \/&gt;&lt;?php echo $item[\"name\"]; ?&gt;&lt;\/td&gt; &lt;td&gt;&lt;?php echo $item[\"code\"]; ?&gt;&lt;\/td&gt; &lt;td class=\"text-right\"&gt;&lt;?php echo $item[\"quantity\"]; ?&gt;&lt;\/td&gt; &lt;td class=\"text-right\"&gt;&lt;?php echo \"$ \".$item[\"price\"]; ?&gt;&lt;\/td&gt; &lt;td class=\"text-right\"&gt;&lt;?php echo \"$ \". number_format($item_price,2); ?&gt;&lt;\/td&gt; &lt;td class=\"text-center\"&gt;&lt;a href=\"index.php?action=remove&amp;code=&lt;?php echo $item[\"code\"]; ?&gt;\" class=\"btnRemoveAction\"&gt;&lt;img src=\"images\/icon-delete.png\" alt=\"Remove Item\" \/&gt;&lt;\/a&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;?php $total_quantity += $item[\"quantity\"]; $total_price += ($item[\"price\"] * $item[\"quantity\"]); } ?&gt; &lt;tr&gt; &lt;td colspan=\"2\" align=\"right\"&gt;Total:&lt;\/td&gt; &lt;td align=\"right\"&gt;&lt;?php echo $total_quantity; ?&gt;&lt;\/td&gt; &lt;td align=\"right\" colspan=\"2\"&gt;&lt;strong&gt;&lt;?php echo \"$ \".number_format($total_price, 2); ?&gt;&lt;\/strong&gt;&lt;\/td&gt; &lt;td&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;\/tbody&gt; &lt;\/table&gt; &lt;?php\n} else { ?&gt;\n&lt;div class=\"no-records\"&gt;Your Cart is Empty&lt;\/div&gt;\n&lt;?php\n}\n?&gt;\n&lt;\/div&gt; &lt;div id=\"product-grid\"&gt; &lt;div class=\"txt-heading\"&gt;Products&lt;\/div&gt; &lt;?php\n$query = 'SELECT * FROM tblproduct ORDER BY id ASC';\n$product_array = $db_handle-&gt;select($query);\nif (! empty($product_array)) { foreach ($product_array as $key =&gt; $value) { ?&gt; &lt;div class=\"product-item\"&gt; &lt;form method=\"post\" action=\"index.php?action=add&amp;code=&lt;?php echo $product_array[$key][\"code\"]; ?&gt;\"&gt; &lt;div class=\"product-image\"&gt; &lt;img src=\"&lt;?php echo $product_array[$key][\"image\"]; ?&gt;\"&gt; &lt;\/div&gt; &lt;div class=\"product-tile-footer\"&gt; &lt;div class=\"product-title\"&gt;&lt;?php echo $product_array[$key][\"name\"]; ?&gt; &lt;?php if (in_array($product_array[$key][\"id\"], $whish_array_pid)) { ?&gt; &lt;span data-pid=\"&lt;?php echo $product_array[$key][\"id\"]; ?&gt;\" class=\"heart\" onclick=\"removeFromWishlist(this)\" title=\"Remove from wishlist\"&gt; &lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-line join=\"round\" stroke=\"currentColor\" class=\"feather feather-heart color-filled\"&gt; &lt;path d=\"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z\"&gt;&lt;\/path&gt;&lt;\/svg&gt;&lt;img src=\"images\/loading.gif\" id=\"loader\"&gt; &lt;\/span&gt; &lt;?php } else { ?&gt; &lt;span data-pid=\"&lt;?php echo $product_array[$key][\"id\"]; ?&gt;\" class=\"heart\" onclick=\"addToWishlist(this)\" title=\"Add to wishlist\"&gt; &lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-line join=\"round\" stroke=\"currentColor\" class=\"feather feather-heart\"&gt; &lt;path d=\"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z\"&gt;&lt;\/path&gt;&lt;\/svg&gt;&lt;img src=\"images\/loading.gif\" id=\"loader\"&gt; &lt;\/span&gt; &lt;?php } ?&gt; &lt;\/div&gt; &lt;div class=\"product-price\"&gt;&lt;?php echo \"\nquot;.$product_array[$key][\"price\"]; ?&gt;&lt;\/div&gt; &lt;div class=\"cart-action\"&gt; &lt;input type=\"text\" class=\"product-quantity\" name=\"quantity\" value=\"1\" size=\"2\" \/&gt;&lt;input type=\"submit\" value=\"Add to Cart\" class=\"btnAddAction\" \/&gt; &lt;\/div&gt; &lt;\/div&gt; &lt;\/form&gt; &lt;\/div&gt; &lt;?php }\n}\n?&gt; &lt;\/div&gt; &lt;div id=\"shopping-cart\"&gt; &lt;a id=\"whishlist\" href=\"wishlist.php\"&gt;Show My Wishlist&lt;\/a&gt; &lt;\/div&gt; &lt;script type=\"text\/javascript\" src=\"vendor\/jquery-3.4.1.min.js\"&gt;&lt;\/script&gt; &lt;script type=\"text\/javascript\" src=\"js\/wishlist.js\"&gt;&lt;\/script&gt;\n&lt;\/BODY&gt;\n&lt;\/HTML&gt;<\/pre>\n<p class=\"code-heading\">wishlist.php<\/p>\n<pre class=\"prettyprint lang-php\">&lt;?php\nrequire_once __DIR__ . \"\/lib\/DataSource.php\";\n$db = new DataSource();\n?&gt;\n&lt;HTML&gt;\n&lt;HEAD&gt;\n&lt;TITLE&gt;Simple PHP Shopping Cart&lt;\/TITLE&gt;\n&lt;link href=\"css\/style.css\" type=\"text\/css\" rel=\"stylesheet\" \/&gt;\n&lt;\/HEAD&gt;\n&lt;BODY&gt; &lt;div id=\"shopping-cart\"&gt; &lt;div class=\"whishlist-cntr\"&gt; &lt;div class=\"txt-heading\"&gt;Wishlist&lt;\/div&gt; &lt;div id=\"whishlist-grid\"&gt; &lt;?php $query = 'SELECT * FROM tbl_whish_list JOIN tblproduct ON tblproduct.id = tbl_whish_list.product_id'; $whish_array = $db-&gt;select($query); if (! empty($whish_array)) { foreach ($whish_array as $key =&gt; $value) { ?&gt; &lt;div class=\"product-item\"&gt; &lt;form method=\"post\" action=\"index.php?action=add&amp;code=&lt;?php echo $whish_array[$key][\"code\"]; ?&gt;\"&gt; &lt;div class=\"product-image\"&gt; &lt;img src=\"&lt;?php echo $whish_array[$key][\"image\"]; ?&gt;\"&gt; &lt;\/div&gt; &lt;div class=\"product-tile-footer\"&gt; &lt;div class=\"product-title\"&gt;&lt;?php echo $whish_array[$key][\"name\"]; ?&gt; &lt;span data-pid=\"&lt;?php echo $whish_array[$key][\"product_id\"]; ?&gt;\" class=\"heart\" onclick=\"removeFromWishlist(this)\" title=\"Add to wish list\"&gt; &lt;svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-line join=\"round\" stroke=\"currentColor\" class=\"feather feather-heart color-filled\"&gt; &lt;path d=\"M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z\"&gt;&lt;\/path&gt;&lt;\/svg&gt; &lt;img src=\"images\/loading.gif\" id=\"loader\"&gt; &lt;\/span&gt; &lt;\/div&gt; &lt;div class=\"product-price\"&gt;&lt;?php echo \"\nquot;.$whish_array[$key][\"price\"]; ?&gt;&lt;\/div&gt; &lt;div class=\"cart-action\"&gt; &lt;input type=\"text\" class=\"product-quantity\" name=\"quantity\" value=\"1\" size=\"2\" \/&gt;&lt;input type=\"submit\" value=\"Add to Cart\" class=\"btnAddAction\" \/&gt; &lt;\/div&gt; &lt;\/div&gt; &lt;\/form&gt; &lt;\/div&gt; &lt;?php }\n}\n?&gt;\n&lt;\/div&gt; &lt;\/div&gt; &lt;\/div&gt; &lt;script type=\"text\/javascript\" src=\"vendor\/jquery-3.4.1.min.js\"&gt;&lt;\/script&gt; &lt;script type=\"text\/javascript\" src=\"js\/wishlist.js\"&gt;&lt;\/script&gt;\n&lt;\/BODY&gt;\n&lt;\/HTML&gt;<\/pre>\n<h2 id=\"jquery-ajax-to-add-remove-wishlist-items\">jQuery AJAX to add \/ remove wishlist items<\/h2>\n<p>This JavaScript file contains the functions to process the AJAX request to add\/remove wishlist items.<\/p>\n<p>The&nbsp;<em>addToWishList()<\/em> function gets the product id from the HTML data attribute. This id is a request param to perform the add action in the server.<\/p>\n<p>Similarly, the <em>removeFromWishlist()<\/em> function calls the server URL to execute the delete query on the wishlist database.<\/p>\n<p>Both the AJAX functions manipulate UI elements to give a seamless and very good user experience on these actions.<\/p>\n<p>js\/wishlist.js<\/p>\n<pre class=\"prettyprint lang-php\">function addToWishlist(obj) { var p_id = $(obj).data(\"pid\"); $(obj).find(\"svg\").hide(); $(obj).find(\"img\").show(); $.ajax({ url : \"ajax-endpoint\/add-to-wishlist.php\", type : \"POST\", data : 'p_id=' + p_id, success : function(data) { $(obj).find(\"svg\").show(); $(obj).find(\"img\").hide(); if (data &gt; 0) { markedAsChecked($(obj)); } } });\n} function removeFromWishlist(obj) { var p_id = $(obj).data(\"pid\"); $(obj).find(\"svg\").hide(); $(obj).find(\"img\").show(); $.ajax({ url : \"ajax-endpoint\/remove-from-wishlist.php\", type : \"POST\", data : 'p_id=' + p_id, success : function(data) { if (data &gt; 0) { $(obj).find(\"svg\").show(); $(obj).find(\"img\").hide(); markedAsUnchecked($(obj)); } } });\n} function markedAsChecked(obj) { $(obj).find(\"svg\").addClass(\"color-filled\"); $(obj).find(\"svg\").parent().attr(\"onClick\", \"removeFromWishlist(this)\"); $(obj).find(\"svg\").parent().attr(\"title\", \"Remove from wishlist\")\n} function markedAsUnchecked(obj) { $(obj).find(\"svg\").removeClass(\"color-filled\"); $(obj).find(\"svg\").parent().attr(\"onClick\", \"addToWishlist(this)\"); $(obj).find(\"svg\").parent().attr(\"title\", \"Add to wishlist\")\n}\n<\/pre>\n<h2 id=\"php-code-to-create-and-manage-ecommerce-wishlist\">PHP code to create and manage wishlist<\/h2>\n<p>This section shows the code to move product to or from the eCommerce wishlist.<\/p>\n<p>On clicking the heart icon in the product gallery, the AJAX will call this PHP. This file inserts the selected item to the users\u2019 eCommerce wishlist.<\/p>\n<p>ajax-endpoint\/add-to-wishlist.php<\/p>\n<pre class=\"prettyprint lang-php\">&lt;?php\nrequire_once __DIR__ . \"\/..\/lib\/DataSource.php\";\n$db_handle = new DataSource();\nif (! empty($_POST[\"p_id\"])) { $memberId = 1; $sql = \"INSERT INTO tbl_whish_list (product_id, member_id) VALUES (?, ?)\"; $paramType = 'ii'; $paramValue = array( $_POST[\"p_id\"], $memberId ); $whishlist_id = $db_handle-&gt;insert($sql, $paramType, $paramValue); echo $whishlist_id; exit();\n}\n?&gt;\n<\/pre>\n<p>On clicking the filled heart icon, it calls the following PHP file. It receives the product id from the request param array.<\/p>\n<p>Based on the product_id it prepares the delete query to remove the item from the user\u2019s wishlist.<\/p>\n<p class=\"code-heading\">ajax-endpoint\/remove-from-wishlist.php<\/p>\n<pre class=\"prettyprint lang-php\">&lt;?php\nrequire_once __DIR__ . \"\/..\/lib\/DataSource.php\";\n$db_handle = new DataSource();\nif (! empty($_POST[\"p_id\"])) { $memberId = 1; $query = \"DELETE FROM tbl_whish_list WHERE product_id = ? AND member_id = ?\"; $paramType = 'ii'; $paramValue = array( $_POST[\"p_id\"], $memberId ); $affectedRows = $db_handle-&gt;delete($query, $paramType, $paramValue); echo $affectedRows;\n}\nexit();\n<\/pre>\n<h2 id=\"database-script\">Database script<\/h2>\n<p>Import this database script to run this example in your server. It has the tables to manage shopping cart products, wishlist in the database.<\/p>\n<pre class=\"prettyprint lang-php\">--\n-- Database: `ecommerce-wishlist`\n-- -- -------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tblproduct` (\n`id` int(8) NOT NULL, `name` varchar(255) NOT NULL, `code` varchar(255) NOT NULL, `image` text NOT NULL, `price` double(10,2) NOT NULL\n) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; INSERT INTO `tblproduct` (`id`, `name`, `code`, `image`, `price`) VALUES\n(1, 'FinePix Pro2 3D Camera', '3DcAM01', 'images\/camera.jpg', 1500.00),\n(2, 'EXP Portable Hard Drive', 'USB02', 'images\/external-hard-drive.jpg', 800.00),\n(3, 'Luxury Ultra thin Wrist Watch', 'wristWear03', 'images\/watch.jpg', 300.00),\n(4, 'XP 1155 Intel Core Laptop', 'LPN45', 'images\/laptop.jpg', 800.00); -- -------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tbl_whish_list` (\n`id` int(11) NOT NULL, `member_id` int(11) NOT NULL, `product_id` int(11) NOT NULL\n) ENGINE=InnoDB AUTO_INCREMENT=111 DEFAULT CHARSET=latin1; INSERT INTO `tbl_whish_list` (`id`, `member_id`, `product_id`) VALUES\n(110, 0, 1); ALTER TABLE `tblproduct` ADD PRIMARY KEY (`id`), ADD UNIQUE KEY `product_code` (`code`); ALTER TABLE `tbl_whish_list` ADD PRIMARY KEY (`id`); ALTER TABLE `tblproduct`\nMODIFY `id` int(8) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5; ALTER TABLE `tbl_whish_list`\nMODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=111; <\/pre>\n<h2 id=\"e-commerce-wishlist-example-output\">E-Commerce shopping cart wishlist example output<\/h2>\n<p>This screenshot shows the eCommerce product gallery below the shopping cart.<\/p>\n<p>Each item in this gallery contains a clickable heart icon to move the item to\/from the wishlist.<\/p>\n<p>Items with the filled heart denote that they are on the users\u2019 wishlist.<\/p>\n<p><a href=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-12299 size-large\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery-550x295.jpg\" alt=\"eCommerce with wishlist gallery\" width=\"550\" height=\"295\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery-550x295.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery-300x161.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery-768x412.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2021\/01\/ecommerce-with-wishlist-gallery.jpg 1200w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>Thus, we have seen a simple example for creating an eCommerce wishlist for customers.<\/p>\n<p>I hope, it helps you to build a module to support your shopping cart to have this feature to increase the conversion rate.<\/p>\n<p>With straight forward PHP, MySQL code with AJAX, we have seen a reasonably good implementation for getting started.<\/p>\n<p>Since it is with core PHP without any libraries, it is easily adaptable to any eCommerce framework.<\/p>\n<p><a class=\"download\" href=\"https:\/\/phppot.com\/downloads\/shopping-cart-wishlist.zip\">Download<\/a><\/p>\n<p> <!-- #comments --> <\/p>\n<div class=\"related-articles\">\n<h2>Popular Articles<\/h2>\n<\/p><\/div>\n<p> <a href=\"https:\/\/phppot.com\/php\/better-customer-engagement-with-ecommerce-wishlist-implementation-for-shopping-cart\/#top\" class=\"top\">\u2191 Back to Top<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last modified on January 5th, 2021. Increase user engagement with your eCommerce website to see your sales leap forward. There are multiple tools like rating, comments, queries, and wishlist to increase user engagement. A persistent shopping cart (over different user sessions) allows user\u2019s to store and earmark products for future purchase. A wishlist helps to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":122844,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[],"class_list":["post-122843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-updates"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/122843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=122843"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/122843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/122844"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=122843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=122843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=122843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}