I would like to remove the default /?add-to-cart= animation buttons on the Shop Archive page. The default mode on a simple product shows a little spinner after clicking the button before showing a tick and providing a "View Cart" option link. (See here: https://snag.gy/ZreQid.jpg)
I would like the simple product Add to Cart button to redirect to the product page in the same way that the variable product does. (i.e. I want the client to view the product page after clicking the button, and I'll change "Add to Cart" label to "View Product" via the Booster for Woocommerce plugin).
So, I found this code on this thread:
/*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_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('<br>[button link="' . esc_attr($link) . '"]VIEW PRODUCT[/button]');
}
The first step works consistently well. The second step works some of the time. For example, on one site, Step 2 works a charm. On a second site (with the same theme, at the same host, etc. etc.), the button displays like this:
[button link="https://example.com/product/product-name/"]VIEW PRODUCT[/button]
i.e. the button doesn't show; this raw code is on display and it's not clickable. See here: https://snag.gy/FxEPWh.jpg
I hope I've explained it properly.
Can anyone help to explain why the above code is not working consistently across different sites? Is there an easier way to do this?