Add text to WooCommerce Loop Category Count - woocommerce

I was wondering if anyone might know how to add text to the 'count function' in the Woocommerce Category Loop.
At present under each category thumbnail it shows the name of the category and in brackets the number of products in that category.
What I would like to be able to do is to add a word after the Count.
We are a non profit which provides free educational lessons.
And I would like to add the word lessons after the count.
So it would show the Category title and then - for example (3 lessons)
Any suggestions welcomed

This is the hook woocommerce_subcategory_count_html. You can find the documentation here:
https://docs.woocommerce.com/wc-apidocs/source-function-woocommerce_template_loop_category_title.html#1105-1122
I haven't tested it, but you'll need to do something like this. Now it works.
add_filter('woocommerce_subcategory_count_html', 'myFunction', 10, 2);
function myFunction($html, $category){
return ' <mark class="count">(' . esc_html( $category->count ) . ' lessons)</mark>';
}
Good luck! Let me know it it worked.

Related

Display a custom field (field type: number) as currency with commas

I have a custom field for capturing and displaying the price of items that I am using in several different places on my site (not a shopping site, prices are just displayed as simple text, the field is setup as a number field type though).
Wherever I could create a variable and echo it in a loop or directly I managed to use money_format (although I know it is already deprecated but still works in my site).
$price = get_post_meta($post, 'price_attachment_page', true);
$pricedollar = money_format("%(#10n",$price);
and then I just call the variable $pricedollar
That is working fine when I have a chance to build the code directly. My problem comes when the same field is called in different places where I cannot do much about it, I use the same field in 2 different types of lightboxes (prettyphoto and glightbox)and within justified image gallery. All displaying in caption or description fields as simple text and this happens in literally thousands of places in my site (a very large catalog site).
I have in the mean time a simple CSS where needed:
:before {
content: "$";
}
to prefix the dollar sign, but that does not help with the commas or the period and the last 2 decimal places, The price looks very awkward.
I have tried all I found out there but nothing works.
This one looked promising and it is even on the documentation of ACF, I have it running on my functions.php but it does nothing.
add_filter( 'acf/format_value/name=price_attachment_page', 'format_number_as_currency', 10, 3 );
function format_number_as_currency( $value, $post_id, $field ){
if($value > 0) :
$value = '&dollar;' . number_format(($value), 0, '.', ',');
endif;
return $value;
}
I am sure if I alter glightbox, prettyphoto and JIG I can probably intercept where they process that specific field and add some code but I was wondering if there is a way to output that field with the currency format sitewide.
I have read at like at least 30 places some ideas to handle this and they all mention either echo or jquery ideas, I am not sure how I can make that work in the 3 places where I need that information displayed (lighboxes and responsive gallery).

fixed price for specific categories

I would like to know some questions. We have a school where in a short time we will begin to enroll people online, especially with the Covid-19. We only charge 1 tuition even if the same student enrolls in several options. So I would like the final price to be the same regardless of the quantity of items. Well, I have found a code that solves me in part since the coupons do not work for me, discounts do not apply this for me, as a last option I could be worth it temporarily:
add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );
function change_calculated_total( $total, $cart ) {
return $total = 40;
}
So if there are 3/4 (maximum number of items admitted to the basket) they will only pay 40€
This code is from here: Change Cart total using Hooks in Woocommerce 3.2+
This option is not the most correct, since it does not show a discount, it simply "tricks the system". But I would like this rule to affect the articles of a specific categories, only the enrollment, but the rest of the items in my store in other categories are charged at normal price. Could you please help me those 2 questions? Thanks in advance

show added to cart message in woocommerce

As mentioned above I want to display "product added to cart message" in woocommerce.
I know there is some kind of built in function
wc_add_to_cart_message()
If I paste it in index page together with
wc_print_notices();
Like this:
wc_add_to_cart_message('products');
wc_print_notices();
wc_add_to_cart_message('products');
wc_print_notices();
then my current output is:
“” has been added to your cart.
My desired output is that it would return that particular product name together with a message.
but what would be the proper way of using it?
Or is there some other way?
In that function you actually have to give product id or array of product ids, so your line should look like:
wc_add_to_cart_message($product_id);

How to change price according to variation in Woocommerce cart

I have two variations in my product. In cart page I need to choose the variations and with respective to variations I need to display the price.
How this can be done? Any track is welcome.
Kindly help me because I have searched a lot a solution for this, and I didn't anything yet that is working as I expect.
I have tried the following code in cart.php to get the variations.
<?php if( ! empty( $_product ) && $_product->get_type( 'variation' ) ){
$variation_attributes = $_product->get_variation_attributes();
$first_attribute = array_slice($variation_attributes, 0,1);
$second_attribute = array_slice($variation_attributes, 1,2); } ?>
By $first_attribute and $second_attribute, I populate the variations in a select box.
I have two attributes and four variations. So according to the variation I need to display the Price. I am not using third party PlugIn.
I believe this is already a part of WooCommerce's set up - as long as you have the variation set up specifically for X-license and X-plan you should be able to set the price to that variation.
Variation Data
Each variation may be assigned.
General:
Regular Price (required) – Set the price for this variation.
Source and full documentation: https://docs.woocommerce.com/document/variable-product/

Wordpress/WooCommerce - Unique Product Name

Is it possible to add a unique name to a specific product when it's added to the shopping cart using the woocommerce API?
For example suppose I sell pets. The user decides he wants a dog named spot. He then clicks on a particular dog breed (the product) say border collie and that product should appear in the shopping cart as a border collie named spot.
To answer your question, yes. You can change things in your own code by adding filters. So for example, say you want to change the name of the product in the cart. In wp-content/plugins/woocommerce/templates/cart/cart.php there is a filter called 'woocommerce_cart_item_name' where the title is outputted. You can modify this in your own code like so:
function your_function( $title, $cart_item, $cart_item_key ){
/*code to modify title*/
return $title;
}
add_filter('woocommerce_cart_item_name','your_function',10,3);
You could add this to the functions.php of your theme.
How you get the name spot in this function depends on your situation.
Read more about filters at https://codex.wordpress.org/Function_Reference/add_filter

Resources