WC_Settings_API::get_option()
Get option from DB.
Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
Method of the class: WC_Settings_API{}
No Hooks.
Return
String
. The value specified for the option or a default value for the option.
Usage
$WC_Settings_API = new WC_Settings_API(); $WC_Settings_API->get_option( $key, $empty_value );
- $key(string) (required)
- Option key.
- $empty_value(mixed)
- Value when empty.
Default: null
WC_Settings_API::get_option() WC Settings API::get option code WC 8.6.1
public function get_option( $key, $empty_value = null ) { if ( empty( $this->settings ) ) { $this->init_settings(); } // Get option default if unset. if ( ! isset( $this->settings[ $key ] ) ) { $form_fields = $this->get_form_fields(); $this->settings[ $key ] = isset( $form_fields[ $key ] ) ? $this->get_field_default( $form_fields[ $key ] ) : ''; } if ( ! is_null( $empty_value ) && '' === $this->settings[ $key ] ) { $this->settings[ $key ] = $empty_value; } return $this->settings[ $key ]; }