WordPress – WooCommerce display price on add to cart button for external products on product page

woocommerceWordpress

I'm trying to add the price to the add to cart button on the product details page for external products

[£100 Buy Now] instead of [But Now]

hoping the achieve a similar modification to the one asked question here:
WooCommerce display price on add to cart button

single-product/add-to-cart/external.php template

<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<p class="cart">
  <a href="<?php echo esc_url( $product_url ); ?>" rel="nofollow" class="single_add_to_cart_button button alt">
    <?php echo $button_text; ?>
  </a>
</p>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>

Just can't figure out where to included the code below to pull in the price

<?php if ( $price_html = $product->get_price_html() ) : ?>
    <span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>

Best Answer

Replace your external.php file with the following code.

<?php
/**
 * External product add to cart
  *
  * @author         WooThemes
  * @package    WooCommerce/Templates
  * @version     2.1.0
  */

 if ( ! defined( 'ABSPATH' ) ) {
 exit; // Exit if accessed directly
 }

 global $product;
 ?>

 <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>

  <p class="cart">
  <a href="<?php echo esc_url( $product_url ); ?>" rel="nofollow" class="single_add_to_cart_button button alt"><?php echo $product->get_price_html(); ?>
<?php echo $button_text; ?>
</a>
</p>

<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
Related Topic