duannei0044 2018-03-25 17:35
浏览 27
已采纳

如何删除Woocommerce 3.3.4上的添加到购物车

So i'm setting up an external link products (affiliate), and i've been trying to remove add to cart from the website with no luck. I've tried many solutions, but none worked. Either they pop html 500, or they break a page, or simply don't work. Also plugins for that do not work. Is there any way i can get it done? Theme i'm using is Exzo: https://themeforest.net/item/modern-electronics-ecommerce-wordpress-woocommerce-theme-exzo/19356950

Solutions i tried:

// Replace add to cart button by a linked button to the product in Shop and archives pages

add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product  ) {
    // Not needed for variable products
    if( $product->is_type( 'variable' ) ) return $button;

// Button text here
$button_text = __( "View product", "woocommerce" );

return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';

}

Then

add_filter( ‘woocommerce_is_purchasable’, false ); 

Also

function WpBlog() {
remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’);
remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’);
return WooCommerce::instance();
}

And woocommerce.php doesnt have over 900 lines needed for this one

    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
  • 写回答

2条回答 默认 最新

  • dongwei1954 2018-03-28 00:55
    关注
    add_filter( 'woocommerce_loop_add_to_cart_link', 'remove_add_to_cart_buttons', 1 );
    function remove_add_to_cart_buttons( $button ) {
        global $product;
    
        if( $product->is_type( 'external' ) ) {
            return '';
        }
    
        return $button;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)