Wed
Wed

Reputation: 342

Woocommerce shop page (category page template) Add to cart button behavior

I'm trying to make category page (shop page) to have custom button that links to single product page instead of standard [Add to cart] behavior.

This below is my code but the link on the button called by theme defined shortcode with an link variable $link. But instead of taking user to single product page it takes user back to the same opened shop page.

What am I doing wrong?

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('[us_btn text="Details" link="' . $link . '" size="12px" align="right" icon="fal|info-circle"]');

Upvotes: 0

Views: 274

Answers (2)

Wed
Wed

Reputation: 342

Had to strip http:// from link

echo do_shortcode('[us_btn text="Details" link="url:' . str_replace("http://", "", $link) . '" size="12px" align="right" icon="fas|info-circle"]');

Upvotes: 0

Keylies
Keylies

Reputation: 185

Check with your developer tools if your link href is filled with product URL, it may be empty if it takes you back to the same page. The shortcode must be the issue if it is not well rendered.

Upvotes: 1

Related Questions