This code will do what you want. It will redirect to the latest product added if you add ?latest_product
to your site’s URL. So the dynamic link would be http://example.com/?latest_product
function wpse_274155_redirect_latest_product() {
// If URL has ?latest_product query string.
if ( isset( $_GET['latest_product'] ) ) {
// Get latest product.
$latest_products = get_posts( array(
'posts_per_page' => 1,
'post_type' => 'product',
'no_found_rows' => true,
'orderby' => 'date',
'order' => 'DESC',
) );
// Make sure product exists.
if ( isset( $latest_products[0] ) ) {
// Redirect to product.
wp_redirect( get_permalink( $latest_products[0] ) );
exit();
}
}
}
add_action( 'template_redirect', 'wpse_274155_redirect_latest_product' );
Related Posts:
- How to get current product category ID in product archive page
- WooCommerce prices location in DB
- WP/WooCommerce REST API cart/checkout/order [closed]
- Fatal Error when installing woocommerce despite upgrading
- Adding an action within a function that is being called by add_filter
- Hide Add to Cart Button
- How to modify “[Product] has been added to your cart” in WooCommerce?
- woocommerce fail to replace template string in email title [closed]
- Why do Woocommerce templates use hooks rather than get_template_part
- Change font size in products listing pages in woocommerce
- Display WooCommerce only in stock sizes product attribute on shop page
- How to stop a Gutenberg Block from firing multiple GET Requests?
- Woocommerce Product Price Inserted programmatically doesn’t get displayed In Single Product Page
- Hide “Delete Note” link in Order Notes Panel
- Exclude products with a stock lower than the low stock threshold from the shop loop [closed]
- Remove Order List Row Link in WooCommerce Admin?
- Unable to update Woocommerce Product Permalink
- wp_customize – detect post type to show/hide customizer options
- WooCommerce – Display nested list of all subcategories on archive-product.php
- WooCommerce quick checkout form? [closed]
- woocommerce cart item remove ajax not working in hosted site [closed]
- Set woocommerce product price based on dealer location [closed]
- How can I custom order the product display?
- WordPress plugin cloak link [closed]
- Woocommerce REST API – updating an order changes custom tax calculations
- How to list all WC products by their attributes values?
- Showing the WordPress standard text area on a Woocommerce Single Product Page?
- Woocommerce Update Causing Internal Server Error [closed]
- WordPress WooCommerce: How to allow only specified customers to pay by check? [closed]
- remove default pagination on woocommerce shop page
- WordPress Comment Box on woocommerce product page [closed]
- Remove Bulk Action For non admin user
- Add max-value to hooked quantity selector in woocommerce [closed]
- Can’t remove woocommerce sidebar
- Woocommerce Slow Queries
- woo product , wp_insert_post() never displays on the front end. What gives? [closed]
- Disabling shopping basket in WooCommerce [closed]
- Single product page doesn’t display price
- Should I use docker in wordpress production?
- can’t get the product id in single woocommerce page
- Php echo woocommerce price
- Different files for order details
- Multiple Schema.org markups on a single product page
- Woocommerce – Adding row to cart table
- Hide a product with a certain tag from product-category
- Custom rewrite for product variation not working
- Block Disposable Emails on Woocommerce Registration
- Can’t Change WooCommerce Default Language to Spanish (Mexico)
- WooCommerce get_author_posts_url() – Author URL redirecting to shop base
- Error message if user is buying less than 200 euros of a given product [closed]
- WooCommerce show a variation both in check boxes and in a list
- Woocommerce – How to mix products and posts on a landing page?
- Disable woocommerce product search plugin’s autocomplete [closed]
- WooCommerce (Bookings) + AddOns not always calculating correctly the total
- Woocommerce order proceed hooks
- How can i get the code of Shop Page Woocommerce?
- “Products” Title changed
- WooCommerce custom product type not saving with namespaces
- Add shortcode to show woocommerce shipping class name on product template
- Upload file to Woocommerce Order
- wp_login overriding user meta data
- pass a woocommerce product name to contact form7?
- Custom Tab in Coupons causes “the link you followed has expired” error
- Woocommerce List categories with Image thumbnail
- How to add (and change the font of) the short product description to order page and customer’s new order e-mail [closed]
- Using built-in validation pop-up for custom fields
- Display WOO Commerce products on HTML page?
- How to add custom text field inputs for attributes in backend?
- Get unsolved array keys of product data tabs in woo product editor page
- set up existent product blocked in woocommerce
- Show products as posts on archive page
- Woocommerce new shop page
- Add class to latest item Woocommerce
- WordPress/Woocommerce Classes and adding new properties
- Adding price to woocommerce cart item with get_price gets multiplied with 3?
- email address non required
- How to get selected variation for a product in WooCommerce Cart Page?
- Admin – Custom Post Type in WooCommerce menu – how to control menu order
- Facing issue in Woocommerce 3.3 version in wordpress
- getting attributes in a product loop
- Removing storefront-sorting div from the before section of Shop page
- (WooCommerce) Conflict with template – Can’t load payment methods
- Hook woocommerce price in backend order edition
- How to put a date range in a virtual/downloadable product? [closed]
- Woocommerce Child Category Permalink Structure Change
- Allow customer to choose an optional free/paid product to add to their order (and reduce stock reduced & record sale)
- How to restrict type/size of file uploads in any plugin?
- In woocommerce some products have empty options, but how to check this
- Stop the “upload file size” error from printing [closed]
- Changing sale price programmatically, but it’s not shown on front-end
- How to disable the “Upgrade or Downgrade” button in “My account” of WooCommerce Subscriptions
- WooCommerce – Inconsistent Indexing of Orders
- How to remove slug from Product category URL in Woocommerce
- Removing ‘woocommerce-no-js’ class from body
- url rewrite doesn’t load woocommerce product
- Add Additional 3 buttons next to “Add to cart” button in woocommerce product page
- How do I remove the recurring total from thank you for your order email?
- Display product categories + child-categories on a single product page
- I want to Display custom woocomerce meta box in orders list
- Detect Product Type with code