Skip Navigation

[Resolved] Saving Logged-in User Selected Query Results by Checkboxing to a User Bin

This support ticket is created 6 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 9 replies, has 2 voices.

Last updated by Christian Cox 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#578657

Tell us what you are trying to do?
Create an actionable for each query in a row cell from a glyphicon onclick for ecommerce Add to Cart / Wishlist with modal and before and after confirmation messages. Selected items saved to a user for their future access. Welcome the simplest solution. Thanks.

IMMEDIATE APPLICATION
1. Finally figured out custom search filtering (STATUS: functioning)
2. Query results in a Bootstrap styled table (STATUS: achieved)

ADVANCED APPLICATION (Add to Cart or Wishlist)
1 Actionable CHECKBOX to rows that Logged-in user can select from and save to a BIN View like a Wishlist (STATUS: clueless)
2. Hook a post ID result to a ecommerce product returned in query, ie WooCommerce, EDD, Sell Media (STATUS: clueless)

Is there any documentation that you are following?
YES: https://toolset.com/documentation/user-guides/front-page-filters/?utm_source=viewsplugin&utm_campaign=views&utm_medium=edit-view-create-custom-search-helpbox&utm_term=Creating%20custom%20searches%20with%20Views#custom-search-view

Is there a similar example that we can see?
hidden link

What is the link to your site?
Not for public consumption. I can send it in a private reply.

#578796

1 Actionable CHECKBOX to rows that Logged-in user can select from and save to a BIN View like a Wishlist (STATUS: clueless)
A multi-row editor like this in CRED isn't currently supported, so the closest I can get you will be a button in each row that you can click to "Add to Wishlist" or something similar. Checking multiple items and bulk-adding the to the wishlist simultaneously is out-of-scope for what I can help you with here in the forum, as it would require a lot of very custom code.

Assuming one Wishlist per User is sufficient, you could accomplish something like this with a repeating custom user field. Each time the user clicks a button to Add to Wishlist, you will add an entry in the repeating field that includes the item's ID. This will require a bit of custom code using cred_save_data. I can help you with this if you're not familiar with PHP.

When displaying lists of items in Views, you can check the current User's repeating custom field for a matching item ID. This will indicate that the item is in a wishlist already, so you can display something other than the "Add to Wishlist" button.

2. Hook a post ID result to a ecommerce product returned in query, ie WooCommerce, EDD, Sell Media (STATUS: clueless)
Sorry, I'm not following you. Can you walk me through the desired process and outcome, one step at a time?

#578878

Thanks Christian.

Re: 1 Actionable CHECKBOX to rows that Logged-in user can select from and save to a BIN View like a Wishlist (STATUS: clueless)

<quote>A multi-row editor like this in CRED isn't currently supported, so the closest I can get you will be a button in each row that you can click to "Add to Wishlist" or something similar. Checking multiple items and bulk-adding the to the wishlist simultaneously is out-of-scope for what I can help you with here in the forum, as it would require a lot of very custom code.</quote>

Yes please. The code for the button for Add to Wishlist would be appreciated. A styled gray/red Bootstrap "glyphicon glyphicon-heart-empty" to "glyphicon glyphicon-heart" with alternating add/remove code onclick would suffice. hidden link

It seems like it would be simple to display the wishlist view. i think I would create a View for the logged in user to show just their Wishlist. I'm using Bootstrap and a membership plugin so I'll created a page for the Views generated shortcode. A bonus would be ability for user to securely forward the list via email via a modal. We have SSL.

<quote>Assuming one Wishlist per User is sufficient, you could accomplish something like this with a repeating custom user field. Each time the user clicks a button to Add to Wishlist, you will add an entry in the repeating field that includes the item's ID. This will require a bit of custom code using cred_save_data. I can help you with this if you're not familiar with PHP.</quote>

I haven't experimented with cred_save_data. Your coding guidance would be appreciated.

2. Hook a post ID result to a ecommerce product returned in query, ie WooCommerce, EDD, Sell Media (STATUS: clueless)

<quote>Sorry, I'm not following you. Can you walk me through the desired process and outcome, one step at a time?</quote>

I'm thinking to add additional fields to an ecommerce platform's post type to Admin backend via Toolset. We sell audio WAV files, but only return the MP3 in the search results for listening due to size limitations. For each MP3 returned in a row we also have a WAV file format stored. The field for the WAV file is delivered by linking and in their dashboard by the plugin. I haven't experimented with how to control 3rd party plugin fields. But I'm sure this is exactly what I need to achieve the ecommerce application. I'll lift the Add to Cart code from the ecommerce platform already available. Just need to tell Views to call it when "Add to Cart" is clicked. Hope this makes sense. If not, I can whiteboard process flow and upload image to ticket in a part 2 follow-up.

#579109
field-group.png

Okay to set up the Wish List, first you must create a new User Field Group. Include a number field called "Item ID", and allow multiple instances of this field (i.e. a repeating field). See field-group.png for the example I will be using below.

Next, you must create an Edit User CRED form. Call it "Edit User Wishlist" or something similar. Autogenerate the form, then remove all the inputs from the generated code except the submit button. That will leave you with a form like this:

[creduserform class='cred-user-form cred-keep-original']

	[cred_field field='form_messages' value='' class='alert alert-warning']

	[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/creduserform]

Add a generic hidden field to your form, just before the submit button. For the value, supply the post ID shortcode wpv-post-id:

[cred_generic_field field='itemid' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

This will allow you to capture the ID of the current item in the list View. Save the User form and add it to your List View's Loop Output editor, so that the form is included in each row of the List.

Then, add the following code to your child theme's functions.php file:

add_action('cred_save_data_12345', 'update_user_wishlist',10,2);
function update_user_wishlist($post_id, $form_data) {
  $item_id = $_REQUEST['itemid'];
  add_user_meta($post_id, 'wpcf-item-id', $item_id);
}

Change 12345 to match the numeric ID of your User CRED form.

Now visit your list on the front-end of the site. You should see a "Submit" button next to each item. When you click the button, your User Profile will be updated and the item's ID will appear in your Wish List fields. Please verify you are able to get this far, then we can continue.

#579400

1. User field "itemid" for Item ID created.
2. CRED User form (edit) created. Specified controlled user level access as required for the application (Note: Only select user level can use Wishlist and that level must be logged in to create a Wishlist.) So a warning message would say "You must be logged in as "X" level to create or add to Wishlist.")
3. Unsure as to response on submit, but set it to return confirm message "Successfully added to Wishlist". It might be wanting the warning message instead of confirmation message. I can figure that out upon testing then edit as needed afterward.
4. Unsure as to Ajax. In the hidden form field field Item ID shouldn't I add post='user'?
5. Added action with "itemid" replaced with the to child function.php
---------------------------------------------------------------------------

I think you meant create Post Form edit for the post type and not User Form edit. Otherwise, there is no way to select the the form data to edit. Creating a User Form edit returned this which is not what we want to occur:

[ This form will auto-generate the password for the new user.
In order for the user to receive the password, you need to create a notification which will include that password. ]

After following instructions including uploading edited function.php Admin goes white as well as front end search query result table page. So I then created an edit Post Form for the post type with the code in the editor. I made sure to change the form ID number to the post type Post Form ID in the add action function. Still get white screen and normal again after reversion to original functions.php

Post form edit code to edit Post type

[creduserform class='cred-user-form cred-keep-original']

[cred_field field='form_messages' value='' class='alert alert-warning']

