Created
December 1, 2022 06:08
-
-
Save kartikparmar/cf176bdfddb16cf6637b8450d9d217fb to your computer and use it in GitHub Desktop.
Setting booking fields data from the URL parameters.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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