Add Price on Add To Cart Button

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 )...

March 31, 2021 WPSlash

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 );

Commission-free ordering

Run restaurant orders on your own WordPress site

FoodMaster adds delivery, pickup, dine-in, POS, and kitchen tools — with zero per-order fees.

Get FoodMaster

Leave a Comment

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

×

🔥 ONE DAY ONLY OFFER 🔥

Upgrade FoodMaster Today

Normally your license is limited to 1 Website.

Today only, get a LIFETIME Unlimited Websites License for just:
$499

✔ Unlimited Client Websites
✔ Unlimited Personal Projects
✔ Future Updates Included
✔ Save Hundreds on Additional Licenses

Offer Ends In: