覆盖wooccommerce添加购物车链接



你好,我试图覆盖woocomerce_loop_add_to_cart_link函数,但不起作用,我已经在我的主题中创建了"woocomerce"文件夹,然后添加"模板"并在文件夹"循环"中添加我需要编辑的文件,即"添加到cart.php"。

但在更改我的href按钮后添加,没有生效,下面是代码:

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 btn btn-warning btn-block btn-sm btn-add-cart" %s>%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'] ) : '',
esc_html( $product->add_to_cart_text() )
),
$product, $args );

要覆盖主题中的wooccommerce模板文件,正确的路径将是

yourtheme/woocommerce/loop/add to cart.php

而不是

yourtheme/woocommerce/templates/loop/add to cart.php

这将解决您的问题。

如果你只想更改文本,WooCommerce推荐了一个插件-https://wordpress.org/plugins/wc-custom-add-to-cart-labels/

最新更新