-
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 1 week, 4 days 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
January 8, 2025 at 8:54 am #1474813Hi,
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,
IsmaelJanuary 10, 2025 at 4:16 am #1474902Great, 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.
January 10, 2025 at 6:07 am #1474909Hi,
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,
IsmaelJanuary 10, 2025 at 6:23 am #1474912I 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.
January 10, 2025 at 7:02 am #1474918Hi,
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,
IsmaelJanuary 10, 2025 at 7:02 am #1474919You are awesome!
Can you please please tell me how to adjust the Price font size? or get a CSS code for that?January 10, 2025 at 7:06 am #1474920Hi,
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,
IsmaelJanuary 10, 2025 at 7:18 am #1474921thanks!!!!!!
-
AuthorPosts
- You must be logged in to reply to this topic.