Support

Account

Home Forums General Issues New to ACF – Need an Advise Reply To: New to ACF – Need an Advise

  • 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.