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 add product in woocommerce with php code [closed]
- Using register_activation_hook in classes
- Is there a way for a plugin to add an attribute to the tag of a theme?
- How to add date range in woocommerce with code
- Creating custom Woocommerce attribute taxonomies from a plugin
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- How to get the original price of the product in woocommerce?
- How to Remove a Filter from the Admin List Table?
- Remove commas from WooCommerce checkout addresses fields
- My shortcode is showing up twice
- Database “Migration” for Plugins?
- WooCommerce Link to Product Category
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Making Quote Plugin more efficient
- Writing scripts using WordPress / WooCommerce classes?
- How do I use the Simple HTML DOM Parser in plugin when other plugin already uses it?
- How to make custom total price reactive in navigation
- Change description on specific WooCommerce product status change
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- How to add a second ‘place order’ button in WooCommerce [closed]
- Instantiate class to be available to all plugin functions
- WP nonce invalid
- Woocommerce redirect thankyou page based on product ID doesn’t empty Cart
- tracking number field in Woocommerce order [closed]
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- Add a product to checkout via form
- Trying to place a custom field after the total section in the checkout page in woocommerce
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Trouble checking if custom woocommerce checkout field is empty or not
- My new button is in the wrong place
- How to obtain the current website URL in my theme?
- Plugin Generate Unexpected output during activation
- Function returns text instead of html [closed]
- Undefined method class::construct() when creating a plugin
- Hook called before text widget save
- wpdb prepare insert table doesn’t work
- Woocommerce – get_items() returns empty array
- how to Update 15k products on plugin activation with meta_option
- Include js script ONLY on woocommerce product category pages? [closed]
- PHP: $_SESSION destroyed after page reload for my custom session
- Creating a brand attribute as a variable
- How to remove Login from in my account page
- Creating plugin with front-end pages
- How to Send Pingbacks for all Posts in WordPress?
- How to access specific product id on other pages/posts?
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- How to retrieve quantity input field by id in woocommerce
- Using zip code to display custom data in Admin Order Details
- Update user meta when an external link in admin notice is clicked
- Is there an option to execute javascript file only on plugin activation
- i want add conditional for add category in wordpress
- Woocommerce remove menu item on myaccount dashboard
- Ajax in a class instantiated via shortcode
- append data to mysql table via submit button coded in php – not working
- random woocommerce categories are not showing when count enabled?
- PHP – Woocommerce 3.2 Add variable shipping insurance with multiple “else if ” conditions
- how to display woocomerce description of each category in wordpress? [closed]
- WordPress 3.0 PHP Error – notice WordPress_product_Type was called incorrectly
- Shortcode Works for Logged in Users but Not Working for Guest
- Submit to itself don’t work
- WooCommerce – Add product category below product price [closed]
- woocommerce plugin bugs
- Adding my own custom template page but got white page
- Woocommerce Price Text
- See output of a sql query while plugin installation in wordpress
- Why this plugin is not working?
- Permission error on plugin save
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- wc_add_notice not working on cart page
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Grabbing value of input field inside of array
- WooCommerce Checkout Cart [closed]
- WordPress REST API – Custom field not added to pages
- Woocommerce – add tracking code to another email template