0.00  View cart

Support WooCommerce Easy Booking Customize Total Booking Duration text

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7848
    Antonio
    Participant

    Hi there,

    I’m trying to customize the Total Booking Duration text with the easy_booking_booking_price_details filter, but I’m stuck.

    This is my code so far:

    add_filter( ‘easy_booking_booking_price_details’, ‘easy_bookings_price_details_custom_text’ );

    function easy_bookings_price_details_custom_text( $details, $product, $booking_data ) {
    // this is where I should be able to insert amazing code
    return $details;
    }

    If I add $details = ‘My custom text’; it replaces the text, but the duration and unit will disappear.
    I think I’m missing some parameters from the filter, but I don’t know where to get them.

    Can you help me?

    Thanks!!

    #7850
    Ashanna
    Plugin's author

    Hello,

    To add text after the existing details, you need to do this:

    add_filter( 'easy_booking_booking_price_details', 'easy_bookings_price_details_custom_text', 10, 3 );
    
    function easy_bookings_price_details_custom_text( $details, $product, $booking_data ) {
        $details .= '<br />'; // Add a line break
        $details .= 'My custom text';
        return $details;
    }

    Don’t forget the . before =, so it adds text and not replaces it.

    Concerning parameters, $details is the existing details, $product is the product object and $booking_data is an array of information about the selection (dates, duration, price, etc.).

    I can help more if you tell me exactly what you need 🙂

    Regards,
    Natasha

    #7851
    Antonio
    Participant

    Hi there!

    Thanks for the quick reply.

    What that code does is to add more text to the details. What I need to do is to replace the text.

    Right now it reads:

    Total booking duration: 2 days

    I need to change it to something like this:

    My custom text: 2 days

     

    😉

    #7852
    Antonio
    Participant

    I managed to change the text this way:

    add_filter( 'easy_booking_booking_price_details', 'easy_bookings_price_details_custom_text' );
    
    function easy_bookings_price_details_custom_text( $details ) {
    	$details=str_replace('Total booking duration', 'My custom text', $details);
    	return$details;
    }

     

    Is it ok, or is there an easier way to do it?

    Thanks!

    • This reply was modified 5 days, 11 hours ago by Antonio.
    • This reply was modified 5 days, 11 hours ago by Antonio.
    #7855
    Ashanna
    Plugin's author

    Ah allright sorry, I misunderstood.

    This filter is not practical to use, I need to improve it.

    In your case, I guess the easiest way would be to use translation files but your solution is ok too.

    #7856
    Antonio
    Participant

    Ok, thanks!

    Just out of curiosity, and probably not directly related to your plugin, how would you extract the variables inside a parameter in this function?

    Say I want to find out which variables are inside $booking_data. If I use var_dump($booking_data) or print_r($booking_data) inside the function I get no return.

    This is probably more related to my lack of knowledge than with the function itself. :/

    #7857
    Ashanna
    Plugin's author

    The result is sent to a javascript file and not displayed directly in PHP, this is why you don’t see it. To see the result you need to do the following:

    • Open your browser’s developer tools (F12 on Windows)
    • Go to the “Network” tab
    • Select dates, you should see a “add_new_price” request, click on it
    • Go to the “Response” tab

    Here’s what’s inside $booking_data:

    $start = $booking_data['start'];
    $end = $booking_data['end']; // Optional (two dates only)
    $duration = $booking_data['duration'];
    $new_price = $booking_data['new_price'];
    $new_regular_price = $booking_data['new_regular_price']; // Optional (if product is on sale)

    And I’m currently adding quantity aswell for a future update.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Want to know what's next with Easy Booking? Check the roadmap!