Replace add to cart button with a read more linked to product page on shop pages in WooCommerce 3

前端 未结 4 1485
逝去的感伤
逝去的感伤 2020-12-06 03:37

I am using woocommerce and I have the following issue:

  • The products are displayed in the homepage with their price and add to cart button.
  • Add to ca
4条回答
  •  感情败类
    2020-12-06 04:17

    In case it helps, this worked for me to apply this solution only to simple products, since variable products don't "add to cart" on archive pages anyway. This way it can be clearer that a product has more options (if it is variable). I also changed the text of "select options" to "more options" in the example below (since not all products in my case would be purchasable even after viewing the single product page's url, which is another non-topical idea for this thread):

    // changes the "select options" text. Forget who to give credit to for this.
    add_filter( 'woocommerce_product_add_to_cart_text', function( $text ) {
    global $product;
    if ( $product->is_type( 'variable' ) ) {
        $text = $product->is_purchasable() ? __( 'More Options', 'woocommerce' ) : __( 'Read more', 'woocommerce' );
    }
    return $text;
    }, 10 );
    
    /**
     * remove add to cart buttons on shop archive page
     */
    
    add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
    function replacing_add_to_cart_button( $button, $product  ) {
    if ( $product->is_type( 'simple' ) ) {
    $button_text = __("View product", "woocommerce");
    $button = '' . 
    $button_text . '';
    }
    return $button;
    }
    

提交回复
热议问题