Last active
August 29, 2015 14:01
-
-
Save igmoweb/1d378819a864c1d899f8 to your computer and use it in GitHub Desktop.
Displaying new custom option in WooCommerce
This file contains 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' ) ); | |
// Muestra nuestro campo especial | |
add_action( 'woocommerce_admin_field_holadolly_special_field', array( &$this, 'display_special_field' ) ); | |
} | |
public function display_special_field( $field ) { | |
var_dump( $field ); | |
} | |
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', 'hola-dolly' ), | |
'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