Created
May 20, 2014 12:02
-
-
Save igmoweb/069cfde118538478a0dc to your computer and use it in GitHub Desktop.
Adding custom options with WooCommerce Settings API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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