Posted: May 11, 2018 at 1:38 pm
|
So I am taking code from this topic on showing specific questions for certain ticket types. I took jxh’s code and placed it within the wp_add_inline_script sample that Tony posted. When I try to add it to the functions.php file for my child theme, I get the following error: syntax error, unexpected ‘}’, expecting ‘,’ or ‘)’ I’m still new to JQuery and PHP, so I am not sure where I’m going wrong on this:
|
|
I can’t seem to edit my post: I forgot to add that it the error stated it was on line 11, which is the line with the “};” symbols |
Hi there, The first thing that stood out that needed fixing in the code was the single quotes were not escaped. In this case it’d be simpler to replace the single quotes within double quotes within the JavaScript part of the code, like this:
|
|
|
Thanks! That helped to get the code saved, unfortunately it doesn’t seem to be hiding the particular ticket IDs as I hoped. Not sure what else I can do at this point. |
Here are a few troubleshooting steps: 1) Check the page source and verify the custom JavaScript code is present on the page. |
|
|
Ok, so it appears that the #ee-reg changes with each checkout transaction but adding an id number at the end. If I change the find( line to the exact id number in that particular transaction, it does work, so the ticket ID is correct. I tried changing the
and while it saved, it did not hide the question and gave the following question in console: When I click the reference link in console, the console box just shows a red X and a blank page within. I also have this error show up, regardless if I have the code in my functions file: `Uncaught DOMException: Failed to read the ‘cssRules’ property from ‘CSSStyleSheet’: Cannot access rules I use Divi, so since it see an et_ shortcode, not sure if it’s related. |
|
|
|
That worked! Thank you! I am very new to JQuery so it’s been a lot of trial and error. One last thing, is there a way to make that hidden question no longer a required question if it is hidden? Otherwise I universally have to make the question optional, which isn’t a dealbreaker, but not preferred. |
|
The closest I found is to use .attr(“required”, false); but it didn’t work, whether I did it like this:
or: ‘find( “[id^=\’ee-reg-form-qstn-grp-veterans-pricing-\’]” ).hide(); |
It may work to follow this outline for those required questions, where you: |
|
|
So from my understanding, the question is set to not required by default and admin. If that is the case, would I only need to use jquery to make the question set to required on certain ticket types? Here’s what I have atm: ‘function ee_custom_hide_question() { Saved, but the question doesn’t appear as required for the tickets types that show the question. Tried removing the .Removeattr() part and just having the .attr and it still wouldn’t work. |
|
Just realized I think my ‘ and brackets were a bit off:
Still didn’t work, but it saved and makes a bit more sense syntax-wise. |
OK that’s a different approach that could work but there are a few items that need fixing:
can be changed to:
|
|
|
Made the changes, got the following error on the line
|
Oh yes, sorry. Those quotes need to be double quotes because the script is within a set of single quotes.
|
|
|
That got it to save, but the code didn’t work. Question still doesn’t require you to select the checkbox to proceed in checkout. I feel like I am missing something. |
Probably a link to the page in question so we can view the source will help find that missing something. |
|
|
|
May I ask which questions are you trying to hide, for which ticket type? |
|
|
Last question “You have selected the veteran price…” |
|
And it hides under the regular ticket, but appears (ideally as a required question) for the veterans only ticket |
This will make that last question required:
|
|
|
That did it! Thank you so much! |
The support post ‘Add jquery to inline php script to hide questions for certain tickets’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.