• Resolved meidanm95

    (@meidanm95)


    Hi!
    I would like to change the remove button functionality to remove the item from wishlist with ajax and without redirection.
    I know how to get the $wl_product[ID] value from the button with ajax but I don’t understand what to do with it inside the ajax php function in order to remove the product from the wishlist

    Thank you for your plugin and help ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter meidanm95

    (@meidanm95)

    UPDATE:
    I made it, but now I have another problem.
    My Problem:
    The wishlist counter does not update as well as the hearts in the products loop.

    1st thing I did was to create an ajax request on the remove button click
    so insted of submitting the form it’s now removes the product from wishlist by getting the button’s value( $_POST[“button”] ) to fire this php function:

    function wishlistAjaxRemove() {  
    	$wl = new TInvWL_Wishlist();
    	$wishlist = $wl->get_by_share_key($wl->get_sharekey());
        $wlp = new TInvWL_Product($wishlist);
    
    		$products = $wlp->get_wishlist(array(
    			'ID' => $_POST["button"],
    			'count' => 100,
    		));
    
    		$titles = array();
    		foreach ($products as $product) {
    			if ($wlp->remove_product_from_wl($product['wishlist_id'], $product['product_id'], $product['variation_id'], $product['meta'])) {
    				$titles[] = sprintf(__('“%s”', 'ti-woocommerce-wishlist'), is_callable(array(
    					$product['data'],
    					'get_name'
    				)) ? $product['data']->get_name() : $product['data']->get_title());
    			}
    		}
    
    	return true;
        wp_reset_postdata();     
        die(); 
    }

    then on success I made another ajax function within the main ajax function to refresh the wishlist shortcode.

    function refreshWlShortcode() {  
        echo do_shortcode('[ti_wishlistsview]');
        wp_reset_postdata();     
        die(); 
    }

    I guess I need to insert somthing inside refreshWlShortcode() function, I just don’t know what :/
    Any help?

    • This reply was modified 2 years, 11 months ago by meidanm95.
    Plugin Author templateinvaders

    (@templateinvaders)

    Hi @meidanm95

    We made a public jQuery function to update wishlist data on the frontend in the latest version of our plugin.

    After you refreshed the wishlist table shortcode you need to run next javascript code:

    tinvwl_add_to_wishlist.update_wishlists_data = 1;
    jQuery.fn.tinvwl_get_wishlist_data();
    Thread Starter meidanm95

    (@meidanm95)

    Thank you!!
    Works like a magic ??
    maybe you can help me with a small problem I have.
    I’m using ‘tinvwl_wishlist_button_clicked’ event to update the shortcode content via ajax and it does not fire on first item added to wishlist, so the shortcode content updates only on second action and above (remove/add to wishlist).
    I guess that’s because tinvwl_wishlist_button_clicked is triggered only after first item is added.. is there a way I can handle it?
    Thank you again! :]

    Plugin Author templateinvaders

    (@templateinvaders)

    Hi,

    We suggest you use the tinvwl_wishlist_mark_products event to update the wishlist table shortcode. Because this event fired only when wishlist data changed.

    Be careful to make a loop because the code above to refresh wishlist data after AJAX removing products will trigger this event also.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Ajax remove item’ is closed to new replies.