Created
July 22, 2020 13:41
-
-
Save autocircled/0d1fde2f1f27c6b53bbd4647953b1de9 to your computer and use it in GitHub Desktop.
Replace old codes with this javascript codes to wp-content/plugins/favorite-plugin/assets/script.js Only line no. 31 has been added in this file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
$(document).on('click', '.wpt-favorite-button', function(){ | |
var $this = $(this); | |
var product_id = $(this).data('product_id'); | |
var user_id = $(this).data('user_id'); | |
var status = $(this).attr('data-status'); | |
$('.message-favorite-button-' + product_id).html("Loading..."); | |
$.ajax({ | |
type: 'POST', | |
url: myAjax.ajaxurl,// + get_data, | |
data: { | |
action: 'favorite_user_meta_update', | |
product_id: product_id, | |
user_id: user_id, | |
status: status, | |
}, | |
complete: function(){ | |
}, | |
success: function(data) { | |
if(data !== 'success'){ | |
$('.message-favorite-button-' + product_id).html(data); | |
return; | |
} | |
if('liked' === status){ | |
$('.message-favorite-button-' + product_id).html("Unliked"); | |
$('.favorite-button-' + product_id).removeClass('favorite-button-liked'); | |
$('.favorite-button-' + product_id).addClass('favorite-button-no-like'); | |
$('.favorite-button-' + product_id).attr('data-status','no-like'); | |
$this.parents('.fav_table_list tr#product_id_' + product_id).hide(); // added this line only to hide product rows | |
}else{ | |
$('.message-favorite-button-' + product_id).html("Liked"); | |
$('.favorite-button-' + product_id).removeClass('favorite-button-no-like'); | |
$('.favorite-button-' + product_id).addClass('favorite-button-liked'); | |
$('.favorite-button-' + product_id).attr('data-status','liked'); | |
} | |
}, | |
error: function() { | |
}, | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment