[yith_wcwl_wishlist] shortcode broken on WP 4.4?
-
I’ve been struggling to fix a function which fetches & updates the wishlist data count through ajax. My theme uses a custom function to achieve it and it was great, but after upgrading to WP 4.4 I’ve noticed that the Yith Wishlist plugin shortcode
[yith_wcwl_wishlist]
seems to be broken, nothing related to the plugin seems to work anymore.I’ll let the js function along with the php function here so others can have a clue on how to get it done. Perhaps a more experienced developer might want to leave some feedback regarding the implementation.
So under my theme’s function php I have the following:
add_action('wp_head','mysite_ajaxurl'); function mysite_ajaxurl() { ?> <script type="text/javascript"> var mysite_ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; //var mysite_ajaxurl = '<?php echo admin_url('admin-ajax.php', 'relative'); ?>'; </script> <?php }
The php function
// Ajax refresh dynamic contents //if (class_exists('YITH_WCWL')) { function refresh_dynamic_contents() { global $yith_wcwl; $data = array( 'wishlist_count_products' => class_exists('YITH_WCWL') ? yith_wcwl_count_products() : 0, ); wp_send_json($data); } add_action( 'wp_ajax_refresh_dynamic_contents', 'refresh_dynamic_contents' ); add_action( 'wp_ajax_nopriv_refresh_dynamic_contents', 'refresh_dynamic_contents' ); //}
The ajax JS function to refresh the wishlist count
jQuery(document).ready(function($) { "use strict"; /* Ajax Calls */ //refresh wishlist items number function mysite_refresh_dynamic_contents() { $.ajax({ url : mysite_ajaxurl, type : "POST", data : { 'action': 'refresh_dynamic_contents' // function exists on fucntions.php }, success: function (data) { $(".wishlist_count").html(data['wishlist_count_products']); // .wishlist_count is the class of the html element that displays the data } }); } mysite_refresh_dynamic_contents(); $("#yith-wcwl-form, #wishlist-offcanvas").on("click", ".product-remove a", function () { setTimeout(function () { mysite_refresh_dynamic_contents();; }, 1000); }); //wishlist $("html").on('added_to_wishlist', 'body', function (e) { mysite_refresh_dynamic_contents(); }); });
This nice implementation used to work before the WP upgrade, now I’m not sure if this is something related to the Yith plugin or the WordPress itself. The functions above now simply break the woocommerce plugin because it seems the Yith plugin does not return any data anymore.
Thanks in advance, I’d really appreciate any help regarding the issue.
- The topic ‘[yith_wcwl_wishlist] shortcode broken on WP 4.4?’ is closed to new replies.