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.
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.
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,