Viewing 24 posts - 1 through 24 (of 24 total)
  • Author
    Posts
  • #1474490

    Hello,
    Can I get a CSS code that would Add line of text under Reviews on each of the Products pages? See screenshot for what I am looking for. Thanks for all your help!

    #1474505

    Hey bemodesign,

    Thank you for the inquiry.

    You can add this template hook in the functions.php file:

    add_action('woocommerce_single_product_summary', 'av_show_product_sales', 6);
    
    function av_show_product_sales() {
        global $product;
    
        if (!$product instanceof WC_Product) {
            return;
        }
    
        $product_id = $product->get_id();
        $start_date = date('Y-m-01', strtotime('first day of last month'));
        $end_date = date('Y-m-d', strtotime('tomorrow'));
    
        $args = [
            'status' => ['wc-completed', 'wc-processing'],
            'limit' => -1,
            'date_created' => $start_date . '...' . $end_date,
        ];
    
        $orders = wc_get_orders($args);
        $sales_count = 0;
    
        foreach ($orders as $order) {
            foreach ($order->get_items() as $item) {
                if ($item->get_product_id() == $product_id) {
                    $sales_count += $item->get_quantity();
                }
            }
        }
    
        if ($sales_count > 0) {
            echo '<p class="product-sales-count">' . esc_html($sales_count) . '+ bought in the past month</p>';
        }
    }
    

    Best regards,
    Ismael

    #1474594

    Ok, I added this code to the Snippets plugin. See attached. But how do I add the text that I want for each individual product? I want it to say different thing for each product. Let me know, thanks!

    #1474595

    So basically, it is just my own text that I will input, not real sales or numbers pulled from data.

    And can the text size be the same as the “review” text that is above it, and black for the text color.

    Thanks!

    • This reply was modified 1 week, 4 days ago by bemodesign.
    #1474636

    Can you get me some code for this please? thanks for your time

    #1474687

    Please let me know on this when you can. Really appreciate this. thanks

    #1474703

    Hi,

    Thank you for the update.

    You can save the part “bought in the past month” as a custom field called “_sales_text_last_month” and adjust the filter in the functions.php file as follows.

    add_action('woocommerce_single_product_summary', 'av_show_product_sales', 6);
    
    function av_show_product_sales() {
        global $product;
    
        if (!$product instanceof WC_Product) {
            return;
        }
    
        $product_id = $product->get_id();
        $start_date = date('Y-m-01', strtotime('first day of last month'));
        $end_date = date('Y-m-d', strtotime('tomorrow'));
    
        $args = [
            'status' => ['wc-completed', 'wc-processing'],
            'limit' => -1,
            'date_created' => $start_date . '...' . $end_date,
        ];
    
        $orders = wc_get_orders($args);
        $sales_count = 0;
    
        foreach ($orders as $order) {
            foreach ($order->get_items() as $item) {
                if ($item->get_product_id() == $product_id) {
                    $sales_count += $item->get_quantity();
                }
            }
        }
    
        if ($sales_count > 0) {
            $custom_message = $sales_count . '+ ' . get_post_meta($product_id, '_sales_text_last_month', true);
            echo '<p class="product-sales-count">' . esc_html($custom_message) . '</p>';
        } 
    }
    

    Best regards,
    Ismael

    #1474743

    I replaced the code with what you gave me, but I still don’t see the line of text. Is there something I need to do beside add this code to the “Snippets” plugin? see attached for where I added your code.

    #1474744

    I don’t understand about the “bought in the past month” custom field or how to add that.

    #1474753

    Hi,

    We tried adding the custom field, but the site is not loading on our end anymore. Are you working on it? To learn more about how to add custom fields, please check this link.

    // https://woocommerce.com/document/custom-product-fields/

    Best regards,
    Ismael

    #1474754

    The site is working. Let me know

    #1474758

    Hey!

    The site is not loading our end. Please check the screenshot in the private field.

    Regards,
    Ismael

    #1474759

    The site is working. I just went to the product page: https://priverproducts.com/product/freeze-flat/

    #1474760

    Hey!

    It’s not loading on our end. Did you install a security plugin? Please disable it temporarily so that we can access the site again.

    Cheers!
    Ismael

    #1474781

    Sorry about that. They said to please try now. thanks

    #1474801

    My hosting guy says it should be good now. Please let me know. thanks

    #1474813

    Hi,

    We edited the product “The Original Freeze Flat” and added the custom field sales_text_last_month, set its value to “bought in the past month”. We also edited av_show_product_sales function and temporarily disabled the condition “if ($sales_count > 0)”so that you can see the modification (see private field). The product doesn’t have any orders yet. You can re-enable the condition if you wish.

    Best regards,
    Ismael

    #1474902

    Great, but can you remove the 0+ at the beginning? I don’t want it to actually track sales, I will fill in the text myself. See screenshot.

    And lastly, could you make the font a couple sizes smaller please?

    Let me know.
    Thanks!

    • This reply was modified 5 days, 2 hours ago by bemodesign.
    • This reply was modified 5 days ago by bemodesign.
    #1474909

    Hi,

    If you want to add a custom text with random sales numbers, just edit the value of the sales_text_last_month custom field and then adjust the filter a bit.

    add_action('woocommerce_single_product_summary', 'av_show_product_sales', 6);
    
    function av_show_product_sales() {
        global $product;
    
        if (!($product instanceof WC_Product)) {
            return;
        }
    
        $custom_message = get_post_meta($product->get_id(), '_sales_text_last_month', true);
    
        if (!empty($custom_message)) {
            printf('<p class="product-sales-count">%s</p>', esc_html($custom_message));
        }
    }

    Again, you can refer to this documentation on how to add or update custom fields: https://woocommerce.com/document/custom-product-fields/

    Best regards,
    Ismael

    #1474912

    I edited the last request before I saw you answered. Did you see the new request? I can add the custom part to each product. Just need the first number part gone and smaller text.

    And how would I move it below the Review?

    Thank you!!!!

    • This reply was modified 5 days ago by bemodesign.
    #1474918

    Hi,

    We added this script to move the sales count under the ratings

    function ava_custom_script_move_product_sales_count()
    {
        ?>
        <script type="text/javascript">
            (function ($)
            {
                $(document).ready(function () {
                    var salesCount = $('.product-sales-count');
                    var productRating = $('.woocommerce-product-rating');
    
                    salesCount.insertAfter(productRating);
                });
            })(jQuery);
        </script>
        <?php
    }
    
    add_action('wp_footer', 'ava_custom_script_move_product_sales_count', 9999);
    
    

    And added this code in the Quick CSS field to adjust the style a bit.

    .product-sales-count {
    	font-size: 0.8em;
    	margin-top: 0;
    	top: -10px;
    	position: relative;
    }

    Best regards,
    Ismael

    #1474919

    You are awesome!
    Can you please please tell me how to adjust the Price font size? or get a CSS code for that?

    #1474920

    Hi,

    You can use this css code to adjust the product price:

    #top .price, #top .price span, #top del, #top ins {
    	display: inline;
    	text-decoration: none;
    	font-size: 30px;
    	line-height: 24px;
    	font-weight: 600;
    }

    If you have any further questions, we kindly ask that you open a new thread. As threads become longer in the forum, they can become harder to manage, tend to drift off-topic, and make it more difficult for users to search for solutions. Keeping threads focused on the original topic helps us track resolutions more effectively and allows users to more easily find answers to similar issues.

    Thank you!

    Best regards,
    Ismael

    #1474921

    thanks!!!!!!

Viewing 24 posts - 1 through 24 (of 24 total)
  • You must be logged in to reply to this topic.