• I am working on a woocommerce plugin extension and i would like to ask how to get value of some field from setting. Like I have checkout page and i would like to make here a list choice and the choices have to be editable.

    Here is code which creating fields in setting:

    class WC_checkout_extension {
        /**
         * Bootstraps the class and hooks required actions & filters.
         *
         */
        public static function init() {
            add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 );
            add_action( 'woocommerce_settings_tabs_settings_tab_demo', __CLASS__ . '::settings_tab' );
            add_action( 'woocommerce_update_options_settings_tab_demo', __CLASS__ . '::update_settings' );
        }
    
        /**
         * Add a new settings tab to the WooCommerce settings tabs array.
         *
         * @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
         * @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
         */
        public static function add_settings_tab( $settings_tabs ) {
            $settings_tabs['settings_tab_demo'] = __( 'Platební roz?í?ení', 'woocommerce-settings-tab-demo' );
            return $settings_tabs;
        }
        /**
         * Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
         *
         * @uses woocommerce_admin_fields()
         * @uses self::get_settings()
         */
        public static function settings_tab() {
            woocommerce_admin_fields( self::get_settings() );
        }
        /**
         * Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
         *
         * @uses woocommerce_update_options()
         * @uses self::get_settings()
         */
        public static function update_settings() {
            woocommerce_update_options( self::get_settings() );
        }
        /**
         * Get all the settings for this plugin for @see woocommerce_admin_fields() function.
         *
         * @return array Array of settings for @see woocommerce_admin_fields() function.
         */
        public static function get_settings() {
            $settings = array(
                'section_title' => array(
                    'name'     => __( 'Nastavení událostí, kde p?evzít (zatím je?tě není nefunguje).', 'woocommerce-settings-tab-demo' ),
                    'type'     => 'title',
                    'desc'     => '',
                    'id'       => 'WC_checkout_extension_section_title'
                ),
                'action1' => array(
                    'name' => __( 'Akce 1', 'woocommerce-settings-tab-demo' ),
                    'type' => 'text',
                    'desc' => __( 'Napi? datum a název akce, pro p?evzetí.', 'woocommerce-settings-tab-demo' ),
                    'id'   => 'WC_checkout_extension_action1'
                ),
                'action2' => array(
                    'name' => __( 'Akce 2', 'woocommerce-settings-tab-demo' ),
                    'type' => 'text',
                    'desc' => __( 'Napi? datum a název akce, pro p?evzetí.', 'woocommerce-settings-tab-demo' ),
                    'id'   => 'WC_checkout_extension_action2'
                ),
                'action3' => array(
                    'name' => __( 'Akce 3', 'woocommerce-settings-tab-demo' ),
                    'type' => 'text',
                    'desc' => __( 'Napi? datum a název akce, pro p?evzetí.', 'woocommerce-settings-tab-demo' ),
                    'id'   => 'WC_checkout_extension_action3'
                ),
                'action4' => array(
                    'name' => __( 'Akce 4', 'woocommerce-settings-tab-demo' ),
                    'type' => 'text',
                    'desc' => __( 'Napi? datum a název akce, pro p?evzetí.', 'woocommerce-settings-tab-demo' ),
                    'id'   => 'WC_checkout_extension_action4'
                ),
                'action5' => array(
                    'name' => __( 'Akce 5', 'woocommerce-settings-tab-demo' ),
                    'type' => 'text',
                    'desc' => __( 'Napi? datum a název akce, pro p?evzetí.', 'woocommerce-settings-tab-demo' ),
                    'id'   => 'WC_checkout_extension_action5'
                ),
            );
            return apply_filters( 'WC_checkout_extension_settings', $settings );
        }
    }
    WC_checkout_extension::init();

    And i need to get values of fields into this list:

    function kia_filter_checkout_fields($fields){
    $fields['extra_fields'] = array(
            'another_field' => array(
                'type' => 'select',
                'options' => array( 'a' => __('Akce 1'), 'b' => __( 'Akce 2' ), 'c' => __( 'Akce 3' ) ),
                'required'      => false,
                'label' => __( 'Vyber si akci, na které bys chtěl objednávku vyzvednout' )
                )
            );
    
    return $fields;
     }
    add_filter( 'woocommerce_checkout_fields', 'kia_filter_checkout_fields');

    Thanks for help

    https://www.ads-software.com/plugins/woocommerce/

  • The topic ‘Checkout extension – get value of field from setting’ is closed to new replies.