Apply function to specific page template
-
I’m using woocommerce and I’m trying to create a function, when clicking the ‘add to cart’ button, the visitor goes directly to the checkout page.
The button is a product link that automatically adds the product to the cart and the page is not a product page, it’s a custom template called landing-page.php which is inside my child theme folder.
I only want this function to work on the landing-page.php, every other template should have a normal checkout process.
Here is the code I’ve found that will execute the function I need; however, it will execute the function on every page template:
add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }
Here is the code I’m trying to use:
if (is_page_template( 'landing-page.php' )) { add_filter ('add_to_cart_redirect', 'redirect_to_checkout'); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; } }
But it doesn’t work. Why isn’t this working?
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Apply function to specific page template’ is closed to new replies.