我试图将价格添加到循环中的添加到购物车按钮。
[100 $添加到购物车]而不是[添加到购物车]
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; ?>
我如何将这两者结合起来?无法在网上找到任何内容。
答案 0 :(得分:6)
这应该有效:将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="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 );
并且价格将显示在&#34;添加到购物车&#34;文本。
编辑:你应该注意,更新woocommerce插件会撤消你对任何文件所做的任何其他修改。
答案 1 :(得分:3)
WooCommerce 3.1.0更新了添加到购物车按钮的功能
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Runnable r = new Runnable() {
@Override
public void run() {
doubleClick = false;
}
};
if (doubleClick) {
//your logic for double click action
doubleClick = false;
}else {
doubleClick=true;
handler.postDelayed(r, 500);
}
}
});
答案 2 :(得分:0)
如果您希望以后的Woocommerce升级(在某种程度上)安全,请遵循the official safe way to do it(谢谢Felix)。
将add-to-cart.php
复制到名为/woocommerce
的主题内的目录中,该目录保持相同的文件结构,但删除/templates/
子目录。
示例:要覆盖管理订单通知,请复制:wp-content/plugins/woocommerce/templates/emails/admin-new-order.php
到wp-content/themes/yourtheme/woocommerce/emails/admin-new-order.php
以下是Woocommerce 3.3.0更新的文件:
<?php
/**
* Loop Add to Cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/add-to-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
sprintf( '<a href="%s" data-quantity="%s" class="%s" %s><span style="color:#bb0d00;">%s</span> <span style="color:#999;">|</span> %s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ),
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ),
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '',
$product->get_price_html(),
esc_html( $product->add_to_cart_text() )
),
$product, $args );
?>
当然,样式按钮的样式或修改按钮的内容完全取决于您,而不仅限于显示产品价格。