Support » Plugin: YITH WooCommerce Wishlist » Get total wishlist via ajax

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi Anthony!

    It will require some code to obtain your goal;

    First of all create a file yith-wcwl-custom.js in your theme root; add this code to the file created

    jQuery( document ).ready( function($){
        var update_wishlist_count = function() {
            $.ajax({
                beforeSend: function () {
    
                },
                complete  : function () {
    
                },
                data      : {
                    action: 'update_wishlist_count'
                },
                success   : function (data) {
                    console.log( data );
                    //do something
                },
    
                url: yith_wcwl_l10n.ajax_url
            });
        };
    
        $('body').on( 'added_to_wishlist removed_from_wishlist', update_wishlist_count );
    } );

    Then append this code at the end of functions.php file of your theme

    function update_wishlist_count(){
        if( function_exists( 'YITH_WCWL' ) ){
            wp_send_json( YITH_WCWL()->count_products() );
        }
    }
    add_action( 'wp_ajax_update_wishlist_count', 'update_wishlist_count' );
    add_action( 'wp_ajax_nopriv_update_wishlist_count', 'update_wishlist_count' );
    
    function enqueue_custom_wishlist_js(){
    	wp_enqueue_script( 'yith-wcwl-custom-js', get_stylesheet_directory_uri() . '/yith-wcwl-custom.js', array( 'jquery' ), false, true );
    }
    add_action( 'wp_enqueue_scripts', 'enqueue_custom_wishlist_js' );

    Now when adding or removing an item from the wishlist, an ajax call should be sent, and the number of product in wishlist will be returned in data param

    Now customize the js code to update your count 🙂

    Please, note that removed_from_wishlist action will be added with 2.0.7 version of the plugin, that will be released soon

    Let me know if this helps
    Have a nice day 🙂

    Thread Starter Anthony Carbon

    (@master-buldog)

    Thank you sir YITHEMES .. this is working perfectly ..

    Plugin Author YITHEMES

    (@yithemes)

    Hi again Anthony!
    Glad to help! Marking this as resolved

    Have a nice day 🙂

    Hello fellow Anthony, Do you mind sharing what you have so others may use the same example you were successful with. I’m trying to do a similar thing. I’m trying to add a simple heart icon in the fix header of the theme I’m using this plugin with, and trying to get it so that when a user add’s something to their wishlist, the number automatically gets indicated in the wishlist icon.

    Thread Starter Anthony Carbon

    (@master-buldog)

    Plugin Author YITHEMES

    (@yithemes)

    Thanks for helping us in sharing our plugin. If you have appreciated our help, please don’t forget to give us a 5-star vote! 😉

    AVOID Anthony Carbon site links.
    They’re full of redirects to scam sites.

    Thanks for the tip!

    I’ve tried the ajax function above but it seems to break the plugin. Chrome developer tools returns an error with a blank index.php file, breaking the woocommerce home page. If I remove the function my woocommerce is perfectly loaded.

    I’ve tried this function after my theme’s custom function to fetch the wishlist count also stopped working. I just can’t see why it is so hard to achieve this functionality.

    Works like a charm!
    Thank you very much (:

    Plugin Author YITHEMES

    (@yithemes)

    Thank to all.

    Have a nice day 🙂

    Get total compare via ajax

    Hi to all..!!

    Same as Whishlist, I wanted to update compare count in header but don’t want to reload the page. I wanted it to show by doing AJAX.
    I am using YITH Plugin for compare and whishlist.

    Please help ASAP..!!

    Plugin Author YITHEMES

    (@yithemes)

    @adriano: Ciao 🙂

    Can you please enable debug on your site, and tell me if some error appear?

    @ktleedham: please, write in the correct forum; we are a team of many developers, and I’m not the right person to ask about compare. Sorry 🙂

    @yiththemes, @ktleedham – Thanks for the feedback! After enabling debug it turned out to be a database error, here’s the error output:

    WordPress database error: [Table ‘mrancho_db.wp_yith_wcwl_lists’ doesn’t exist]
    SELECT l.* FROM wp_yith_wcwl_lists AS l WHERE 1 AND l.user_id = 2 AND l.is_default = 1 ORDER BY ID DESC
    WordPress database error: [Table ‘mrancho_db.wp_yith_wcwl_lists’ doesn’t exist]
    SELECT l.* FROM wp_yith_wcwl_lists AS l WHERE 1 AND l.user_id = 2 AND l.is_default = 1 ORDER BY ID DESC
    WordPress database error: [Table ‘mrancho_db.wp_yith_wcwl_lists’ doesn’t exist]
    SELECT COUNT(*) FROM wp_yith_wcwl_lists WHERE wishlist_token = ‘NMJVAFPHCNM3’
    WordPress database error: [Table ‘mrancho_db.wp_yith_wcwl_lists’ doesn’t exist]
    SHOW FULL COLUMNS FROM wp_yith_wcwl_lists
    WordPress database error: [Table ‘mrancho_db.wp_yith_wcwl_lists’ doesn’t exist]
    SELECT l.* FROM wp_yith_wcwl_lists AS l WHERE 1 AND l.user_id = 2 AND l.is_default = 1 ORDER BY ID DESC

    I have no idea why I’m getting such a DB error, I’ve updated WordPress to its latest version (4.4.2) as also the plugin itself (2.0.13)… Although it seems the error points out to the non existence of the yith plugin’s tables within the DB, those tables actually do exist, so, not sure what to do from here.

    I’d really appreciate any input regarding this issue.

    Sorry, but I didn’t get what you mean about the correct forum.

    Regards,
    Adriano.

    Plugin Author YITHEMES

    (@yithemes)

    @adriano,

    this is a really strange issue
    The best solution I can imagine, is to force WP to regenerate WishList DB structure

    Anyway, this will require to delete all current contents of wishlist, and some hardcoding

    If you don’t bother to proceed this way, here’s the step to follow:
    1. Disable wishlist plugin
    2. visit wp-admin/options.php in your site backend and search for yith_wcwl_db_version option; delete the content of the option, and save
    3. Delete wcwl* tables from your DB (and yes, you may want to make a complete backup before to click the “I’m sure” button 😀 )
    4. Activate again the plugin

    Let me know if this helps

    Does this snippet works on premium version? I have tried it without success.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Get total wishlist via ajax’ is closed to new replies.