Skip Navigation

[Resolved] Favourite System: cannot remove favourite, but can add double

This thread is resolved. Here is a description of the problem and solution.

Problem:
Favourite System: cannot remove favourite, but can add double

Solution:
You need to use the Toolset Form's hook cred_save_data to remove the favorite.

Please check the following reply:
=> https://toolset.com/forums/topic/creating-a-shortlist-system-for-members-similar-to-airbnb/#post-1339707

You can find the proposed solution in this case with the following reply;
=> https://toolset.com/forums/topic/favourite-system-cannot-remove-favourite-but-can-add-double/#post-1347251

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by tobiasF-3 5 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1346063

This is in relation to the problem you helped me with last week:
https://toolset.com/forums/topic/creating-a-shortlist-system-for-members-similar-to-airbnb/

Adding favourites to the shortlist works fine. But the fabourites functionality is weird: i cannot remove a favourite. But I can add doubles and when logiing back in it does bot show me if a favourite is added already or not.

Do you see where this is going wrong? Thx!

#1346069

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please send me problem URL and access details.

I have set the next reply to private which means only you and I have access to it.

#1347251

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link
- Select the shortlist option from the dropdown
- Click on button "Favorite" - favorite will be added and the button will become "Remove Favorite"
- Click on the button "Remove Favorite" - and the favorite item will be removed.

I've updated the code as given under that is added to "Custom Code" section of Toolset:


add_action('cred_save_data', 'func_set_list_user_favorites',10,2);
function func_set_list_user_favorites($post_id, $form_data) {
    if ($form_data['id']==1205) {
      
       toolset_connect_posts('location-favourite',$_POST['location_id'], $post_id);
       toolset_connect_posts('shortlist-favourite',$_POST['shortlist_id'], $post_id);
      
$title = "fvID-".$post_id."-locID-".$_POST['location_id']."-slID-".$_POST['shortlist_id']."-uID-".get_current_user_id();
       $slug = sanitize_title($title);
         
        $args = array('ID' => $post_id, 'post_title' => $title, 'post_name' => $slug);
        wp_update_post($args);
    }else  if ($form_data['id']==2127) {
      
       toolset_disconnect_posts('location-favourite',$_POST['location_id'], $post_id);
       toolset_disconnect_posts('shortlist-favourite',$_POST['shortlist_id'], $post_id);
       wp_delete_post($post_id);
      
      //post_author
     }
  
  
}

You can see how view's loop output build here:
=> hidden link

Then, I've added the following code to the following form's "Enter the message to display instead of the form." section:
=> hidden link

 [cred_form form='remove-from-favorites'] <script>  jQuery('#select-shortlists').trigger('change'); </script>

I've created another form as you can see here:
hidden link

#1347753

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please confirm that the solution I shared help you to resolve your issue 🙂

#1352051
Screenshot 2019-09-30 at 22.07.51.jpg

Hey Minesh, thank you so much for this an sorry for the long delay, I was away for a while.
I've tried it, the favourite/remove mechanism works nice now, but there are still issues: on the main page where you can see the locations as overview, I think the favourites do not update. When I choose a shortlist, the locations should update to their 'favourite' state, otherwise a user does not know if he already favourited it and then adds it twice. you know what I mean?

Also, I have a weird issue since you last worked on the website: when I simply go here:
hidden link

and try to add a dynamic toolset image in the view loop, only the common blocks appear, do you know what you changed or what am I doing wrong? (basically I am trying to follow this (at 2mins): https://toolset.com/documentation/user-guides/how-toolset-plugins-work-with-gutenberg/creating-and-designing-views-from-within-block-editor/, also see attachment)

Thank you very much for your patience.
Cheers
Tobi

#1352373

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I can show you the way how it should work as there is no native feature available. As said you can file a feature request for Favorite feature using the following link:
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

What you before ask was already above and beyond the scope of our support policy and now your request is to have help on such custom requirement is pure custom programming and we do not entertain such custom feature/edits.

As a supporter, we need to work within the defined support boundaries and I (we) need to strictly follow that. I can not work for such a custom feature you want which needs such custom programming. I tried my best to show you how you can add/remove favorites by sharing some custom code but I can not be able to offer help further here.

If you need custom programming for your project, please feel free to contact our certified partners:
=> https://toolset.com/contractors/

I hope what I wrote makes sense and clear to you. Thank you for understanding and have a great time.

#1352429

Hey Minesh, no problem I understand and I greatly appreciate your help. For me as a non-coder it is hard to know what is custom code or hard to do and therefore outside of your support and what is easy or with toolset plugins to do and inside of your support. - so no problem and thank you for getting me in the right direction 🙂

Regarding the question in tte second part of my last post: I think that falls into the support: Could you please quickly check what is going on in that link? F.ex: I cannot pick a toolset image cell anymore? Since this happened after you last worked on the site I would love you to look into that quickly and then we can close this thread. Thx again! Tobi

#1352433

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There should not be any side effects of my code as the code added is applicable on the frontend only for forms. You should remove the code and check. If the issue persists - please open a new ticket will all the required information and feel free to resolve this ticket.

#1352489

Okay thx. I will open another ticket then.