Created
May 20, 2024 08:43
-
-
Save propertyhive/0b6537826a32f31d6b5e6e068604ca50 to your computer and use it in GitHub Desktop.
StuRents Book Now URL (updated)
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
// optional if wanting to remove the default 'Make Enquiry' button | |
//remove_action( 'propertyhive_property_actions_list_start', 'propertyhive_make_enquiry_button', 10 ); | |
add_filter( 'propertyhive_single_property_actions', 'add_custom_make_enquiry_action' ); | |
function add_custom_make_enquiry_action( $actions ) | |
{ | |
global $property; | |
if ( strtolower($property->availability) == 'sold out' ) | |
{ | |
$action = array( | |
'href' => '#', | |
'label' => __( 'Book Now', 'propertyhive' ), | |
'class' => 'action-book-now action-book-now-sold', | |
'attributes' => array( | |
'disabled' => 'disabled' | |
) | |
); | |
array_unshift($actions, $action); | |
return $actions; | |
} | |
$imported_sturents_data = $property->_property_import_data; | |
if ( empty($imported_sturents_data) ) | |
{ | |
return $actions; | |
} | |
// Use preg_match to extract the book_now_url field | |
if (preg_match('/"book_now_url"\s*:\s*(null|"https:\/\/[^"]*")/', $imported_sturents_data, $matches)) { | |
$book_now_url = $matches[1]; | |
if ($book_now_url !== 'null') { | |
// Remove quotes if the URL is found | |
$book_now_url = trim($book_now_url, '"'); | |
$action = array( | |
'href' => $book_now_url, | |
'label' => __( 'Book Now', 'propertyhive' ), | |
'class' => 'action-book-now', | |
); | |
array_unshift($actions, $action); | |
} | |
} | |
return $actions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment