I am trying to display a button which will direct users to a different product but the URL of this button will be the same as the current URL but will append 2 added letters to the end of the URL. For example, I am on product URL mywebsite.com/products/super-awesome-product-abc and I want the button to link to mywebsite.com/products/super-awesome-product-abcdef. I have 100 products and I will be creating more over time. I would like a dynamic solution that will display the new URL regardless of what page/product they are on. The appended characters will always be the same. I will add that the appended "abc" and "abcdef" in my example are also the product SKU. Perhaps I can use this in the solution. I am adding these buttons to the /themes/mytheme/woocommerce-bookings/booking-form/datetime-picker.php file.
I believe this works for me. I placed the below code in my themes function.php file:
add_action( 'woocommerce_before_add_to_cart_form', 'booking_lastminute_button', 35 );
function booking_lastminute_button(){
global $product;
if( $product->get_sku() ) {
echo '<p class="lastminute-button"><a href="mysite.com/products/super-awesome-product-abc' .$product->get_sku(); echo 'def">Click to find a better product</a></p>';
}