首页 > 解决方案 > 我如何更改 WooCommerce 中的默认添加到购物车按钮?

问题描述

这就是一切的样子

截屏

我想为外部产品卡添加一个新的“add_to_cart”按钮模板,而不影响内部产品卡。但是当我添加时,旧的仍然存在。我的代码有什么问题?

这是我在functions.php中的代码

function loop_custom_variable_products() {
    global $product;
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 30 ); // Remove price
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 30); // remove add to cart
    remove_action( 'woocommerce_after_shop_loop_item', 'loop_variations_custom_buttons_and_prices', 30 ); // Add prices with custom buttons
}
add_action( 'init', 'loop_custom_variable_products' );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_variable_add_to_cart1', 30 );
//add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_variable_add_to_cart1', 30);
function woocommerce_variable_add_to_cart1(){
   //... some code for new add to card style
}

标签: phpwordpresswoocommerce

解决方案


推荐阅读