Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created December 1, 2022 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kartikparmar/cf176bdfddb16cf6637b8450d9d217fb to your computer and use it in GitHub Desktop.
Save kartikparmar/cf176bdfddb16cf6637b8450d9d217fb to your computer and use it in GitHub Desktop.
Setting booking fields data from the URL parameters.
<?php
/**
* Setting booking fields data from the URL parameters. start and end date is passed in the URL parameters. This can be changed according to business requirements. e.g check_in and check_out.
*/
function bkap_set_bookings_via_get() {
if ( isset( $_GET['start'] ) && isset( $_GET['end'] ) ) {
$start_date = $_GET['start'];
if ( ! empty( $_GET['end'] ) ) {
$end_date = $_GET['end'];
} else {
$end_date = $_GET['start'];
}
if ( isset( WC()->session ) ) {
WC()->session->set( 'start_date', $start_date );
WC()->session->set( 'end_date', $end_date );
}
}
}
add_action( 'woocommerce_before_single_product', 'bkap_set_bookings_via_get' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment