Home Forums General Issues New to ACF – Need an Advise


New to ACF – Need an Advise

  • Hey

    I’m building a tourist website and my theme support only 1 price per tour (single page), and my client want to sell each tour as a package which mean that the user should choose the level of hotel (3 levels) and than the bedrooms quantity (3 options) – that results with 9 prices per tour.

    I need at the Back End to add 9 fields to set each option price
    and at the Single Tour Front End 2 drop down (Level of Hotel + Bedrooms quantity) – which once the user select, it will update the tour price.

    I’m new to ACF – so I would appreciate any advise, how should I set it?

    Should I set 9 fields at the back End (at the Tour Edit page) to set the price for each option OR can I set one field with 9 fields ?

    How Should I display it at the front end ?

    How should I pass the selected parameters to update the Tour Price ?

    Once again. I will appreciate any advise 🙂


  • I think you’re going to need to use jQuery to run a script after the appropriate field has been selected. JQuery is JavaScript that you can use to manipulate values from the HTML.

    If I understand you, you have two fields: one for the hotel and one for the bedrooms. So, run jQuery after the second field is selected and store the price in a third field. You can do the same thing on the back end or calculate when the post is saved.
    I don’t think you need nine fields.

    You could have one pulldown with the hotel level, another with the number of bedrooms and a third text field that gets updated with the price after saving. That would be a simple IF ELSE script.

    Another option is to create one pulldown displaying and explaining the nine options, and setting the value of the option as the price. So what the person sees as is “Hotel level 1, 1 bedroom”, but the value of the choice is the price associated with that selection. This can be done when the ACF field is created.

    Hope this helps. I’m not entirely sure if I am seeing what you are trying to do though.

  • @bosoxbill’s suggestion is what I would do. 2 select fields and a text/number field for the price. This will take custom jQuery as he indicates. I have some examples of custom code that gets values from fields and updates other fields, most of it uses AJAX, which you might need to get the price to set.

    You’re also going to need a place in the admin for the client to set the actual prices for the different combinations. Basically, a field in the admin that is not available on the front end. Exactly how you’re going to do this I can’t say. The best solution would be that the client has a “Base Price” and that all of the other values are derived from some type of calculation based on this price. This part really depends on what the client needs and how they set the prices for the different options.

  • I overlooked a place to store the price for each package. I was thinking that these would be hidden programmatically.

    So, you may have to create a field for the price of each of the package (nine fields). When creating the fields, set the default value for each one to the price you want.

    Then create a front-end form that only shows the fields that you want. You would still have access to price fields on the back end.

    The code for the functions file could look something like this, assuming these fields: pulldowns (hotel_level [values: 1,2,3], bedrooms [values:1,2,3]), text fields (price_1, price_2, price_3, price_4, price_5, price_6, price_7, price_8, price_8, price_9, total):

    function update_guest_package_price(){
    	$total_price = 0;
    if(get_field('hotel_level') == '1' && get_field('bedrooms')  == 1){
    	$total_price = get_field('price_1');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '1' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_2');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '1' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_3');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 1){
    	$total_price = get_f5eld('price_4');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_5');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_6');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '3' && get_field('bedrooms')  == 1){
    	$total_price = get_field('price_7');
    	update_field( 'total', $total_price);
    elseif( get_field('hotel_level') == '3' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_8');
    	update_field( 'total', $total_price);
    elseif(get_field('hotel_level') == '3' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_9');
    	update_field( 'total', $total_price);
    add_action('acf/save_post', 'update_guest_package_price', 20);

    I have not tested this code, but this is the general idea where you use conditional logic based on the selected fields to obtain the desired output.

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

The topic ‘New to ACF – Need an Advise’ is closed to new replies.