Skip Navigation

[Resolved] Additional packages

This support ticket is created 7 years, 5 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)

Tagged: 

This topic contains 50 replies, has 2 voices.

Last updated by Bochnacki 7 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#534664

"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 did exactly that ????

Probably your PHP code works fine, but you can not verify it because "Package for 10 post" is not activated (even after approval). It is saved as 'Draft'.
"Package for 5 posts" works well and always works.

#534681

Your website is too slow to access the admin dashboard.

I am not sure how do you setup the product "Package for 10 post" post, why do you need to setup the product "Package for 10 post" as inactivated?
Why your user can buy the product even the product is not activated?

To avoid new misunderstand, please provide the database dump file, and describe detail steps to duplicate same problem, how and where I can buy the product "Package for 10 post" post.
What is you expected to see after the order completed.

And as I mentioned above, there isn't such a feature within Toolsets, it needs custom codes, according to our support policy, it is out the range of Toolset support.
https://toolset.com/toolset-support-policy/
you can also check out our certified partners for it:
https://toolset.com/consultant/

#534699

Maybe the test page I gave you access is not a speed daemon, but I can log in to the admin panel without any problem. Does not matter.

I want to give you access to my REAL test page, but despite my request, you do not provide me with the ability to send private messages.

And in fact, we still do not understand.
In https://toolset.com/forums/topic/additional-packages/#post-532604 you wrote:
"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 the limitation after the user purchases a product.
But the above thread is for doing action after user submit a CRED form. "
My fault - I missed or did not immediately understand this statement.
I do not ask for help to limit the posts depending on the product.
I ask for help in making new/additional Packages, so that I can plug in the right products.

"Add new Ad package" (in my case it is "Add new Ad package 5" which works well) this is CRED form. 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".

I hope this clarifies my problem 🙂

#535394

As your request, I have enabled below private detail box, please provide these:
1) the database dump file, this way I can debug it without breaking your website.
2) point out the problem page URL and CRED form URL

Thanks

#536429

Thanks for the details, I am checking it in your website, since it isn't in English, it might take some time to test and debug.

#536466

Since your website isn't in English, to avoid any misunderstand, I need you confirm these:
I assume we are talking about this problem:
1) Login with user name "info"
2) Open URL
hidden link
there is a text "Ogłoszenia w Pakiecie:" and the number "1"
3) When user "info" buy a product "Pakiet 5",which custom post field "Product post limitation" value is "2"
you are going to achieve this:
"Ogłoszenia w Pakiecie:" + = 2
If it is, where is the "Ogłoszenia w Pakiecie:" form? how do you setup it, is it the custom user field "User total available ad credits "?

4) When user "info" create a post with CRED form "Ogłoszenie w kat. Osobowe - pakiet",
you are going to achieve this:
"Ogłoszenia w Pakiecie:" - = 1

please confirm above questions, or correct me if there is other thing missing.

#536535

1) Login with user name "info" - Yes, but it is not an administrator login. Login administrator I gave you separately.

2) - "Ogłoszenia w Pakiecie:" means "the number of remaining posts to add"

3) - "Product post limitation" - This is the post field in the "Fee Config" field group, created according to your instructions - https://toolset.com/forums/topic/additional-packages/#post-534518 . It is not useful now or used, but I have not deleted it yet.

"Ogłoszenia w Pakiecie:" + = 2 - The number of allowed posts in the Package is set in the "Number of ads" field in the "Ad Package Group" field assigned to the product.

Product "Pakiet 5" I set on 2 possible posts for faster verification when / if the package is exhausted, it's just for testing. Ultimately, as soon as the site will be online will be 5 posts, according to the name "package 5".
Let's leave 2 possible posts for product "Pakiet 5".

If it is, where is the "Ogłoszenia w Pakiecie:" form? how do you setup it, is it the custom user field "User total available ad credits "? - There is no "Classifieds in Package:" form. This is custom user field "User total available ad credits".

