Home › Forums › WoodMart support forum › show related product at top of products that are out of stock
show related product at top of products that are out of stock
- This topic has 20 replies, 2 voices, and was last updated 10 months, 4 weeks ago by Hung Pham.
-
AuthorPosts
-
November 28, 2023 at 7:33 pm #516562
av_admin_1984ParticipantHello,
Is it possible to show the related product at top of the page only if the product status is “out of stock”
November 29, 2023 at 12:21 pm #516757
av_admin_1984ParticipantHello
I found this code and edit some part, it should work but it won’t!function xtemos_display_related_products() { global $product; // Check if the current product is out of stock if (!$product->is_in_stock()) { $related_ids = wc_get_related_products($product->get_id(), 4); // Exclude out of stock products from the related products list $args = array( 'post_type' => 'product', 'post__in' => $related_ids, 'post_status' => 'publish', 'posts_per_page' => 4, 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT LIKE' ) ) ); $related_query = new WP_Query($args); if ($related_query->have_posts()) { echo '<div class="related-products">'; echo '<h2> Check out the available products! </h2>'; echo '<ul>'; while ($related_query->have_posts()) { $related_query->the_post(); global $product; echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; } echo '</ul>'; echo '</div>'; wp_reset_postdata(); } } } add_action('woocommerce_single_product_summary', 'xtemos_display_related_products', 5);
Would you please tell me is that right and is that compatible with latest woocommerce and woodmart ?
November 29, 2023 at 7:04 pm #516954
Hung PhamKeymasterHi av_admin_1984,
Thanks for reaching to us,
The issue could be solved in case you’re using Custom Layouts, we have a special “Hook” element in Elementor that you can place to your custom layout and then the plugin will be able to add its custom content there.
But we don’t know which one exactly it needs. You can either try to select all hooks one by one or contact plugin developers for help. https://xtemos.com/docs-topic/custom-hooks-and-plugins-compatibility/
Regards,
December 1, 2023 at 7:09 pm #517711
av_admin_1984ParticipantHello
You have access to my site, please cheek that
Thanks
December 2, 2023 at 10:22 am #517786
Hung PhamKeymasterHi av_admin_1984,
I got issue when tried to edit Custom Single Product layout.
You should deactivate all plugins (except Required Plugins) and then reactivate them one by one. This makes it very easy to isolate the plugin causing problems.
Regards,
- This reply was modified 11 months ago by Hung Pham.
December 2, 2023 at 8:32 pm #517907
av_admin_1984ParticipantHi Hung,
Thanks for reply
1-This site is the staging from the live site, so you can change anything
2-In this post I asked for help https://xtemos.com/forums/topic/woocommerce-group-attributes-plugins/https://xtemos.com/forums/topic/woocommerce-group-attributes-plugins/ so those plugins are responsible or something else,
3-Please remove those screenshots and never share my site in public again
4- You have access to cpanel so that you can test anything’sThanks
December 4, 2023 at 12:53 pm #518195
Hung PhamKeymasterHi av_admin_1984,
Thanks for reaching to us,
1. I fixed the issue, however, you have not added Custom Code yet, please try to add to functions.php file in Child theme and use have a special “Hook” widget in Elementor to see if it works.
2 > 4. Our colleague handled that topic, so he will checks your replies.
Regards,
January 12, 2024 at 9:09 pm #529451
av_admin_1984ParticipantHi again Hung Pham
I give you access to WordPress and cpanel and want to add the ability to show related stock products for only those out-of-stock products at the top of the page
I added that code in the first comment on this page
Please check and tell me why the related product not working
Not that, There are many custom codes in my theme, comment on them but don’t remove them at all.
January 15, 2024 at 12:26 pm #529825
Hung PhamKeymasterHi av_admin_1984,
I really appreciate your patience.
I removed screenshots, and I can see that Related Products section is showing on my end. Did you resolve by yourself?
Regards,
- This reply was modified 11 months ago by Hung Pham.
January 15, 2024 at 1:20 pm #529867
av_admin_1984ParticipantHi
It’s defult woodmart elements
I want to show related products, in top of page of single product that was out of stock
I don’t know was it clear or not
January 15, 2024 at 1:22 pm #529868
av_admin_1984ParticipantI mean it has condition
If single product was out of stock, when user open that, at the top of page, should show the related productIts only for out of stock products
January 15, 2024 at 6:01 pm #530042
Hung PhamKeymasterHi av_admin_1984,
I checked the problem and I saw that you use different hooks, so please choose one hook and everything will work.
I attached screenshots in Private area.
Regards,
January 15, 2024 at 8:33 pm #530100
av_admin_1984ParticipantI do have not private area and I told your coluge before, that you can just upload the image to my site and let me know to cheek that
January 15, 2024 at 8:43 pm #530103
av_admin_1984ParticipantI crated the Layout for single product named “Out Of Stock Product”, it’s empty
Please import a demo for this single layout,
crate the related product with correct hook to show the related product in just out of products
send me email or add images in my wordpress media so I can cheekJanuary 16, 2024 at 6:55 pm #530472
Hung PhamKeymasterHi av_admin_1984,
Here are screenshots (no details, just Custom Code)
https://monosnap.com/file/bfHKFO2myQldKO32ePJa4ipmBJS2Du
https://monosnap.com/file/FNaWJ7yI5XHVNPQ7wYniX6Eg3xtGYRRegards,
January 16, 2024 at 7:27 pm #530484
av_admin_1984ParticipantHi
Did you even understand what I’m looking for?
I except after a month, you finish this task and close this topic, but give me a screenshot and when I select and add that function, it does not work…
Are you Human or you are AI?
January 16, 2024 at 8:30 pm #530515
Hung PhamKeymasterHi av_admin_1984,
The issue has been resolved. https://prnt.sc/tyQ6qGWP71Ak
The Single product layout you had a different hook than in the custom code, which is why it did not work.
Regards,
January 16, 2024 at 11:14 pm #530556
av_admin_1984ParticipantThis is very ugly and doesn’t look like the Related Product
What should I do about that?January 17, 2024 at 6:46 pm #530909
Hung PhamKeymasterHi av_admin_1984,
By default, customization is out of basic support, but we made an exception to help you to run the custom code, if you find it looks ugly then need to style it by yourself.
Thanks for understanding our limitation.
Regards,
January 17, 2024 at 6:51 pm #530911
av_admin_1984ParticipantThanks for your exception
I expect this code will run and look like the related product not just show the link,
I don’t want to crate it for me, Just consider and add it to next updateJanuary 18, 2024 at 7:00 am #531013
Hung PhamKeymasterHi av_admin_1984,
Keep us in mind for future questions and concerns, we’re always here to help!
Regards,
-
AuthorPosts
- You must be logged in to create new topics. Login / Register