WPSlash

Add Price on Add To Cart Button

Wednesday March 31, 2021

The following snippet will copy the price automatically and add it inside the add to cart button

add_action("wp_footer", "wpslash_hook_to_add_the_price_in_button");
function wpslash_hook_to_add_the_price_in_button()

{

    ?>
    <script>

        jQuery(document).ready(function() 


            {



jQuery(document).on('change', '.extra-options-accordion select, .extra-options-accordion input , .input-text.qty', function()
    {


        var price  = jQuery('.wf_product_view .price:first').text();

        jQuery('.wf_product_view .single_add_to_cart_button').html(price+' | Add to cart');

    });   
			
				jQuery( this ).on( 'found_variation', function( event, variation ) {


        var price  = variation.price_html;

        jQuery('.wf_product_view .single_add_to_cart_button').html(price+' | Add to cart');

    });            



      });
		
		




    </script>

    <?php
}

function wpslash_include_price_in_add_to_cart_button( $text, $product ) {
 		
        $text = strip_tags(wc_price($product->get_price()))." | ".$text;
    
    return $text;
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wpslash_include_price_in_add_to_cart_button', 10, 2 );

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

Tutorials

How to Set Up SMS and WhatsApp Order Notifications for Your WooCommerce Restaurant (2026)

Why SMS and WhatsApp Notifications Matter for Restaurant Orders A customer places an order on your <a href="https://www.wpslash.com/how-to-set-up-real-time-order-tracking-for-your-woocommerce-restaurant-website-2025-2/" title="How to Set Up Real-Time Order Tracking for Your <a href="https://www.wpslash.com/how-to-set-up-catering-and-large-group-orders-on-your-woocommerce-restaurant-website-2025/" title="How to Set Up Catering and Large Group Orders on Your WooCommerce Restaurant Website (2025)”>WooCommerce Restaurant Website (2025)”>restaurant website at 7:15 PM during the Friday rush. […]
May 3, 2026
Tutorials

How to Set Up Real-Time Order Tracking for Your WooCommerce Restaurant Website (2026)

Why Real-Time Order Tracking Matters for Restaurant Websites Picture this: a hungry customer places an order on your <a href="https://www.wpslash.com/how-to-build-a-customer-loyalty-program-for-your-wordpress-restaurant-website-2025/" title="How to Build a Customer Loyalty Program for Your <a href="https://www.wpslash.com/how-to-connect-your-wordpress-restaurant-website-to-doordash-uber-eats-grubhub-2025/" title="How to Connect Your WordPress <a href="https://www.wpslash.com/how-to-rank-your-restaurant-website-on-google-local-seo-for-wordpress-2025/" title="How to Rank Your Restaurant Website on Google: Local SEO for WordPress (2025)”>Restaurant Website to DoorDash, Uber […]
May 3, 2026
Tutorials

How to Set Up Catering and Large Group Orders on Your WooCommerce Restaurant Website (2026)

Why Catering and Large Group Orders Matter for Restaurant Revenue Most restaurant owners pour energy into optimizing their dine-in experience and individual delivery orders while overlooking a revenue channel that can transform their bottom line: catering. A single corporate lunch order for 30 people can equal what your dining room generates in an entire slow […]
May 2, 2026