[cred_generic_field field='itemid' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

Added function.php code. Is it possible that "update_user_wishlist" need to be the post type slug?

// Playbox Wishlist action from CRED 
add_action('cred_save_data_5574', 'update_user_wishlist',10,2);
function update_user_wishlist($post_id, $form_data) {
  $item_id = $_REQUEST['itemid'];
  add_user_meta($post_id, 'wpcf-item-id', $item_id);
} 
#579605

I think you meant create Post Form edit for the post type and not User Form edit. Otherwise, there is no way to select the the form data to edit.
Actually, I mean an Edit User Form. Please refer to my earlier comment:

Assuming one Wishlist per User is sufficient, you could accomplish something like this with a repeating custom user field. Each time the user clicks a button to Add to Wishlist, you will add an entry in the repeating field that includes the item's ID.

The custom field exists on the User's profile, not on the post type, so you need to modify the User with the CRED form, not the post. I think this is the disconnect, and you'll need to use User forms instead of Post forms in order for the provided code to work.

Creating a User Form edit returned this which is not what we want to occur: This form will auto-generate the password for the new user.
No problem, this warning can be disregarded because we're not modifying the user's password or other critical information with the form. Since the other input fields have been removed, the information for these fields will remain unchanged. We will only be modifying the custom field that stores references to each item in their Wishlist, and we will be doing that with the custom code I provided.

Added function.php code. Is it possible that "update_user_wishlist" need to be the post type slug?
Again we're updating the User here, not the post. The argument "$post_id" in this case actually refers to the User ID, it's a bit confusing but the variable name is arbitrary.

#579729

Okay. I scrubbed my brain. Almost there. What am I doing wrong?

I found one disconnect. That being I missed the add the edit User Form shortcode to the output loop of my search result view. Performed that missing part and again white screen after edited functions.php is uploaded. Back to normal when I revert to original functions.php.

My loop output as updated in the View editor:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
		[wpv-post-body view_template="Loop item in THE RESULT PAGE Search"]
      [types usermeta='itemid' format='FIELD_NAME: FIELD_VALUE' user_current='true' separator=', '][/types]
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Of which, edit User form code is this :

[creduserform class='cred-user-form cred-keep-original']

[cred_field field='form_messages' value='' class='alert alert-warning']

[cred_generic_field field='itemid' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[wpv-post-id]"
}
[/cred_generic_field]

And, edited functions.php has this added action code and 1111 is the Id of the newly created edit Post form ID:

add_action('cred_save_data_1111', 'update_user_wishlist',10,2);
function update_user_wishlist($post_id, $form_data) {
  $item_id = $_REQUEST['itemid'];
  add_user_meta($post_id, 'wpcf-item-id', $item_id);
}

MY CURRENT CONFUSION 😐

Does your instruction "Change 12345 to match the numeric ID of your User CRED form." call for the ID of the newly created edit User form for this application OR the preexisting edit Post form (where the user uploads digital assets returned by the search view) OR the Post form ID for the post type?

My futher confusion is with this statement: For the value, supply the post ID shortcode wpv-post-id. Am I supposed to change the value with something other than literally "wpv-post-id"?

#579893

Does your instruction "Change 12345 to match the numeric ID of your User CRED form." call for the ID of the newly created edit User form for this application OR the preexisting edit Post form (where the user uploads digital assets returned by the search view) OR the Post form ID for the post type?
Only one of those three options you mentioned is a User form, the others are post forms, right? The first one is the one I'm referring to. Remember, you're editing the User with this form, not the post, even though the form appears in a loop of posts.

Am I supposed to change the value with something other than literally "wpv-post-id"?
Literally how you have it. You have a View that loops over posts, and within that View you have placed your CRED form. So in the context of the View Loop, wpv-post-id refers to the current post in the loop. It represents the item you want to add to the User's wishlist, so we capture that in the CRED form and save it into the User's wishlist custom field.

Performed that missing part and again white screen after edited functions.php is uploaded.
If you're getting a white screen, you probably have a syntax error in your PHP code. You can enable server logs to discover the source of the problem. Go in your wp-config.php file and look for define(‘WP_DEBUG’, false);. Change it to:

define('WP_DEBUG', true);

Then add these lines, just before it says 'stop editing here':

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

Then, try to refresh the page in admin to show the white screen again. This will create an error_log.txt file in your site's root directory, where errors will be logged. Please send me its contents. Once that is done, you can revert the updates you made to wp-config.php.

#581351

Is there a way to forward debug info without making it public? How do I send it to you as requested?

#581674

Sure, I can enable private reply fields here. You can provide dummy information for the server login and just paste your debug info in the comments area.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.