Your CRED form is designed to add Product "Ogloszenie - standard" to the order. This Product has an ID of 45. Your code is written to only add the custom field value to Product ID 1175. Can you help me understand why these IDs are different?
See the attached screenshots.
Term "intop" is a paid option associated with product ID 1175.
This option is activated with another CRED form - ID 3845 (screen "intop.jpg").
Which order was placed when you edited the "top top" post with CRED Commerce form 3845? These are the only orders I see that include product 1175, and the date when the order status changed to "Complete":
#4512 - 12 August
#4504 - 11 August
#4503 - 11 August
#4501 - 11 August
#4599 - 14 August
#4597 - 14 August
#4596 - 14 August
These were all "Complete" before I suggested the changes to your code. Please start from the beginning with new posts.
1. Submit CRED Commerce form 39 to create a new post. This adds product 45 into your cart.
2. Checkout, then mark the order complete.
3. What is the post ID created by CRED?
4. What is the order ID for your 1st WC order?
5. Now edit the post from #3 using CRED Commerce form 3845. This adds product 1175 to your cart.
6. Check out, then mark the order complete.
7. What is the order ID for your 2nd WC order?
Thank you.
Ok, I added new posts.
"3. What is the post ID created by CRED?
4. What is the order ID for your 1st WC order?
7. What is the order ID for your 2nd WC order?" - I do not understand
Now as the "Osobowe" view is set to "Order" on [Field - In Topp][Descending][As a number], only those posts that I activated as "In Top" with CERD from ID-3845 are visible.
All others are invisible.
Also the css class (the background of the post that has been "In Top") and the shortcode term "intop" (the "PODBIJ" button does not disappear) does not work, but that's understandable after the change to functions.php. I hope I can improve it later 🙂
("Order": [Field - In Topp][Descending][As a number] - I have to undo this setting for now, but you have access so if you need it you can change it)
7. What is the order ID for your 2nd WC order?" - I do not understand
When you click "PODBIJ" to submit CRED Commerce form 3845, product "Ogloszenie - Top" is added to your cart. Then you checkout, and a new order is generated. I was asking for the new order ID, but I don't think it's important now. You said the new Osobowe posts are appearing at the top of the list, so I think this is working correctly. By default, the posts should have the "Normal" value for this custom field. If CRED Commerce form 3845 is submitted, the post should have the "In Top" value for custom field. Please confirm this is working as expected.
Now as the "Osobowe" view is set to "Order" on [Field - In Topp][Descending][As a number], only those posts that I activated as "In Top" with CERD from ID-3845 are visible.
All others are invisible.
Old posts, created before the "In Top" field was added, will not have a saved value for this field, so they will not appear in the list. This can be resolved by resaving the old posts with the default "Normal" value for the custom field. All new posts will have the default value applied unless they are set to "In Top" with CRED Commerce form 3845, so they will all appear in the list. I hope this helps clear things up.
Now as the "Osobowe" view is set to "Order" on [Field - In Topp][Descending][As a number], only those posts that I activated as "In Top" with CERD from ID-3845 are visible.
All others are invisible.
I'm talking about new posts that have been added after the changes.
If they are not selected / marked as "in top" they will not appear on the list of posts.
I understand, if Osobowe posts are created in wp-admin, the default value will be set automatically. However I forgot that we need to set the default value when Osobowe posts are created by CRED.
There are two ways to set the default value:
1. Use cred_save_data hook to add the default value to any Osobowe post created by CRED:
add_action('cred_save_data', 'cred_add_default_in_topp',10,2);
function cred_add_default_in_topp ($post_id, $form_data)
{
// IDs of all forms that create Osobowe posts
$forms = array( 1, 2, 3 );
if (in_array($form_data['id'], $forms))
{
update_post_meta($post_id, 'wpcf-in-topp', 1 );
}
};
Modify the $forms array to include all the IDs of forms that create Osobowe posts.
2. Add the "in-topp" input field to your CRED forms and set its value to "1", then hide the input field using CSS.
#1 is probably the best option, but as you add and remove CRED forms you will probably need to update your hook to work with other form IDs.
It works, but the order is gone. Please, see screen "in-top.jpg".
My fault. I forgot to remove the code:
$.each($('.in-top'), function() {
$(this).prependTo(".offers");
});
How did I remove the order is correct.
The setting should be like on the screen "setup-intop.jpg".
Thank you very much for help.