custom plugin – custom post type -Selectable options for User

Currently i am writing my first own WordPress plugin and I have a few problems.
I read / did a lot of tutorials, but i have the feeling that I’m not moving forwards.

I can create my own Posttyp “rentable_car”
I also can add own metadata like “build year”

So far so good.
But now i want to add the possibility, to add different options (“Extras”) from a list i have to create – for example “big music system”, “car cleaning service” etc. to each specific car in the admin menu.

in the frontend, the user should have the possibility to check one or more of these options.

The next step is, that i want to add a price for each of these Extras. Also i want to be able to set a tax for each extra.

In short:

  • I want to be able to give my car a list of possible extra features (admin area)
  • I want to be able to give these extra features prices and taxes (admin area)
  • I want the user to be able, to choose from this list one or many features for the specific car.

Could anyone help me?
I don’t want you write the code I need, but I need an push in the right direction.

1 Answer
1

For the admin part I would recommend using the plugin Advanced Custom Fields (ACF). You could however also use the built in meta boxes – but it’s a bit difficult to get started with and I have the feeling that this would be a bit ‘too much’ for now.

ACF lets you add field to post types – also to custom post types.

Inside your template file you can then again use the values entered into those fields like this:

<?PHP 

$field_value = get_field('name_of_the_field');

echo($field_value);

?>

As I mentioned above this is just for the admin part – just for getting custom fields for your post types and then get the data sets of your post types printed.

Getting the user make a selection based on those data sets is a whole different / more complex story. AFAIK for that you would basically not create a new page per data set, but a new form.

UPDATE: a.f.a.i.k. you can always include custom fields made with ACF by exporting them as PHP and then adding the function to your plugin file:

To include fields via PHP, please use the ACF export tool and copy the generated PHP code into your theme / plugin …

http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

Leave a Comment