Home › Toolset Professional Support › [Resolved] cred commerce
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 |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Tagged: Toolset Forms, Views plugin
This topic contains 27 replies, has 2 voices.
Last updated by Shane 4 years, 6 months ago.
Assisted by: Shane.
Hi Christian created this function for me several years ago, however we have changed the logic of the form because we found our customers were confused. So now we want the product to be added to the cart and have them be taken to woocommerce if the box is checked ( which it is by default).
Could it be easily modified- Sorry im not really a programmer
Thanks very much
// cred form for juried show- goes to ecommerce if box to waive isnt checked otherwise redirects to thanks page
add_action( 'cred_commerce_before_add_to_cart', 'ts_only_buy_if_checked', 10, 2 );
function ts_only_buy_if_checked( $form_id, $post_id ) {
$forms = array( 15806, 3 );
if( in_array( $form_id, $forms) ) {
if( !isset( $_POST['addfee'] ) || $_POST['addfee'] != 1 ) {
wp_redirect( 'hidden link' );
exit();
}
}
}
Hi Steve,
Thank you for getting in touch.
Currently as it looks, this code will redirect them to the thanks page IF the checkbox isn't checked correct?
However now you want to redirect them IF it is checked?
Can you confirm for me, especially the part about the code's functionality.
Thanks,
Shane
Shane thanks It should redirect if unchecked but in our testing the opposite is happening. we would like it to
redirect if un checked and go onto woocommerce fif checked. The for is at
hidden link
Its live but feel free to test- I can clean out your entries after the fact
Hi Stevem
Not sure i'm understanding correctly because based on the login of this code here
if( !isset( $_POST['addfee'] ) || $_POST['addfee'] != 1 ) { wp_redirect( '<em><u>hidden link</u></em>' ); exit(); }
The user will get redirected in 2 scenarios:
1. If the checkbox field is not checked, this would mean the addfee field is not equal to 1.
2. If the field is not on the form at all.
Right now you want it to redirect to the Thanks page <b>IF</b> it is checked ?
In that case you will need to change the logic to this.
if( isset( $_POST['addfee'] ) || $_POST['addfee'] == 1 ) { wp_redirect( '<em><u>hidden link</u></em>' ); exit(); }
The code above is a direct opposite to the one that Christian provided so it should work in an opposite fashion.
Thanks,
Shane
Shane I also moved this code out of functions and into a plugin- is there any reason it wouldn't work there . It doesn't seem to be working as you describe here
Hi Steve,
Would you mind allowing me to have admin access to the site so that I can check on this for you ?
The private fields will be enabled for your next response.
Secondly I would like to know where you've added the custom code.
Thanks,
Shane
Hi Steve,
I'm currently working on this for you.
Thanks,
Shane
Hi Steve,
I'm a little confused.
Let me share what is happening now without any modification to your code.
Test 1
When I submit the form with the Add Handling Fee checkbox selected i'm redirected to the Cart Page. (This is what you want)
So you form works as how you want it and with the original code that Christian provided.
Test 2
When I submit the form with the Add Handling Fee checkbox NOT with Christian's original code i'm redirected to this page /juried-show-thanks/
(This Is also your desired result).
It is in keeping with your original thread here
So now we want the product to be added to the cart and have them be taken to woocommerce if the box is checked ( which it is by default).
No modification was needed for it to work exactly as how you want it.
Thanks,
Shane
Shane were you logged In I neglected to mention it seems to work ok if your are logged in but doesn't if you arent. Im on a little deadline but will test again after lunch and report back if need be
Hi Steve,
Thanks I will try without being logged in.
Hi Steve,
I've verified that when i'm logged out and the field is checked i'm redirected to the Cart page. Let me know your testing results.
Thanks,
Shane
Ok Shane I tried it just now (not logged in) and though i got taken to the woo cart page , the cart was empty ( this has been reported to us though this is the first time its happened to me). The exact message was "Cart is currently empty" I back arrowed and re-sumitted the form and the second time the application fee was added to the cart as expected.
Thoughts
Hi Steve,
In my fresh testing of the form again. I was successfully taken to the cart page. See My Screenshot.
All that was done was to fill out the required fields and submit the form and I was successfully take to the cart page.
Could you try from a different computer and let me know if you're still running into the issue where the product isn't being added?
Thanks,
Shane
Shane I did try from another computer and it went through- Then tried again this am from my machine after a reboot in a private window and I got the cart is empty screen screen (attached). Im wondering if there's some timing issue cause by the file upload size. The people using this form are professional artists and their files can largeish. Several Mb each and up to 5 files. Could i ask you to test with a larger file o and perhaps a couple and see .
We are also wondering if theres a way we can post the status of that generic check box either to the post or the notification. It might help us debug possible scenarios where people are confused by the form and uncheck the box when they should have left it checked)
Hi Steve,
If possible could you provide a few sample images that I can use to test ?
Particularly the ones that you have been using ?
You can upload them to a Google Drive folder and share them with me so that I can run a test on the form again.
I asked Christian to run a test on the form and it added the product to the cart for him as well.
Looking forward to hearing from you soon.
Thanks,
Shane