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

Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #516562

    av_admin_1984
    Participant

    Hello,

    Is it possible to show the related product at top of the page only if the product status is “out of stock”

    #516757

    av_admin_1984
    Participant

    Hello
    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 ?

    #516954

    Hung Pham
    Keymaster

    Hi 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,

    #517711

    av_admin_1984
    Participant

    Hello

    You have access to my site, please cheek that

    Thanks

    #517786

    Hung Pham
    Keymaster

    Hi 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.
    #517907

    av_admin_1984
    Participant

    Hi 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’s

    Thanks

    #518195

    Hung Pham
    Keymaster

    Hi 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,

    #529451

    av_admin_1984
    Participant

    Hi 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.

    #529825

    Hung Pham
    Keymaster

    Hi 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.
    #529867

    av_admin_1984
    Participant

    Hi

    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

    #529868

    av_admin_1984
    Participant

    I mean it has condition
    If single product was out of stock, when user open that, at the top of page, should show the related product

    Its only for out of stock products

    #530042

    Hung Pham
    Keymaster

    Hi 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,

    #530100

    av_admin_1984
    Participant

    I 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

    #530103

    av_admin_1984
    Participant

    I 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 cheek

    #530472

    Hung Pham
    Keymaster

    Hi av_admin_1984,

    Here are screenshots (no details, just Custom Code)

    https://monosnap.com/file/bfHKFO2myQldKO32ePJa4ipmBJS2Du
    https://monosnap.com/file/FNaWJ7yI5XHVNPQ7wYniX6Eg3xtGYR

    Regards,

    #530484

    av_admin_1984
    Participant

    Hi

    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?

    #530515

    Hung Pham
    Keymaster

    Hi 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,

    #530556

    av_admin_1984
    Participant

    This is very ugly and doesn’t look like the Related Product
    What should I do about that?

    #530909

    Hung Pham
    Keymaster

    Hi 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,

    #530911

    av_admin_1984
    Participant

    Thanks 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 update

    #531013

    Hung Pham
    Keymaster

    Hi av_admin_1984,

    Keep us in mind for future questions and concerns, we’re always here to help!

    Regards,

Viewing 21 posts - 1 through 21 (of 21 total)