wwwilson
Forum Replies Created
-
Hey @spencerfinnell ,
Ah, thanks for correcting. I didn’t clarify that I was trying to get the post/page id of the current page and not the simpay form.
Nevertheless I’m still stumped with the same problem for some reason. The var_dump turns up as the page id, however any post meta I then pull using the same page id returns null or simpay message
This value must be greater than or equal to 1.
Can you confirm you can get a result from the filter when returning a custom field value using the current page’s id and this filter?
Thanks @spencerfinnell
WP doesn’t get any post data during ‘init’ so I have adapted your script to get the id from ‘url_to_postid’ instead. I have hit a snag that the ‘simpay_form_#_amount’ filter doesn’t seem to accept post ids in any shape or form.
You can see from this code that simply using a post id prevents the filter from working correctly.
add_filter( 'simpay_form_203_amount', function ( $amount ){ // 1.a. Get post ID from URL $current_url = "//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $simpay_post_id = url_to_postid($current_url); // 1.b. $simpay_field = get_field('price',$simpay_post_id); // 2.a. Get post ID manually (for example's sake) $manual_id = 123; // The exact same id as $simpay_post_id // 2.b. $manual_field = get_field('price',$manual_id); // Success: Both $simpay_field and $manual_field var_dump the same (int) value here, however... return $simpay_field; // 1. returns nothing return $manual_field; // 2. returns field successfully } );
Any ideas why I can’t use a post ID in this filter?
Cheers,
Wilson
Follow up after testing with pulled post ids i.e. from get_the_ID() (apologies my previous reply was after manually coding the post ids)*
It appears like the simpay_form_#_amount filter can’t get the post ID of the current post.
For example if I place this in my theme’s functions.php file:
function simpay_price($amount){ $id = get_the_ID(); return $id; } add_filter( 'simpay_form_203_amount', 'simpay_price' );
And add the form to a post.
echo do_shortcode('[simpay id="203"]')
I would expect to see the price as the post_id however the result produced by the form is
This value must be greater than or equal to 1.
which suggests no value was returned by the filter (as the post ID was not found).
I am wondering if this is because the post needs to render in order to get the post id but in doing so the shortcode will also render (and therefore is not able to be filtered by post id)?
Hey @spencerfinnell,
This works a dream, thanks!
My only bother was to get it to work for multiple shortcodes displayed on the same page (i.e. a payment button for each variation).
One workaround I found was to create a maximum number of forms to variations expected on each page and use your stated method to apply a variation to each form available. It’s a little clunky but works.
I don’t suppose there is a more elegant solution? No worries if not.
Cheers,
Wilson
Hey @spencerfinnell,
Thanks for your reply.
My case is that I have multiple post types acting as product. Each product page with a number of variations of that product. Every product and variation requires a purchase button/form.
A variable on a product page is $price which would differ based on the product and variation.
Instead of creating a form for every product and variation in the simpay admin, I am wondering if there is a quick way to feed data directly to the form. In effect, creating payment forms on the fly and bypassing the need to create a unique form in the simpay admin for every instance.
For example’s sake I’ve used shortcodes with fake variables to try to illustrate the point: So on a product page I might include 3 variations of a given product.
[simpay product_id="123" variation="x" price="10"] [simpay product_id="123" variation="y" price="20"] [simpay product_id="123" variation="z" price="30"]
Each shortcode would generate a payment form with corresponding variation/price.
Do you know if this be achieved somehow? Let me know if I can be more clear.
Cheers,
Wilson
Forum: Plugins
In reply to: [Accept Stripe Payments] Refunding usersHey @mbrsolution
Thanks for your response.
I am looking to set up a vendor system where user A can purchase a service from user B, but user B can decide if they can deliver it. If not user B cannot deliver the service they can reject the request, initiating a refund for the order. Ideally this would be an automatic process.
Forum: Plugins
In reply to: [Accept Stripe Payments] Custom CSSHey Alexander, Perfect. Just what I was looking for. Thank you for your help!
Forum: Plugins
In reply to: [GDPR] Privacy page feature for other required Terms pagesForum: Plugins
In reply to: [GDPR] Can’t validate consent_checkboxes fieldsOn that note: It would also be great to know how I could pull a list of required fields at the backend too (so validation doesn’t have to be done manually each time).
Forum: Plugins
In reply to: [GDPR] No modal appearsUpdated to latest version and added cookies and seems to work now, thanks!
Forum: Plugins
In reply to: [GDPR] Shortcodes do not workHi Fernando. Perfect, this is just what I was looking for thank you!
Forum: Plugins
In reply to: [GDPR] Shortcodes do not workHey Fernando, I have a bunch of other custom post types/fields the user can create too. Are you planning to support the ability to hook them in too?
Forum: Plugins
In reply to: [GDPR] Add to custom registration pageHey Fernando, Brill, thanks for your help. I’ll have a dig through and get back if I have any questions. Cheers!