Skip Navigation

[Resolved] inserting more than a cred form on the same page

This support ticket is created 5 years, 7 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Author
Posts
#1091179

Hello Luo,

Thank you for your reply.
I checked the new booking form where It's located in a single product page as I recently included another form to approve the post on the same page. When I removed the recent form from the page, It seems that it works back again and saves the relationship. I'll try to find another way around with the packs forms as I have 3 cred forms on it's page that are displayed in a loop view.

If you have a solution for inserting more than a cred form on the same page, I'll appreciate it so much.

#1091182

Hello,

I assume we are talking about the page "Membership":
hidden link

and the view "Membership"
hidden link

The post form "Premium Pack":
hidden link

I have tested it in my localhost, in the page "Membership", you are displaying the post form "Premium Pack" three times, when I click one of the submit button, it adds the same product "Premium Pack" in to cart.

Are you going to add different product into the cart depends on the post view "Membership"?

If it is, you can try with the filter hook "cred_commerce_add_product_to_cart", for example add below codes into your theme file "functions.php":

add_filter('cred_commerce_add_product_to_cart', function($product_id, $form_id, $post_id){
	if($form_id == 12215 && $product_id == '12296'){
		if(isset($_POST['@product-pack_parent'])){
			$product_id = $_POST['@product-pack_parent'];
		}
	}
	return $product_id;
}, 20, 3);

More help:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_add_product_to_cart
Filter that allows to dynamically alter the product associated with a CRED Commerce form, when adding to cart.

#1091428
Screen Shot 2018-08-24 at 4.12.48 AM.png
Screen Shot 2018-08-24 at 3.19.54 PM.png
Screen Shot 2018-08-24 at 3.19.08 PM.png
Screen Shot 2018-08-24 at 3.19.03 PM.png
Screen Shot 2018-08-24 at 3.18.55 PM.png

Hello Luo,

Thank you for your recommendation as I already set a filter to update the product in the cart.
BUT,
still the relationship problem existing.
I moved the cred form to a separate page and created a cred child post link, I get the right product id in the url but can't use it to update the cred form post title as it's getting the post title from the page containing the form instead of the product.
If there is a way to extract the parent product id from the url, that would be a solution in my opinion.

The other way around that: if there is an api shortcode to connect the 2 post types from php.

Thank you,

#1092794
#1097129

Thank you Luo,

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