• Hi there, I am trying to get simple products add to cart button to link to the product page instead of adding the product to cart. But none of the normal woocommerce functions seem to be working, is this normal for the theme? Or have I made some change myself that might be causing this?

    Thanks for any help in advance

    Harry

Viewing 6 replies - 1 through 6 (of 6 total)
  • By default woocommerce should be adding an add to cart not a view details button. The image and the title should link to your single page through.

    What do you mean by “normal woocommerce functions”. What functions are you trying to add?

    Kadence Themes

    Thread Starter rookdesigns

    (@rookdesigns)

    Hi there yes the image and title do link to the product, I just dont want customers to be able to add product until they have run through a form that is held within the product.

    This is what I mean by normal functions(sorry might not have been the best terminology):

    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    
    add_action( 'woocommerce_after_shop_loop_item', 'my_woocommerce_template_loop_add_to_cart', 10 );
    
    function my_woocommerce_template_loop_add_to_cart() {
        echo '<form action="' . get_permalink() . '" method="get">
                <button type="submit" class="single_add_to_cart_button button alt">Read More</button>
              </form>';
    }

    But all this does is add a second button to the products on the archive page.

    Cheers

    Thread Starter rookdesigns

    (@rookdesigns)

    Have you edited the woo-commerce templates? Have you tried deactivating plugins?

    When I test your function it works fine for me.

    Kadence Themes

    Thread Starter rookdesigns

    (@rookdesigns)

    Hi yes I have edited some woocommerce templates, I will try deactivating plugins although not sure what plugins might be causing this issue. i’ll let you know how it goes. Cheers

    Thread Starter rookdesigns

    (@rookdesigns)

    Hi I have looked into this and nothing seems to make any difference, All I can do is add a second add to cart button that links to the product page as well as the kad_add_to_cart button.

    I have tried this to, which has the above effect:

    *PUT THIS IN YOUR CHILD THEME FUNCTIONS FILE*/
    
    /*STEP 1 - REMOVE ADD TO CART BUTTON ON PRODUCT ARCHIVE (SHOP) */
    
    function remove_loop_button(){
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_kad_add_to_cart', 10 );
    }
    add_action('init','remove_loop_button');
    
    /*STEP 2 -ADD NEW BUTTON THAT LINKS TO PRODUCT PAGE FOR EACH PRODUCT */
    
    add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');
    function replace_add_to_cart() {
    global $product;
    $link = $product->get_permalink();
    echo do_shortcode('<a href="'.$link.'" class="button addtocartbutton">Order</a>');
    }

    I also only want this to effect simple products only, is this possible?

    Thanks for your help

    as always.

    Best

    Harry

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add to cart link to product page’ is closed to new replies.