4) "Ogłoszenia w Pakiecie:" - = 1 - Yes. Shows that only 1 post can be added.

#536965

Thanks for the details, checking it in your website, will feedback if there is anything found

#537002

A1) "Ogłoszenia w Pakiecie:" + = 2
Since you did not follow my instructions, you have modified the field slug from "user-post-limitation" to "user-total-available-ad-credits", so the PHP codes won't work
I have added below codes into your theme/functions.php as below:

// 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-total-available-ad-credits', true);
	update_user_meta($user_id, 'wpcf-user-total-available-ad-credits', $org_user_post_limitation + $add_user_post_limitation);
}; 
         
// add the action 
add_action( 'woocommerce_order_status_completed', 'action_woocommerce_order_status_completed', 10, 1 ); 

The only thing change is from "user-post-limitation" to "user-total-available-ad-credits"
Can you confirm it first? I just tested it in your website, and it does work, now it shows:
Ilość ogłoszeń dostępnych do publikacji: 7

Q2) "Ogłoszenia w Pakiecie:" - = 1
It is a new question, I can work on it when you confirm above does work. thanks

#537123
package-error.jpg

Luo Yang, thank you very much for your help but this is not a good solution.
Yes, the available posts are now shown and counted, but there are some errors.
1. Once purchased "Package 5" is fine, but "Package 10" is still saved as Draft.
2. Available posts are counted by two product fields: "Product post limitation" and "Number of ads", which is double - error.
3. If in the field "Number of ads" I do not enter anything in the admin panel purchased Package does not show either "Original number of ads" or "Package number of ads allowed". On the 'my account' page, the effect is the same as on the screen "package-error.jpg".

In my opinion, counting posts and limiting their quantity will not fix the problem.
I think this - https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/ is the solution to my problem, but when I use this solution nothing changes. Either something bad I do or I do not understand... Anyway, I can not apply it.

#537460

I have asked you to confirm what you are going to achieve in post:
https://toolset.com/forums/topic/additional-packages/page/2/#post-536466
And you confirm it in post:
https://toolset.com/forums/topic/additional-packages/page/2/#post-536535

So I setup the PHP codes as your request:
https://toolset.com/forums/topic/additional-packages/page/2/#post-537002

But you say it is not a good solution, so there might be a lots of misunderstands in this thread.

As I mentioned above, the thread you mentioned above:
https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/
It is using CRED action hook "cred_save_data" to update the post title, here is the document for the action hook "cred_save_data"

About the product "Pakiet 10", I tried these in your website:
Login as user "info", open URL
hidden link
click link "WYKUP PAKIET 10", complete the purchase.
Login with admin user "automa", complete the order.
Login as user "info", open URL
hidden link
I can see the number "Ilość ogłoszeń dostępnych do publikacji" was added to 3+3 = 6

So the codes does work for the product "Pakiet 10", and it is working for my solution:
https://toolset.com/forums/topic/additional-packages/#post-532604

In your new screenshot:
hidden link
The new post "CRED Auto Draft e0fdd5116f3c8469dd6eb64c4195fe75" , the post status is "Published", it is not draft post, which is different from what you say:
extra Package that I want to have is still written as a "Draft"
https://toolset.com/forums/topic/additional-packages/#post-534632
There is a text "Draft" in the post title, that is because you did not setup the post title in the CRED form, so wordpress will setup a post title automatically. After you confirm So it is a published post, not a draft post

To avoid more misunderstand, please describe more details for what you are going to achieve:
in the screenshot
hidden link
What do you expect to see in the column "Original number of ads"? how do you expect to setup the column value?
What do you expect to see in the column "Package number of ads allowed"? how do you expect to setup the column value?
Where and how can I see the "My account " page,
What do you expect to see in the section "Activate package"?

I need details to test and debug it in your website. thanks

#537556
package-normal.jpg

"What do you expect to see in the column "Original number of ads"?" -
1. (red on screen "package-normal.jpg") - the number of posts available in the package - that is when I purchase the package, but I have not added yet another post.

