WooCommerce 在产品页面上外部产品的添加到购物车按钮上显示价格 [英] WooCommerce display price on add to cart button for external products on product page

查看:33
本文介绍了WooCommerce 在产品页面上外部产品的添加到购物车按钮上显示价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将价格添加到外部产品的产品详细信息页面上的添加到购物车按钮

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

[£100 Buy Now] 而不是 [But Now]

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

希望对这里提出的问题进行类似的修改:WooCommerce 在添加到购物车按钮上显示价格

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 模板

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

推荐答案

用以下代码替换您的 external.php 文件.

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

这篇关于WooCommerce 在产品页面上外部产品的添加到购物车按钮上显示价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