Skip Navigation

[Resolved] Sell post fields for a post type

This support ticket is created 7 years, 10 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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
#411603

I am trying to: sell post fields in a post type using post form and WooCommerce

I visited this URL: NA

I expected to see: NA

What I want to do is:
1. after a user create/submitted a free post (must be registered and logged in) he can see the option to add post fields for a fee when editing his post
1.a an alternative is buying a simple product (non virtual) that is related to the free post the user created

2. a link to purchase the additional post fields or simple product take the user to a WooCommerce product

3. the product information should include the parent post id or url i.e. the post type that sent the user to the product

4. if the user purchased the post fields or simple product the post fields will be available for editing in the post form for the post type
4.a in case of simple product purchase display an indication that a simple product was purchased

5. there is a 1:1 relationship between the post fields and the post type
5. in case of simple product there is a many to one relationship between simple products and the post type

I'm not sure how to do this and need your advise...
Also is there an option to use conditional display in post forms?

Instead, I got: NA

#411634

Dear David,

There are lots of questions in this thread, I am trying to answer them one by one.

Q1) after a user create/submitted a free post (must be registered and logged in) he can see the option to add post fields for a fee when editing his post.
There is a logic problem in your workflow, when a visitor submitted post with CRED form, there isn't correspond wordpress user can be setup as the post author, after the visitor register into your website, wordpress not find the post he just submitted.
So I suggest you reverse the workflow as below:
the visitor buy a free product, and register as a wordpress user, then submit a free post.
Which is possible within CRED plugin, see our document:
https://toolset.com/documentation/user-guides/charging-payments-with-cred-to-register-users/

Q2) a link to purchase the additional post fields or simple product take the user to a WooCommerce product
Yes, it is possible to take the user to a product when register users, see above document.

Q3) the product information should include the parent post id or url i.e. the post type that sent the user to the product.
Yes, it is possible within CRED form for creating child post, see our document:
CRED Forms for Child Content
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

Q4) and 4.a)
What kind of post fields are we talking about, how do you setup the post field?
If you are going to display some specific fields in the CRED form conditionally, please check our document:
Conditional Display for Form Inputs
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/

Q5)
What kind of relationship do you want?
are we talking about 1 post have only one custom field?
If it is, you just need a single instance custom field.
Are you going to setup such kind of relationship between "Product" post type and your custom post type, for example:
Product 1 -> cpt post 1
Product 2 -> cpt post 1
Product 3 -> cpt post 2
Product 4 -> cpt post 2
If it is, you can setup your custom post type as parent post type of "Product", see our document:
Creating Post Type Relationships
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

#411913

Thanks Luo Yang,

I might have not explained my self properly as I already seen the information you provided.

Here is what I'm trying to do:

1. provide users to submit their own posts for free on my site. - this is done already and works just fine

2. allow a user to buy a simple product that have a 1:1 relationship to a post (I would like to display the buy option in the edit form I created for the post and on the post itself)
2.a once the first time the product was bought (complete the purchase) flag the post somehow that a payment was made
2.b with a completion of the purchase display post fields on the post form that the user couldn't see/edit before the purchase. I'm trying to do that with [wpv-conditional]; and hide the purchase option that was displayed before
I'm not sure if I should use child post for this instead
2.c any user can buy the simple product
2.d only the post owner can edit the additional fields that added after the first purchase

3. how do I display a (or link to a) product that will display the parent post URL?
3.a I would like to display this in Post form, is it possible?

if using a child post for this
4. how do I display a link to a form of a child post in the parent edit form?
4.a I think this might solve the issue

all the above is done in the front end without having the user access the back end.

I hope this is more clear now.
thanks,

David

#411936

I am still not clear what is the 1:1 relationship you want.

Q2.a) once the first time the product was bought (complete the purchase) flag the post somehow that a payment was made
In CRED commerce plugin, you can do below after the payment completes:
1) Updating the post status when the payment status updates
2) Setting the post author when payment completes
3) Email notification
See our document:
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/
section "What Happens when Payments Complete"
If you need other custom features, for example add a custom field into the post after payment comletes, you will need to try with custom codes, for example:
cred_commerce_after_payment_completed
Action to be executed after the purchase is completed successfully
https://toolset.com/documentation/user-guides/cred-commerce-api/

Q2.b) with a completion of the purchase display post fields on the post form that the user couldn't see/edit before the purchase. I'm trying to do that with [wpv-conditional]; and hide the purchase option that was displayed before
If it is a custom field, you can try with Views shortcode [wpv-conditional] to hide the CRED form shortcode.
See our document:
https://toolset.com/documentation/views-shortcodes/#wpv-conditional

Q3) how do I display a (or link to a) product that will display the parent post URL?
Is there any post relationships between "Product" post and the "parent post" post type?
If there is parent/child relationship, you can display them with Views shortcode [wpv-post-link]:
https://toolset.com/documentation/views-shortcodes/#wpv-post-link
id (opt):
'$parent' | 'post-id' | '$custom post name'
Displaying Fields of Parent Pages
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

Q3.a) I would like to display this in Post form, is it possible?
When you are using CRED form for creating child post, you can display the parent post information with CRED shortcode: [cred_post_parent], see our document:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/
section "Information about Parent Pages"

Q4) how do I display a link to a form of a child post in the parent edit form?
Yes, it is possible, see above document:
section "Displaying the Form"

#413547

Hi Luo Yang,

thank you for all the links, I have seen and read most of them before.

While I was able to display a link to a child post form in my parent post edit form on the front end I'm still having a difficulty to understand how to solve my problem.
Please note that I'm not a developer. so while I can semi understand the API's I'm not sure how to use it.

lets try again:

I have a parent post that my users can submit for free using post form on the front end.
I have a couple of things I want to add for the parent post for a fee.

1. add a custom type fields to the post that only one user (post owner) can add for a fee. I believe this can be done with child post form for a fee.
I know how to create the child form and how to charge for it.
the problem is how to flag the parent post that a child form purchase was completed successfully

the idea is to have a conditional display on the parent post edit form to buy additional field types.
once a purchase is complete display the data on the parent form front end and allow the user to edit the fields on the parent post edit form. also, hide the purchase option after the purchase was completed successfully.

2. with the purchase above ship to the user a simple product
I can see an order in woocomerce for the product associated with the child form but I cannot see to what parent post its related to.
I need the parent post URL so I can customize the shipped product. mainly I need the parent post URL and a few custom post type fields I created for the parent post.

I thought I can create a child post field like 'purchased complete' and flag it to true using cred_commerce_after_order_completed API but I'm not sure how to do that.
is there another way to know that the child post purchased completed successfully?

if I can have that I believe I can use the conditional display using the 'purchased complete' to show or hide the purchase option vs. the edit data option on the parent post edit form.

I hope this makes it more clear and hope you can help me with this again.

thanks again,

David

#413692

Q1) Yes, it is possible with a custom field,
When user submit the CRED form for creating child posts, You can use CRED action hook "cred_commerce_after_payment_completed" to update the specific field value in parent post, for example "sold", then in the CRED form for editing parent post, use Views shortcode [wpv-conditional] to check the field value is "sold", then display the text "purchase was completed successfully"

More help:
cred_commerce_after_payment_completed: (action)
This hook allows doing a custom action when post data is saved to database.
https://toolset.com/documentation/user-guides/cred-commerce-api/

wpv-conditional
Conditional shortcode to be used to display a specific block of meta HTML based on results of a boolean expression . If the expression is true, then the meta HTML between the [wpv-conditional][/wpv-conditional] shortcodes will be executed.
https://toolset.com/documentation/views-shortcodes/#wpv-conditional

Q2) As you can see in document:
https://toolset.com/documentation/user-guides/cred-commerce-api/
action hook cred_commerce_after_payment_completed, there is a parameter:
'cred_post_id'=> Post ID that was created/edited with the form,
This is the child post ID, with it you can get it's parent post ID, Types is using a custom field "_wpcf_belongs_[parent-slug]_id" to store the parent post ID, for example, the parent post type is using slug "product", then the field slug is "_wpcf_belongs_product_id", see our document:
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
section "Displaying child posts using Types PHP functions"

#413912
2 - form for a fee front end does not show the parent fields.JPG
1 - form for a fee for child post.JPG

Thanks Luo,

I understand the theory perfectly and it does make sense.
Where I need help is with an exact sample of the code I need to make it happen.

I'm not sure how to write the hook code myself. this is where my knowledge stop and I really can use some help.
It seems that I need only this one snippet of code to make it happen for Q1.