"What do you expect to see in the column "Package number of ads allowed"?" -
2. (red on screen "package-normal.jpg") - the number of posts STILL available in the package - for example: I purchase "Package 10", where the total number of posts is 10, I have already added 7 posts, so here should be shown 3.

"What do you expect to see in the section "Activate package"?" -
3. (red on screen "package-normal.jpg") - Package Name according to order number.

#537772
add-other-category.jpg

I thought about this solution https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/ because it seems to me that it gives you the ability to create any number of packages, and thus the ability to add posts in different categories. But I may be wrong.
Only the posts in the "Osobowe" category can now be added to the package. I would also like to be able to add in the Package posts in other categories, such as "Dostawcze" (screen "add-other-category.jpg").
The CDER form for posts in the "Dostawcze" category is ready ("Ogłoszenie w kat. Dostawcze - pakiet" ID: 1731) but will not be shown after clicking on the "Dostawcze" link (screen "add-other-category.jpg") because it is not in the running package.
I hope I described it clearly 🙂

Maybe you have an idea how to solve this problem?

#538414

Thanks for details, can we handle each question one by one? this will help other users to find the answers.
1)"What do you expect to see in the column "Original number of ads"?" -
1. (red on screen "package-normal.jpg") - the number of posts available in the package - that is when I purchase the package, but I have not added yet another post.

a) I disabled the plugin in your website "WooCommerce - Autocomplete Orders", it skips the action hooks of CRED commerce plugin
b) Added below codes in your theme/functions.php:


add_action('woocommerce_order_status_completed','my_hook_func',10,1);
function my_hook_func($order_id)
{
	$cred_form_id = get_post_meta($order_id, '_cred_form_id', true);
	if(
		in_array($cred_form_id, array(1772, 566)) // if it is CRED form 1772 or 566
		){ 
		
		$product_id = $data['cred_product_id']; // get the Product ID
		$package_id = get_post_meta($order_id, '_cred_post_id', true); // get the Package 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;
		}
		update_post_meta($package_id, 'wpcf-original-number-of-ads', $add_user_post_limitation); //setup original-number-of-ads field value
	}
}

Please test again, check if it is what you want,

2) What do you expect to see in the column "Package number of ads allowed"?
It needs other custom codes, please confirm above question first, then create new thread for the new question, you can assign it to me directly

3) What do you expect to see in the section "Activate package"? -
Please provide the details to see the problem, where and how I can see the the ""Activate package" of your screenshot, same as above, it is a new question, create new thread for it. thanks

#538576
package-error-2.jpg

Luo Yang, thank you for the help, but we are starting to roll around ...
I would like to describe for the third time what is to be in the "Active Package is:" ...
On the issue of "Package number of ads allowed" you tell me to make a separate thread ...

There is nothing shown in admin panel in "Original number of ads" for" CRED form ID=566" - nothing is shown because in product "Package 5" the field "Number of ads" is empty. But if it is not empty it will be counted once the "Product post limitation" field ... That's too bad ...
I now purchased "Package 5" (screen "packege-error-2.jpg") - "Active Package is:" is good, shows the correct name (though not quite good, because the page is "Package Order #2059", and in the admin panel the order number is "#2060 ", But the "Number of ads available for publication:" field is "0 ".
When I buy "Package 10", it does not change, even though on hidden link I see that I have purchased a "Package 10".

I thank you for your hard work and commitment, but more and more things stop working, and questions and problems begin to multiply.
Besides, I'm afraid that it will not help to solve my problem globally, as I wrote here https://toolset.com/forums/topic/additional-packages/page/2/#post-537772
You have focused on the ability to assign the right number of posts to a given Product/Package, but this is only part of the problem. It remains a matter of being able to add posts in different categories.
If I can add/copy Packages, then each of them can be assigned to the corresponding product and thus determine the number of possible posts.

Can not really expand topic https://toolset.com/forums/topic/add-new-ad-package-when-cloned-does-not-formatpublish-packages-as-normal/ ?