2 回答

TA貢獻1804條經驗 獲得超2個贊
下面的代碼可以解決這個問題(基于woocommerce_template_loop_add_to_cart()
原始函數代碼):
add_action('init', 'remove_add_to_cart_function_callback' );
function remove_add_to_cart_function_callback() {
? ? remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
? ? add_action( 'woocommerce_after_shop_loop_item', 'custom_template_loop_add_to_cart', 10 );
}
if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
? ? function custom_template_loop_add_to_cart( $args = array() ) {
? ? ? ? global $product;
? ? ? ? if ( $product && is_cart() ) {
? ? ? ? ? ? $defaults = array(
? ? ? ? ? ? ? ? 'quantity'? ?=> 1,
? ? ? ? ? ? ? ? 'class'? ? ? => implode(
? ? ? ? ? ? ? ? ? ? ' ',
? ? ? ? ? ? ? ? ? ? array_filter(
? ? ? ? ? ? ? ? ? ? ? ? array(
? ? ? ? ? ? ? ? ? ? ? ? ? ? 'button',
? ? ? ? ? ? ? ? ? ? ? ? ? ? 'product_type_' . $product->get_type(),
? ? ? ? ? ? ? ? ? ? ? ? ? ? $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
? ? ? ? ? ? ? ? ? ? ? ? ? ? $product->supports( 'ajax_add_to_cart' ) && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
? ? ? ? ? ? ? ? ? ? ? ? )
? ? ? ? ? ? ? ? ? ? )
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? 'attributes' => array(
? ? ? ? ? ? ? ? ? ? 'data-product_id'? => $product->get_id(),
? ? ? ? ? ? ? ? ? ? 'data-product_sku' => $product->get_sku(),
? ? ? ? ? ? ? ? ? ? 'aria-label'? ? ? ?=> $product->add_to_cart_description(),
? ? ? ? ? ? ? ? ? ? 'rel'? ? ? ? ? ? ? => 'nofollow',
? ? ? ? ? ? ? ? ),
? ? ? ? ? ? );
? ? ? ? ? ? $args = apply_filters( 'woocommerce_loop_add_to_cart_args', wp_parse_args( $args, $defaults ), $product );
? ? ? ? ? ? if ( isset( $args['attributes']['aria-label'] ) ) {
? ? ? ? ? ? ? ? $args['attributes']['aria-label'] = wp_strip_all_tags( $args['attributes']['aria-label'] );
? ? ? ? ? ? }
? ? ? ? ? ? wc_get_template( 'loop/add-to-cart.php', $args );
? ? ? ? }
? ? }
}
代碼位于活動子主題(或活動主題)的functions.php 文件中。經過測試并有效。

TA貢獻1789條經驗 獲得超10個贊
如果不是購物車,您嘗試過嗎?
if (!is_cart()) :
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
endif;
- 2 回答
- 0 關注
- 146 瀏覽
添加回答
舉報