Well, what it works for me in this case was this code
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_add_to_cart' );
function redirect_add_to_cart() {
if ( isset( $_POST['add-to-cart'] ) ) {
$url = wc_get_checkout_url();
return $url;
}
}
It redirects if it is a product but if you are in the shop page it wont redirect, of course if you want to redirect in another page but in single product page the code should be if ( !isset( $_POST['add-to-cart'] ) ) {
I hope my question and answer helps somebody who visits this post
Related Posts:
- the_content and is_main_query
- How to pass/get data to/from the WooCommerce data-product_variations object?
- Filter hook before create order WooCommerce
- Display WooCommerce newest product reviews on top [closed]
- How to change Woocommerce breadcrumbs content?
- Add Dropdown menu using “add_filter => wp_nav_menu_items”
- Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu
- Filter out some plugin action in wp head / wp_footer
- Adding Filter Conditionally Per Page ID
- Filter category in WooCommerce shop page to display related sub-category
- Using Conditional Statement in functions.php
- Same Conditionals Not Working on Two Different Hooks
- How to change currency programmatically on creating order action?
- Filter the regular price of woocommerce products
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- Redirect customer to login page (with other signup plugin) if user not logged in when proceeding to checkout
- Adaptive product filters for WooCommerce
- Add default user field to WooCommerce checkout [closed]
- Link to Shop-Filter with .current-menu-item
- Adding a Clone link to product attributes – post_row_actions() filter, or how to override a Class question
- Building a request processor for multi-page forms, etc using $_GET requests
- Woocommerce “added to cart” message on main(home) page
- Replacing a deprecated filter ‘woocommerce_get_price’ with ‘woocommerce_product_get_price’
- Woocomemrce order and registration fileds to UPPERCASE
- How should I be using filters and is_single together?
- Filter wp_redirect() to stop redirect under certain condition
- Redirect no product url’s to static url
- Sorting products by price ( regular + sale price )
- Redirect to woocommerce checkout after adding to cart – item already in cart
- WooCommerce coupon hook argument NULL when using filter woocommerce_get_shop_coupon_data
- How to access page variable inside action hook
- Is there any reason for the nested filters to be applied on the first case and not in the second one?
- auth_redirect() doesn’t send users to the page where they orginally tried to acces
- Redirect an archive page to its relevant URL-friendly filtered page
- How to redirect a unique link based on login status
- adding an action inside if condition not working
- Put data in my-account/view-order/id/ page
- Modify WooCommerce email shipping text value
- The title of an attachment is not working
- is_page_template() doesn’t work with excerpt_length filter
- Is there a way to overwrite a filter used in canonical.php?
- WooCommerce comments_template Filter Not Firing
- Woocommerce: Only one review per verified buyer [closed]
- Add a filter conditionally based on frontpage
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?
- Disable emojicons introduced with WP 4.2
- How to remove a filter that is an anonymous object?
- WordPress hooks/filters insert before content or after title
- How to add defer=”defer” tag in plugin javascripts?
- add_action(), add_filter() before or after function
- apply_filters(‘the_content’, $content) vs do_shortcode($content)
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- What is the very earliest action hook you can call?
- How would one modify the filtering Gutenberg applies to pasted content?
- How can I modify the WordPress default widget output?
- Add custom options to the wplink dialog
- Remove classes from body_class
- what is __return_false in filters
- Explanation for apply_filters function and its variables
- Gutenberg: Is there a way to know if current block is inside InnerBlocks?
- How to reorder billing fields in WooCommerce Checkout template? [closed]
- Insert HTML just after tag
- Changing WooCommerce Display Price Based on User Role & Category [closed]
- How to add a custom CSS class to core blocks in Gutenberg editor?
- How to show page content in feed?
- wp_headers vs send_headers. When to use each?
- Filter any HTTP request URI?
- How to Pass External Variables to Filters/Actions
- How to filter users on admin users page by custom meta field?
- Filter by one custom field, order by another?
- Not able to change wp_title using add_filter
- Check IF is a “single product page” and Check the “role” for a Redirect
- How to appending to the_content using add_filter with custom post type?
- Query WP REST API v2 by multiple meta keys
- No filter of code on switch from html to visual editor, how?
- Sanitize and data validation with apply_filters() function
- How to modify posts_where filter only for the search query
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- How to get shortcode’s input values inside a filter?
- Removing Image and Caption Dimension Attributes
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- How to bulk delete all users with no posts?
- How many filter/action hooks are healthy?
- WordPress 3.9 – Trouble Editing TinyMCE 4.0
- Changing JPEG compression depending on image size
- How to add filter with 2 args?
- Why is javascript allowed in my post content?
- How to use update_{$meta_type}_metadata filter to modify meta value
- How to wrap an element around an iframe or embed in content automatically?
- Filter specific shortcode output?
- WordPress Internal @ Mentions
- How to add headers to outgoing email?
- Earliest hook to reliably get $post/$posts
- Insert new element to array with add_filter
- LESS CSS enqueue_style with add_filter to change rel attribute
- Is it possible to filter comments in a post so a user can only see the comments they have written?
- Remove Editor From Homepage
- How to modify Contact Form 7 Success/Error Response Output [closed]
- Where to hook into post content?