Having trouble with this issue, any help is appreciated!
I want each of my woocommerce single product pages to have a button \"Book Now\" that links to a page that I
Updated
This will add in single product pages a "Book Now" button linked to your "Booking Appointments" page passing through the URL the product ID, the product sku…
So the code will be:
// Add a custom button in Single product pages
add_action( 'woocommerce_single_product_summary', 'replacing_template_single_add_to_cart', 31, 0 );
function replacing_template_single_add_to_cart() {
global $product;
$product_id = $product->get_id();
$sku = $product->get_sku();
// Set below the page ID, your button text and link parameters to pass in url
$page_id = 124;
$button_text = __('Book Now', 'woocommerce');
$link = get_permalink( $page_id ) . '?id=' . $product_id . '&sku=' . $sku;
// Output your custom text
echo '<a href="'.$link.'" class="book-now button">'.$button_text.'</a>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
In your your "Booking Appointments" page form you will be able to get the values from the URL with
$_GET
to populate necessary fields with an additional scripts in which you will use:$product_id = $_GET['id']; $sku = $_GET['sku'];
Tested and works in WooCommerce 3+.
At the very end of content-single-product.php
you can add
<a class="button-link" href="<?php
get_page_by_path(booking-appointments);
?>">Booking Appointments</a>
then use .button-link to style the link to look like a button.