Skip to content

Instantly share code, notes, and snippets.

@igmoweb
Created May 20, 2014 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igmoweb/069cfde118538478a0dc to your computer and use it in GitHub Desktop.
Save igmoweb/069cfde118538478a0dc to your computer and use it in GitHub Desktop.
Adding custom options with WooCommerce Settings API
<?php
class WC_Settings_Hola_Dolly extends WC_Settings_Page {
public function __construct() {
$this->id = 'hola-dolly';
$this->label = __( 'Hola Dolly', 'hola-dolly' );
// Añadir pestaña
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
// Mostrar los campos
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
// Guardar los cambios
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
public function get_settings() {
$settings = array(
array( 'title' => __( 'Opciones Generales', 'hola-dolly' ), 'type' => 'title', 'id' => 'holadolly_general_options', 'desc' => __( 'Nuestras opciones generales.', 'hola-dolly' ) ),
array(
'title' => __( 'Un número', 'hola-dolly' ),
'id' => 'holadolly_general_options_number',
'default' => 0,
'type' => 'number',
'desc_tip' => __( 'Pon un número por aquí', 'hola-dolly' )
),
array( 'type' => 'sectionend', 'id' => 'holadolly_general_options' ),
array( 'title' => __( 'Opciones Especiales', 'hola-dolly' ), 'type' => 'title', 'id' => 'holadolly_special_options', 'desc' => __( 'Nuestras opciones especiales.', 'hola-dolly' ) ),
// Aquí va nuestro campo especial encerrado en una nueva sección
array(
'title' => __( 'Campo especial', 'wookings' ),
'id' => 'holadolly_general_options_special',
'default' => '',
'type' => 'holadolly_special_field'
),
array( 'type' => 'sectionend', 'id' => 'holadolly_special_options' ),
);
return apply_filters( 'holadolly_woocommerce_holadolly_settings', $settings );
}
}
new WC_Settings_Hola_Dolly();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment