Hi there team HP.
Was wondering how to only have two options for the listing extras, per booking and per each. So removing the per place per each and per place from the selection.
We’ve come across a snippet by Yevhen dated Dec '22 in a topic Able to limit price extras to per booking only? and another topic Only keep per place as price extra using the same snippet, but both just have one option and we’d like to also have per each (per listing) and possibly have it as default instead of the blank should vendors not make a selection.
Below is the snippet used by the two topics listed above.
add_filter(
'hivepress/v1/models/listing/attributes',
function($attributes){
if(isset($attributes['price_extras'])){
$attributes['price_extras']['edit_field']['fields']['type']['options'] = [
'per_order' => 'per booking',
];
}
return $attributes;
},
1000
);
add_filter( 'hivepress/v1/models/listing/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/listing_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/listing_attributes', 'change_price_extras_custom', 200 );
add_filter( 'hivepress/v1/models/vendor/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/vendor_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/vendor_attributes', 'change_price_extras_custom', 200 );
function change_price_extras_custom($form, $model = null){
$is_form = strpos( current_filter(), 'form' );
$is_model = strpos( current_filter(), 'model' );
$is_listing = strpos( current_filter(), 'listing' );
$per_vendor = get_option( 'hp_booking_per_vendor' );
if ( ! $is_listing && ! $per_vendor ) {
return $form;
}
$fields = [];
if ( $is_model ) {
$fields = $form;
} else {
$fields = $form['fields'];
}
$listing_id = null;
if ( $is_listing ) {
if ( $is_model ) {
$listing_id = $model->get_id();
} elseif ( $is_form ) {
$listing_id = $model->get_model()->get_id();
} else {
$listing_id = get_the_ID();
}
if ( ! $listing_id || ! hivepress()->booking->is_booking_enabled( $listing_id ) ) {
return $form;
}
}
if ( $is_listing && hivepress()->get_version( 'marketplace' ) ) {
if ( get_option( 'hp_listing_allow_price_extras' ) ) {
$fields['price_extras']['fields']['type'] = [
'type' => 'select',
'options' => [
'per_order' => 'per booking',
],
'_order' => 30,
];
}
}
if ( $is_model ) {
$form = $fields;
} else {
$form['fields'] = $fields;
}
return $form;
}
ihor
June 11, 2023, 6:11pm
2
Yes, this may be possible with the code snippet, our developer @yevhen will check this as soon as possible.
yevhen
June 13, 2023, 12:15pm
4
Please try this PHP code snippet. If I correctly understand, then per each option is equal to per day option
add_filter(
'hivepress/v1/models/listing/attributes',
function($attributes){
if(isset($attributes['price_extras'])){
$attributes['price_extras']['edit_field']['fields']['type']['options'] = [
'per_order' => 'per booking',
'per_item' => 'per day',
];
}
return $attributes;
},
1000
);
add_filter( 'hivepress/v1/models/listing/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/listing_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/listing_attributes', 'change_price_extras_custom', 200 );
add_filter( 'hivepress/v1/models/vendor/fields', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/forms/vendor_update', 'change_price_extras_custom', 200, 2 );
add_filter( 'hivepress/v1/meta_boxes/vendor_attributes', 'change_price_extras_custom', 200 );
function change_price_extras_custom($form, $model = null){
$is_form = strpos( current_filter(), 'form' );
$is_model = strpos( current_filter(), 'model' );
$is_listing = strpos( current_filter(), 'listing' );
$per_vendor = get_option( 'hp_booking_per_vendor' );
if ( ! $is_listing && ! $per_vendor ) {
return $form;
}
$fields = [];
if ( $is_model ) {
$fields = $form;
} else {
$fields = $form['fields'];
}
$listing_id = null;
if ( $is_listing ) {
if ( $is_model ) {
$listing_id = $model->get_id();
} elseif ( $is_form ) {
$listing_id = $model->get_model()->get_id();
} else {
$listing_id = get_the_ID();
}
if ( ! $listing_id || ! hivepress()->booking->is_booking_enabled( $listing_id ) ) {
return $form;
}
}
if ( $is_listing && hivepress()->get_version( 'marketplace' ) ) {
if ( get_option( 'hp_listing_allow_price_extras' ) ) {
$fields['price_extras']['fields']['type'] = [
'type' => 'select',
'options' => [
'per_order' => 'per booking',
'per_item' => 'per day',
],
'_order' => 30,
];
}
}
if ( $is_model ) {
$form = $fields;
} else {
$form['fields'] = $fields;
}
return $form;
}
Hi there Yevhen
Thanks for the snippet as its working. However it seems we need the default of per place per each and per booking .
Can you maybe explain how the calculations work for the per_quantity, per_item and per_order as some of these have recently been added and they’re a bit confusing as when playing around with the options and then checking the calculations when making the booking, the per place per each is doing as we want, but the wording of per_item sounds as though it should be doing the same.
So we would really appreciate some clarity as to the meanings and how the calculations work.
And then just the value for the per place per day option that we need to change in the snippet, as when checking the code in the browser, it doesn’t have a value. We just see value=“per_quantity”, value=“per_item” and value"per_order". The per place per each option just has value=“”.
THANKS again for the snippet and for the great support as always by the HivePress team!
yevhen
June 16, 2023, 12:49am
8
Here is a short explanation of how the calculation works for each price extras type
per_quantity - the extra price total amount depends on the number of guests which is chosen in the booking make form in the field Place by the user
per_item - the extra price total amount depends on the number of chosen dates
per_order - the extra price amount adds to the order’s total price and does not depend on the number of guests or the number of chosen dates
THANKS Yevhen.
That explains things great and we managed to change the snippet to work as we want it to.
system
Closed
July 16, 2023, 4:29pm
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.