For passing the parent post information into a product or a child post form I'm not sure how to that anymore.
please see images for the issue
image 1 is the form to create a child post for a fee
i link to it from the edit parent post form (I'm expecting to see the parent field type in the create child post and i cannot see it) see image 2.

The same go to passing the parent URL and some other type fields belong to the parent post to the woocommerce product when the user purchase the child post. I'm expecting to see these in the woocomerce order information otherwise i dont know to which post this purchase was made and custom the shipped product accordingly.

Let me know if you need access to my staging site if this helps.
Please advise,

Thanks,

David

#413968

Since it is a custom PHP codes problem, please duplicate same problem in a test site, and fill below private detail box with login details, also point out the problem CRED form URL, page URL, and which one is the "sold" field, which one is the parent post type, I need test and debug in a live website, thanks

#414385

Thanks for the details, I am checking your test site, will feedback if there is anything found

#414940

I suggest you add below codes into your theme/functions.php:


add_action('cred_commerce_after_payment_completed','my_hook_func',10,1);
function my_hook_func($data)
{
// if it is specific CRED form ID 343
	if(isset($data['extra_data']['cred_form_id']) && $data['extra_data']['cred_form_id'] == 343){
// child Headstone Coordinates post ID
		$child_post_id = $data['extra_data']['cred_post_id'];
// parent memorial post ID
		$parent_post_id = get_post_meda($child_post_id, '_wpcf_belongs_memorial_id', true);
// save value 3 into custom field plate-sold
		update_post_meta($parent_post_id, 'wpcf-plate-sold', 3);
	}

}

Hope it help

#415706
Woocom order status payment pending.JPG
status publish sold plate set to no.JPG
Payment not comepelte on my account.JPG
manually change order to complete.JPG
just clicking the update post button.JPG
Conditional area should show somthing.JPG
after updating the paot on the backend.JPG

Thanks Luo,

I am in the midst of testing your code and run into some issues with my PayPal sandbox. for some reason the purchases I submit are not automatically flagged as complete even after installing WooCommerce Order Status Control plugin. I guess something with my PayPal sandbox/WooCommerce configuration is wrong and I will check it in the next few days.

with that said a few issues still at hand

changing the order to complete manually does not change the parent post field "plate-sold" to equal sold. is the code you created should change that in a manual update scenario?

I noticed that creating a free parent post using the front end does not set the "plate-sold" to the default value although it seems like it is set to that value in the back end.
the way I was able to see this issue is when I set a conditional display based on this value and I get an empty area instead of a display
in the cred form Edit Memorial I set this conditional:
[wpv-conditional if="( $(wpcf-plate-sold) eq '1' )"]Add on
<p>
Add a stainless steal plate and GPS coordinates to the headstone
</p>
<a href="[cred_child_link_form form='388' parent_id='-1' target='_self']" class="btn btn-success" role="button">Add on - GPS coordinates and a dedicated plate</a>
<br>
[cred_child_link_form form='388' parent_id='-1' text=link to buy plate' target='_self']
[/wpv-conditional]

user create a new memorial post
click on edit the post
expectation see the above condition display the content

I have tried to create a child post using 2 options
1. link to a child post cred form from parent edit cred form
this create a child post but never show the information in the parent post edit in the back end even after the order was manually changed to complete
the link I use here is <a href="[cred_child_link_form form='388' parent_id='-1' target='_self']" class="btn btn-success" role="button">Add on - GPS coordinates and a dedicated plate</a>
for some reason it translate to hidden link target="_self"></a>

2. link to a child post from the parent post (front end view mode)
this create the child post and display the information in the parent post edit in the back end once the order was manually changed to complete
the link I use here is [cred_child_link_form form='388' parent_id='-1' text=link to buy plate' target='_self']
which give me the the url hidden link

Also, I'm still not sure how to pass the parent post information in the order for ordering processing. I need the parent post urls and some other fields from the parent post.

Thanks,

David

#415783

I suggest you try with the option 2):
link to a child post from the parent post (front end view mode)
And follow our document to setup the child form link:
https://toolset.com/documentation/user-guides/cred-forms-for-child-content/

And the shortcode cred_child_link_form will output a link with HTML "a" tag, you can not use it in "href" attribute
See our document:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_child_link_form
Display a link to a page to add a child post

And I suggest you create different threads for each question, it will help other users to find the answers. thanks

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