Viewing 16 posts - 1 through 16 (of 16 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 4 days, 11 hours 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

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