-
AuthorPosts
-
January 2, 2025 at 7:57 pm #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!January 3, 2025 at 5:49 am #1474505Hey 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,
IsmaelJanuary 3, 2025 at 7:56 pm #1474594Ok, 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!
January 3, 2025 at 7:58 pm #1474595So 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.
January 4, 2025 at 8:35 pm #1474636Can you get me some code for this please? thanks for your time
January 6, 2025 at 12:16 am #1474687Please let me know on this when you can. Really appreciate this. thanks
January 6, 2025 at 7:09 am #1474703Hi,
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,
IsmaelJanuary 7, 2025 at 2:22 am #1474743I 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.
January 7, 2025 at 2:23 am #1474744I don’t understand about the “bought in the past month” custom field or how to add that.
January 7, 2025 at 5:52 am #1474753Hi,
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,
IsmaelJanuary 7, 2025 at 6:10 am #1474754The site is working. Let me know
January 7, 2025 at 6:32 am #1474758Hey!
The site is not loading our end. Please check the screenshot in the private field.
Regards,
IsmaelJanuary 7, 2025 at 6:37 am #1474759The site is working. I just went to the product page: https://priverproducts.com/product/freeze-flat/
January 7, 2025 at 6:39 am #1474760Hey!
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!
IsmaelJanuary 7, 2025 at 5:01 pm #1474781Sorry about that. They said to please try now. thanks
January 8, 2025 at 2:13 am #1474801My hosting guy says it should be good now. Please let me know. thanks
-
AuthorPosts
- You must be logged in to reply to this topic.