WooCommerce在“添加到购物车"按钮上显示价格 [英] WooCommerce display price on add to cart button

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

问题描述

我正在尝试将价格添加到循环中的添加到购物车"按钮中.

I'm trying to add the price to the add to cart button in the loop.

[100 $添加到购物车]而不是[添加到购物车]

[100$ Add to cart] instead of [Add to cart]

add_to_cart.php模板:

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="tiny button %s product_type_%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( $product->id ),
        esc_attr( $product->get_sku() ),
        $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
        esc_attr( $product->product_type ),
        esc_html( $product->add_to_cart_text() )
    ),
$product );

price.php模板:

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

如何结合这两个?在网络上找不到任何内容.

How do I combine these two? Couldn't find anything on the web.

推荐答案

这应该起作用:将add_to_cart.php文件修改为

This should work: modify the add_to_cart.php file to

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s %s</a>',
    esc_url( $product->add_to_cart_url() ),
    esc_attr( $product->id ),
    esc_attr( $product->get_sku() ),
    $product->is_purchasable() ? 'add_to_cart_button' : '',
    esc_attr( $product->product_type ),
    $product->get_price_html(),
    esc_html( $product->add_to_cart_text() )
),
$product );

,价格将显示在添加到购物车"文本的前面.

and the price will display in front of the "Add to cart" text.

您应该注意,更新woocommerce插件将撤消该操作以及您对任何文件所做的任何其他修改.

You should note that updating the woocommerce plugin will undo that and any other modification you have made to any of the files.

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

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