PHP Classes

File: assets/js/ade-wishlist.js

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Ade Simple WooCommerce Wishlist plugin   assets/js/ade-wishlist.js   Download  
File: assets/js/ade-wishlist.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Ade Simple WooCommerce Wishlist plugin
Plugin to add wishlists to WooCommerce sites
Author: By
Last change:
Date: 1 year ago
Size: 3,502 bytes
 

Contents

Class file image Download
jQuery(document).ready(function ($) { //add to wishlist $(".ade-wishlist-icon").each(function (index, element) { $(this).click(function (e) { e.preventDefault(); var product_id = $(this).attr("data-product-id"); var data_saved = $(this).attr("data-saved"); var button = $(this); var wishlist_nonce = ade_wishlist.nonce; //ajax $.ajax({ url: ade_wishlist.ajax_url, type: "POST", data: { action: "ade_wishlist", product_id, wishlist_nonce }, beforeSend: function () { //swal Swal.fire({ title: "Please wait...", icon: "info", text: data_saved == "true" ? "Removing from wishlist..." : "Adding to wishlist...", allowOutsideClick: false, onOpen: () => { Swal.showLoading(); } }); }, success: function (response) { //success if (response.code == 200) { Swal.fire({ title: "Success", icon: "success", text: response.message, type: "success" }).then(function () { //update wishlist html button.html(response.icon); //update data_saved button.attr("data-saved", response.data_saved); }); } else { Swal.fire({ title: "Error", icon: "error", text: response.message, type: "error" }); } }, error: function (error) { //error Swal.fire({ title: "Error", icon: "error", text: "Something went wrong", type: "error" }); } }); }); }); //remove from wishlist $(".remove-ade-wishlist").each(function (index, element) { $(this).click(function (e) { e.preventDefault(); var product_id = $(this).attr("data-product"); var button = $(this); var wishlist_nonce = ade_wishlist.nonce; //ajax $.ajax({ url: ade_wishlist.ajax_url, type: "POST", data: { action: "ade_wishlist", product_id, wishlist_nonce }, beforeSend: function () { //swal Swal.fire({ title: "Please wait...", icon: "info", text: "Removing from wishlist...", allowOutsideClick: false, onOpen: () => { Swal.showLoading(); } }); }, success: function (response) { //success if (response.code == 200) { Swal.fire({ title: "Success", icon: "success", text: response.message, type: "success" }).then(function () { //reload location.reload(); }); } else { Swal.fire({ title: "Error", icon: "error", text: response.message, type: "error" }); } }, error: function (error) { //error Swal.fire({ title: "Error", icon: "error", text: "Something went wrong", type: "error" }); } }); }); }); });