The problem of creating additional packages has already been described ( https://toolset.com/forums/topic/how-to-change-the-cred-forms-a-location-for-the-new-ad/ ), but it was not resolved in the Forum. I have received some tips, but I do not know PHP and I can not use them. And for trying to do this by "specialists" I've already lost $ 200 ...
I found https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/ , the described method seems trivial, but as I add the code shown (with the corresponding form fields) to my functions.php file, the page stops working.
Can anyone help me?
Dear Bochnacki,
Please you describe more details for your question:
but it was not resolved in the Forum
The thread you mentioned above has been marked as resolved:
https://toolset.com/forums/topic/how-to-change-the-cred-forms-a-location-for-the-new-ad/
If you still need help on same topic, you can reopen it, please let me know if you need assistance for it. thanks
The thread https://toolset.com/forums/topic/how-to-change-the-cred-forms-a-location-for-the-new-ad/ did not want to continue, because my concept changed, I simplified it.
The idea is to create packages with varying amounts of posts. Or:
Package for 5 posts
Package for 10 posts
Package for 20 posts
I have finished products for 5, 10 and 20 posts but still can not do separate packages.
As I mentioned above: please provide detail steps to duplicate same problem:
I have finished products for 5, 10 and 20 posts but still can not do separate packages.
How do you setup these:
Package for 5 posts
Package for 10 posts
Package for 20 posts
How do you want to do separate packages?
Are we talking about this case:
There is a product "Package for 5 posts", if your user buy this product, he will be able to create 5 posts in your website?
If it isn't what you are going to achieve, please describe details for your questions. I need to test it in my localhost, thanks
"There is a product "Package for 5 posts", if your user buy this product, he will be able to create 5 posts in your website?" - exactly.
And similarly to the product "Package for 10 posts" - how the user buys it can create 10 posts.
"How do you want to separate the packages?" For the product "Package for 5 posts" I have Post Form "Add new Ad package." And for "Package for 10 posts" I want to do "Add new Ad package 10", and for "Package for 20 posts" the next "Add new Ad package 20".
Thanks for the details,
1) the question you are asking is not related to the thread you mentioned above:
https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/
You are asking for setting limitation after user purchase a product.
But the above thread is for doing action after user submit a CRED form.
And it is still not clear that:
For the product "Package for 5 posts" I have Post Form "Add new Ad package." And for "Package for 10 posts" I want to do "Add new Ad package 10"
2) What are the "Add new Ad package" and "Add new Ad package 10"?
Are they CRED form links? How do you setup these CRED forms? If you can describe the question with detail steps, that will help us to find the problems.
3) For your question:
And similarly to the product "Package for 10 posts" - how the user buys it can create 10 posts.
There isn't such a built-in feature within CRED Commerce, as a workaround, I suggest you try these:
a) setup a custom numeric user field, for example "post-limitation":
b) after the user purchase a product, use action hook "woocommerce_order_status_completed" to trigger a custom PHP function:
hidden link
c) In the custom PHP function, check the product ID, if it is product "Package for 10 posts", then update the user field "post-limitation" value to: +10
https://codex.wordpress.org/Function_Reference/update_user_meta
d) Create a view to list posts which author is the current user
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
e) Use Views shortcode [wpv-conditional] to check if the found posts count [wpv-found-count] is no more than user field "post-limitation" value, then display a CRED form for user to create new post, else display a warning message and links for your user to buy more products:
https://toolset.com/documentation/views-shortcodes/#wpv-conditional
https://toolset.com/documentation/views-shortcodes/#wpv-found-count
"And it is still not clear that:
For the product "Package for 5 posts" I have Post Form "Add new Ad package." And for "Package for 10 posts" I want to "Add new Ad package 10"
Answer - With the help of CRED form "Add new Ad package" we buy (in my case) product "Package for 5 posts", and with "Add new Ad package 10" I want to buy product "Package for 10 posts".
"Package for 5 posts" and "Package for 10 posts" have different prices.
2) What are the "Add new Ad package" and "Add new Ad package 10"?
Are they CRED form links? - yes, these are CRED forms, just like in https://toolset.com/reference-site/toolset-classifieds/
How do you set up these CRED forms? - "Add new Ad package" is assigned to CPT "Packeges" and product "Package for 5 posts" is selected as "Charge payment with this form". Similarly, I want to make the CRED form "Add new Ad package 10" with the product "Package for 10 posts" assigned as "Charge payment with this form".
3) a) setup a custom numeric field, for example "post-limitation": - I created a new user field
b) and c) - as I mentioned I do not know PHP and I can not apply it well
d) and e) - it's not a problem, but now I can not do anything like I do not have a well-written function "woocommerce_order_status_completed"
I hope I have described everything right now ????
As I mentioned above, there isn't such a built-in feature within CRED commerce plugin, it need custom PHP codes, if you still need assistance for it, please provide a minimal test site with same problem, with only toolset plugins and wordpress default theme, and fill below "private detail box" with login details and ftp access, also point out the problem page URL and CRED form URL, where I can edit your PHP codes, I can setup a demo for you.
Thanks for the details, I can login your website, but please backup your website first before I do any test and debug in your website, then update this thread. thanks
Backup done.
Thanks for the help.
Your website is too slow to debug in it, I have to wait for 10 minutes to open the admin dashboard.
Here is my suggestion with detail steps:
1) Create a custom numeric field "product-post-limitation" in post type "product"
Edit those "product" posts, setup the value of field "product-post-limitation" for each product
2) setup a custom numeric user field, for example "user-post-limitation"
3) after the user purchase a product, use action hook "woocommerce_order_status_completed" to trigger a custom PHP function:
hidden link
4) In the custom PHP function, check the product ID, find the value of "product-post-limitation" of the product post, then update the user field "user-post-limitation" value to: + value of "product-post-limitation"
for example add below codes into your theme functions.php:
// define the woocommerce_order_status_completed callback
function action_woocommerce_order_status_completed( $order_id ) {
$order = wc_get_order( $order_id );
$add_user_post_limitation = 0;
foreach ( $order->get_items() as $item ) {
$product_id = $item['product_id'];
$product_post_limitation = get_post_meta($product_id, 'wpcf-product-post-limitation', true);
$add_user_post_limitation += $product_post_limitation;
}
$user_id = (int)$order->customer_id;
$org_user_post_limitation = get_user_meta($user_id, 'wpcf-user-post-limitation', true);
update_user_meta($user_id, 'wpcf-user-post-limitation', $org_user_post_limitation + $add_user_post_limitation);
};
// add the action
add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );
Thanks for the help.
Unfortunately, this does not help, because the new, extra Package that I want to have is still written as a "Draft". Consequently, it is not possible to add/buy a post that would be deducted within it.
Unless I changed your code wrong ...
As a product ID I typed "1136", and as a limit of posts to buy "3"
// define the woocommerce_order_status_completed callback
function action_woocommerce_order_status_completed( $order_id ) {
$order = wc_get_order( $order_id );
$add_user_post_limitation = 3;
foreach ( $order->get_items() as $item ) {
$product_id = $item['1136'];
$product_post_limitation = get_post_meta($product_id, 'wpcf-product-post-limitation', true);
$add_user_post_limitation += $product_post_limitation;
}
$user_id = (int)$order->customer_id;
$org_user_post_limitation = get_user_meta($user_id, 'wpcf-user-post-limitation', true);
update_user_meta($user_id, 'wpcf-user-post-limitation', $org_user_post_limitation + $add_user_post_limitation);
};
// add the action
add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 );
Let me know if I changed this wrong.
But that does not matter now, because that's not the point. The problem is still that the new / additional package is not saved as a package.
First, a new package must be saved to run your code. I think I'm right, right?
The codes I provided works in my localhost, I don't think you have followed the steps I mentioned in post:
https://toolset.com/forums/topic/additional-packages/#post-534518
Since your website is too slow to test and debug, I am not sure how do you setup in your own website, To avoid any misunderstand, please provide database dump file of your, also point out the problem page URL, and describe more details for the question:
The problem is still that the new / additional package is not saved as a package.
What is the new / additional package ?
How do you create/save it? with CRED form?
What kind of "package" do you want to setup?
I need details to test and debug it in my localhost.
And to test above PHP codes, you will need to login as a user, buy a product, for example "Package for 5 posts", and complete the payment, then login as a admin user, confirm the order, mark the order as "Complete" status, then it will trigger above custom PHP codes, update the custom user field value.
"I don't think you have followed the steps I mentioned in post" - I did everything.
I will be happy to give you all the access data and database file to my proper test page.
But I will not do that in public post. Please enable send private message.
I think it will be best as you will see and you will have access to my test page. Its design is different from your referenced https://toolset.com/reference-site/toolset-classifieds/ These differences may have an impact on understanding the problem.