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 add headers to outgoing email?
- LESS CSS enqueue_style with add_filter to change rel attribute
- Remove Editor From Homepage
- Remove description from on Home
- How can I detect if a user changes their password?
- Moving sharedaddy buttons (in Jetpack) to the top of a post?
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- filter the_title problem in nav
- Sensei LMS Hooks to Remove Content
- How to re-enable a filter after disabling with __return_false
- Ignore dots when searching in the media library?
- Exclude One Category and its Subcategories using WP_LIST_FILTER
- Where is this inline CSS code [closed]
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Why won’t my preg_replace work with content_save_pre?
- Echoing Categories only if they’re a child of a given category
- WooCommerce Conditional Tag inside plugin
- Add ‘data-text’ attribute to TagCloud HTML
- Why in archive page doesn´t show read more button with excerpt?
- Removal of Jetpack OG Tags from old blog site
- Insert term when page is published – avoid duplicates after edits
- Filter Media by Featured on Admin
- page_attributes_dropdown_pages_args filter does not work
- How to access plugin variables from theme templates without using globals?
- Make WP not format code, not insert line breaks in between tags
- add img class to native wordpress galleries
- Get Posts updated or published within the last x hours
- How to get a single hook from wp_head()?
- WP filter to alter admin CSS styles?
- preview_post_link for Custom Post Types
- Filter an array with a callback – for single & multidimensional arrays
- Why this filter hook is not working when passing parameters?
- Change the template when the user is not logged in using page_template filter (it does not work)
- Regarding post text filtering
- Add Filter not working with get_posts
- How to Prevent WordPress to encode html in post?
- Filter posts by meta data using custom query
- Filter causing loss of _wp_attachment_metadata
- Action hook to control access to certain parts of my site
- How can I tranlslate post date in italian?
- Use alternative front page if cookie is set
- Having wp-admin on different domain
- Use a functions in functions.php to remove a string for template theme
- How to add woocommerce product price filter widget to other page
- how to output HTML tags in post_content and not as plain text
- Security question – Display a General Custom Login Error Message
- Add filter conditionally to a page
- Woocommerce login to specific page or referrer
- How to apply a filter to everything?
- Remove action added from class
- Identify admin/logout and more filters
- Sanitizing a custom query’s clauses
- How to create a list of terms who’s posts also have a predefined external term?
- How to add product thumbnail on orders list on backend?
- Limit total tags in the_content