Woocommerce:替换产品使用<button>添加到购物车元素<a>

时间:2019-07-07 17:33:26

标签: wordpress woocommerce cart

在主页上,我具有产品网格,并且已将具有此类代码的购物车按钮添加到购物车中

<a href="/?add-to-cart=2609" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="2609" ...

我想用按钮代替它

<button data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="2609" ...

我怎么能?

1 个答案:

答案 0 :(得分:1)

您应该在functions.php中添加“ woocommerce_loop_add_to_cart_link”过滤器

add_filter( 'woocommerce_loop_add_to_cart_link', 'loop_add_to_cart_link_change_tag', 10, 3 );
function loop_add_to_cart_link_change_tag( $link_code, $product, $args ) {
    $r = array(
        '<a '  => '<button ',
        '</a>' => '</button>'
    );
    return strtr($link_code, $r);
}