在主页上,我具有产品网格,并且已将具有此类代码的购物车按钮添加到购物车中
<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" ...
我怎么能?
答案 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);
}