Skip to content

Instantly share code, notes, and snippets.

@kutoi94
Created July 12, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kutoi94/0dd5b3f1d930d944e729dfbc9a3fc406 to your computer and use it in GitHub Desktop.
Save kutoi94/0dd5b3f1d930d944e729dfbc9a3fc406 to your computer and use it in GitHub Desktop.
Create custom field in product details page by meta box plugin
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array (
'title' => 'Car Rental',
'id' => 'car-rental',
'post_types' => array(
0 => 'car-rental',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array (
'id' => 'price',
'type' => 'number',
'name' => 'Rental price',
'required' => 1,
'prepend' => '$',
),
array (
'id' => 'car_year',
'type' => 'number',
'name' => 'Car Year',
'required' => 1,
),
array (
'id' => 'max_passengers',
'type' => 'number',
'name' => 'Max passengers',
'required' => 1,
),
array (
'id' => 'fuel',
'name' => 'Fuel',
'type' => 'select',
'placeholder' => 'Select an Item',
'options' => array(
'Gasoline' => 'Gasoline',
'Petrol' => 'Petrol',
'Electricity' => 'Electricity',
),
'required' => 1,
),
array (
'id' => 'door',
'name' => 'Door',
'type' => 'select',
'placeholder' => 'Select an Item',
'options' => array(
2 => '2',
4 => '4',
5 => '5',
),
'required' => 1,
),
array (
'id' => 'gearbox',
'name' => 'Gearbox',
'type' => 'select',
'placeholder' => 'Select an Item',
'options' => array(
'Tiptronic' => 'Tiptronic',
'Manuatic' => 'Manuatic',
),
'required' => 1,
),
array (
'id' => 'fuel_usage',
'type' => 'text',
'name' => 'Fuel Usage',
'desc' => 'Ex: 101/100km',
),
array (
'id' => 'engine_capacity',
'type' => 'text',
'name' => 'Engine capacity',
'desc' => 'Ex: 2500 cc',
),
array (
'id' => 'max_luggage',
'type' => 'text',
'name' => 'Max luggage',
),
array (
'id' => 'mileage',
'type' => 'text',
'name' => 'Mileage',
'desc' => 'Ex: 500km or Unlimited',
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes_2' );
function your_prefix_register_meta_boxes_2( $meta_boxes ) {
$meta_boxes[] = array (
'title' => 'Car rental - Side',
'id' => 'car-rental-side',
'post_types' => array(
0 => 'car-rental',
),
'context' => 'side',
'priority' => 'low',
'fields' => array(
array (
'id' => 'car_gallery',
'type' => 'image_advanced',
'name' => 'Car gallery',
'force_delete' => 1,
'max_file_uploads' => 7,
'image_size' => 'post-thumbnail',
'max_status' => true,
),
),
);
return $meta_boxes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment