The goal is to show the total price of a purchase of a particular product based on the quantity ordered. Example if you wish to buy 3 mugs for $50, then a “Total: $150” will be shown. If you wish to changed it to something like quantity of 5, then it will display “Total: $250”, and so on..
Now. which hook to use? I particularly choose “woocommerce_single_product_summary”.
You can see it on in content-single-product.php in the templates folder of woocommerce. It’s something like below:
/** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title - 5 * @hooked woocommerce_template_single_rating - 10 * @hooked woocommerce_template_single_price - 10 * @hooked woocommerce_template_single_excerpt - 20 * @hooked woocommerce_template_single_add_to_cart - 30 * @hooked woocommerce_template_single_meta - 40 * @hooked woocommerce_template_single_sharing - 50 */ do_action( 'woocommerce_single_product_summary' );
The numbers there will be it’s position. I don’t have to explain everything in there. You should get a hint by now of what it’s doing.
So our code would be like this: