代码之家  ›  专栏  ›  技术社区  ›  IDontEvenKnow

如何在Woocommerce 3.3.4中删除添加到购物车

  •  0
  • IDontEvenKnow  · 技术社区  · 6 年前

    因此,我正在建立一个外部链接产品(附属公司),我一直在试图删除添加到购物车从网站上没有运气。我尝试了许多解决方案,但都没有奏效。要么弹出html 500,要么破坏页面,要么根本不起作用。还有一些插件不起作用。我有什么办法可以完成吗? 我使用的主题是Exzo: https://themeforest.net/item/modern-electronics-ecommerce-wordpress-woocommerce-theme-exzo/19356950

    我尝试的解决方案:

    // 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>';
    

    }

    然后

    add_filter( ‘woocommerce_is_purchasable’, false ); 
    

    而且

    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();
    }
    

    和woocommerce。php不需要900多行代码

        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 回复  |  直到 6 年前
        1
  •  1
  •   IDontEvenKnow    6 年前
    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;
    }
    
        2
  •  0
  •   Harry Manback    6 年前

    您可能会很幸运地使用此插件- https://wordpress.org/plugins/yith-woocommerce-affiliates/

    如果这不起作用,您能否覆盖主题中的“添加到购物车”模板?