Okay.. After some more reading I came to a working solution.
First we make the plugin listen IF the type of page is a product page.
Then IF that is true, conditional logic can be implemented.
This way it’s update proof and it also works on any other template. Great!
Here ‘s the code I added in plugin (somewhat minified to the basics):
add_action( 'wp', 'redirect_single_product_page' );
function redirect_single_product_page() {
if (is_product()) { // if the page is a single product page
$redirectPage = true; // some dummy value for conditional logic
if ($redirectPage) {
$target_url = ...; // construct a target url
wp_redirect($target_url, 301); // permanent redirect
exit();
}
}
}
If the page does not meet the conditional logic, normally expected behavior applies.
Related Posts:
- Use wc_enqueue_js only on specific pages – nested add_action
- woocommerce subscriptions – get expiration date [closed]
- Automated Cart Update With Alert Box Each Time
- WooCommerce/WordPress: how hide entire table form after submit (Admin Dashboard)?
- How to auto fetch customer details in Woocommerce in checkout page
- I want to add custom add to cart link [closed]
- Extend Woocommerce Widget Class – WC_Widget_Product_Categories
- Change product_base programmatically
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- custom post type with role Vendor
- Woocommerce custom Plugin in wordpress [closed]
- Add a custom WooCommerce settings tab with sections
- Payment field disappears on custom Paypal plugin
- I am having errors with checkout on wordpress
- product_type_options get saved value [closed]
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Looping through and combining calls to Woocommerce REST API
- How to import woocommerce custom fields data into another site?
- How do I remove an action hook inside a class that is called by another class?
- How keep woocommerce users separeted in multisite install and keep admins on network
- Custom field fetch error on woocommerce pdf invoice
- Woocommerce Convert existing order to the cart
- How to change product SKU’s in bulk with a plugin
- Edit tag cloud widget number
- How to use update and delete query in wordpress
- add_meta_boxes action with refresh on save
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- How to get Woocommerce Variation ID? [closed]
- Add product tag names to WooCommerce new order email subject
- How To Change The Html of Products filtration sidebar in Woocommerce?
- How To add custom radio boxes to WooCommerce Billing page and change total price by this field?
- WooCommerce: update custom fields after checkout validation failure
- Trigger Woocommerce New User Email
- My Own layout in WooCommerce pages [closed]
- Woocommerce – remove product from category
- Add the Name of Products Ordered to Admin New Order Email WooCommerce
- Get WooCommerce product details and transfer them to a custom DB table
- Custom filter in admin edit custom post type responding with invalid post type?
- How to access global variable $menu inside a class function
- Custom user login page by creating a plugin
- Woocommerce product variation backorder
- Status 400 for AJAX POST Request with admin-ajax.php
- Singelton class does not work, multiple initialization on page reload
- How to upload a file to a folder named after the user_id via plugin
- WooCommerce Webhooks not firing because of error in wp-includes/meta.php
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- adjust section according to country?
- Sum the total amount of a specific product purchased per user and display in table
- Pagination for custom shop loop woocommerce
- get_total () returns 0 – woocommerce [closed]
- wp_insert_post: array only. wp_update_post: array|object (?)
- Building a REST API for your web app exposes primary keys of DB records?
- WooCommerce pages looks unstyled
- How to display a custom product field value of a specific category on a Woo Commerce checkout page?
- Personalize checkout text
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- Custom Taxonomy Select Menu: Setting default option value?
- Get category id when SEO URL is turned on
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Display Sibling WooCommerce Product Categories on Archive Page
- How to sort WooCommerce products page by latest in-stock items first?
- Using ACF Relationship field to set post type to draft or published status
- How to update ticket price programatically when adding to cart and checkout in woocommerce
- Woocommerce My acount page
- Get WooCommerce products with similar SKU
- Use CSS tag inside PHP code
- Hide payment method based on user role AND minimum cart value
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- How can i avoid duplicate same post in wp?
- IF statement not working – Any suggestions?
- How do I disable cache for a certain page?
- Get x numbers of a woocommerce category products using Wp_Query
- using filter and hook inside class
- Get field value and use as variable in php
- Set notification if is two product category in cart
- Priority call methods – PHPMailer->addAddress(NULL)
- Reverse Cross-Sells (WooCommerce)
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- How to properly escape in ternary operators – Wp Coding Standards?
- How to send logs to plugin owner for a plugin?
- Force CSV download with template_redirect
- WooCommerce Custom Pagination
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- Woocommerce product variations getting created without attribute values selected
- WordPress wp_set_object_terms does not assign product to custom taxonomy
- PHP Add products to cart with WooCommerce Addons
- Woocommerce product search result page layout
- Woocommerce attatch files and custom input meta to cart items and then to order
- Woocommerce, via php snippet: How to get product price and divide it by a number from an attribute, and then display the new price via php/html?
- WooCommerce: Custom dropdown for variation selection