• Resolved jgw95

    (@jgwinbush)


    Hi all, I recently implemented some code into my functions file to change the ‘buy product’ buttons on the main shop pages of my site to ‘view product’ so the user would be taken to the full product listing rather than adding the item straight to cart/ going to external link. The ‘view product’ buttons have been successful, however, I now have two ‘buy product’ buttons on the full product listing. I’ve been searching for some code to get rid of one of these but I’ve only been able to remove both or have both… can anybody point me in the right direction please?

    Code used was;

    // First, remove Add to Cart Button
      
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
      
    // Second, add View Product Button
      
    add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_view_product_button', 10 );
      
    function bbloomer_view_product_button() {
    global $product;
    $link = $product->get_permalink();
    echo '<a href="' . $link . '" class="button addtocartbutton">View Product</a>';
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    Hi @jgwinbush,

    I added your referenced code to one of my test installations which only has the WooCommerce plugin and our free Storefront theme enabled. When doing some I’m not seeing two Add to cart buttons displaying on the site.

    Image Link: https://cloudup.com/c3ezOJK57ak

    From what you have described, it seems like code from another plugin or the theme activated only on your particular site is causing this code to add two buttons.

    To see if that is the case we’d suggest carrying out a conflict test on your site by disabling all other plugins aside from WooCommerce along with switching to a theme like Storefront. This will help with trying to and locate what software you have installed which could possibly be causing this behaviour? You could use a free plugin called Health Check and Troubleshooting to carry out such testing.

    When in Troubleshooting mode all plugins will be deactivated and only the admin of the site carrying out the troubleshooting would see those changes. Any customers visiting the site would see no changes at all.

    Once you have disabled all other plugins and switched theme if the behaviour is resolved you can then enabled your theme and sites plugins testing after each one is enabled until the behaviour returns to locate the culprit.

    https://docs.woocommerce.com/document/how-to-test-for-conflicts/

    You can test the code when using the free Storefront theme by adding it to that themes functions.php file.

    Plugin Support Stuart Duff – a11n

    (@stuartduff)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can reopen it again if you need be.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Two ‘Buy Product’ buttons on product listing – woocommerce’ is closed to new replies.