precio en las categorias de vehiculo
class vehicle_type_price {
public function __construct() {
if ( is_admin() ) {
add_action( 'tipos_de_vehiculos_add_form_fields', array( $this, 'create_screen_fields'), 10, 1 );
add_action( 'tipos_de_vehiculos_edit_form_fields', array( $this, 'edit_screen_fields' ), 10, 2 );
add_action( 'created_tipos_de_vehiculos', array( $this, 'save_data' ), 10, 1 );
add_action( 'edited_tipos_de_vehiculos', array( $this, 'save_data' ), 10, 1 );
}
}
public function create_screen_fields( $taxonomy ) {
// Set default values.
$vtp-vehicle_price = '1.00';
// Form fields.
echo '<div class="form-field term-vtp-vehicle_price-wrap">';
echo ' <label for="vtp-vehicle_price">' . __( 'Precio mínimo', 'innubel' ) . '</label>';
echo ' <input type="number" id="vtp-vehicle_price" name="vtp-vehicle_price" placeholder="' . esc_attr__( 'Precio mínimo', 'innubel' ) . '" value="' . esc_attr( $vtp-vehicle_price ) . '">';
echo ' <p class="description">' . __( 'Precio mínimo para calcular el presupuesto', 'innubel' ) . '</p>';
echo '</div>';
}
public function edit_screen_fields( $term, $taxonomy ) {
// Retrieve an existing value from the database.
$vtp-vehicle_price = get_term_meta( $term->term_id, 'vtp-vehicle_price', true );
// Set default values.
if( empty( $vtp-vehicle_price ) ) $vtp-vehicle_price = '1.00';
// Form fields.
echo '<tr class="form-field term-vtp-vehicle_price-wrap">';
echo '<th scope="row">';
echo ' <label for="vtp-vehicle_price">' . __( 'Precio mínimo', 'innubel' ) . '</label>';
echo '</th>';
echo '<td>';
echo ' <input type="number" id="vtp-vehicle_price" name="vtp-vehicle_price" placeholder="' . esc_attr__( 'Precio mínimo', 'innubel' ) . '" value="' . esc_attr( $vtp-vehicle_price ) . '">';
echo ' <p class="description">' . __( 'Precio mínimo para calcular el presupuesto', 'innubel' ) . '</p>';
echo '</td>';
echo '</tr>';
}
public function save_data( $term_id ) {
// Sanitize user input.
$vtp-new_vehicle_price = isset( $_POST[ 'vtp-vehicle_price' ] ) ? floatval( $_POST[ 'vtp-vehicle_price' ] ) : '';
// Update the meta field in the database.
update_term_meta( $term_id, 'vtp-vehicle_price', $vtp-new_vehicle_price );
}
}
new vehicle_type_price;