normalize_settings_args( $args ) ); // output checkbox printf( '', $id, $setting_name, $value, checked( $value, $current, false ), $class ); // output description. if ( isset( $description ) ) { printf( '

%s

', $description ); } } /** * Text input callback. * * args: * option_name - name of the main option * id - key of the setting * size - size of the text input (em) * default - default setting (optional) * description - description (optional) * type - type (optional) * * @return void. */ public function text_input( $args ) { extract( $this->normalize_settings_args( $args ) ); // echo '
';var_dump($this->normalize_settings_args( $args ));echo '
'; if (empty($type)) { $type = 'text'; } if ($type == 'number') { $width = ($size * 10) + 25; $style = "width: {$width}px"; } else { $style = ''; } printf( '', $type, $id, $setting_name, $current, $size, $placeholder, $class, $style ); // output description. if ( isset( $description ) ) { printf( '

%s

', $description ); } } /** * Color picker callback. * * args: * option_name - name of the main option * id - key of the setting * size - size of the text input (em) * default - default setting (optional) * description - description (optional) * * @return void. */ public function color_picker( $args ) { extract( $this->normalize_settings_args( $args ) ); // echo '
';var_dump($this->normalize_settings_args( $args ));echo '
'; printf( '', $id, $setting_name, $current, $size, $class ); // output description. if ( isset( $description ) ) { printf( '

%s

', $description ); } } /** * Textarea callback. * * args: * option_name - name of the main option * id - key of the setting * width - width of the text input (em) * height - height of the text input (lines) * default - default setting (optional) * description - description (optional) * * @return void. */ public function textarea( $args ) { extract( $this->normalize_settings_args( $args ) ); printf( '', $id, $setting_name, $current, $width, $height, $placeholder ); // output description. if ( isset( $description ) ) { printf( '

%s

', $description ); } } /** * Select element callback. * * @param array $args Field arguments. * * @return string Select field. */ public function select( $args ) { extract( $this->normalize_settings_args( $args ) ); printf( ''; if (isset($custom)) { printf( '
', $id ); switch ($custom['type']) { case 'text_element_callback': $this->text_input( $custom['args'] ); break; case 'multiple_text_element_callback': $this->multiple_text_input( $custom['args'] ); break; default: break; } echo '
'; } // Displays option description. if ( isset( $args['description'] ) ) { printf( '

%s

', $args['description'] ); } } public function radio_button( $args ) { extract( $this->normalize_settings_args( $args ) ); foreach ( $options as $key => $label ) { printf( '', $id, $setting_name, $key, checked( $current, $key, false ) ); printf( '
', $id, $setting_name, $key, $label); } // Displays option description. if ( isset( $args['description'] ) ) { printf( '

%s

', $args['description'] ); } } /** * Multiple text element callback. * @param array $args Field arguments. * @return string Text input field. */ public function multiple_text_input( $args ) { extract( $this->normalize_settings_args( $args ) ); if (!empty($header)) { echo "

{$header}:

"; } foreach ($fields as $name => $field) { $label = $field['label']; $size = $field['size']; $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; if (isset($field['label_width'])) { $style = sprintf( 'style="display:inline-block; width:%1$s;"', $field['label_width'] ); } else { $style = ''; } $suffix = isset($field['suffix']) ? $field['suffix'] : ''; // output field label printf( '', $id, $name, $style, $label ); // output field $field_current = isset($current[$name]) ? $current[$name] : ''; printf( '%7$s
', $id, $setting_name, $name, $field_current, $size, $placeholder, $suffix ); } // Displays option description. if ( isset( $args['description'] ) ) { printf( '

%s

', $args['description'] ); } } public function order_status_select( $args ) { // get list of WooCommerce statuses if ( version_compare( WOOCOMMERCE_VERSION, '2.2', '<' ) ) { $statuses = (array) get_terms( 'shop_order_status', array( 'hide_empty' => 0, 'orderby' => 'id' ) ); foreach ( $statuses as $status ) { $order_statuses[esc_attr( $status->slug )] = esc_html__( $status->name, 'woocommerce' ); } } else { $statuses = wc_get_order_statuses(); foreach ( $statuses as $status_slug => $status ) { $status_slug = 'wc-' === substr( $status_slug, 0, 3 ) ? substr( $status_slug, 3 ) : $status_slug; $order_statuses[$status_slug] = $status; } } // select order status $args['options'] = $order_statuses; $this->select( $args ); } public function shipping_methods_package_types( $args ) { extract( $this->normalize_settings_args( $args ) ); foreach ($package_types as $package_type => $package_type_title) { printf ('
%s:
', $package_type_title); $args['package_type'] = $package_type; unset($args['description']); $this->shipping_method_search( $args ); } // Displays option description. if ( isset( $description ) ) { printf( '

%s

', $description ); } } // Shipping method search callback. public function shipping_method_search( $args ) { extract( $this->normalize_settings_args( $args ) ); if (isset($package_type)) { $setting_name = "{$setting_name}[{$package_type}]"; $current = isset($current[$package_type]) ? $current[$package_type] : ''; } // get shipping methods $available_shipping_methods = array(); $shipping_methods = WC()->shipping->load_shipping_methods(); // echo '
';var_dump($shipping_methods);echo '
'; if ( $shipping_methods ) { foreach ( $shipping_methods as $key => $shipping_method ) { // Automattic / WooCommerce Table Rate Shipping if ( $key == 'table_rate' && class_exists('WC_Table_Rate_Shipping') && class_exists('WC_Shipping_Zones')) { $zones = WC_Shipping_Zones::get_zones(); foreach ($zones as $zone_data) { if (isset($zone_data['id'])) { $zone_id = $zone_data['id']; } elseif (isset($zone_data['zone_id'])) { $zone_id = $zone_data['zone_id']; } else { continue; } $zone = WC_Shipping_Zones::get_zone($zone_id); $zone_methods = $zone->get_shipping_methods( false ); foreach ( $zone_methods as $key => $shipping_method ) { if ( $shipping_method->id == 'table_rate' && method_exists( $shipping_method, 'get_shipping_rates') ) { $zone_table_rates = $shipping_method->get_shipping_rates(); foreach ($zone_table_rates as $zone_table_rate) { $rate_label = ! empty( $zone_table_rate->rate_label ) ? $zone_table_rate->rate_label : "{$shipping_method->title} ({$zone_table_rate->rate_id})"; $available_shipping_methods["table_rate:{$shipping_method->instance_id}:{$zone_table_rate->rate_id}"] = "{$zone->get_zone_name()} - {$rate_label}"; } } } } continue; } // Bolder Elements Table Rate Shipping if ( $key == 'betrs_shipping' && is_a($shipping_method, 'BE_Table_Rate_Method') && class_exists('WC_Shipping_Zones') ) { $zones = WC_Shipping_Zones::get_zones(); foreach ($zones as $zone_data) { if (isset($zone_data['id'])) { $zone_id = $zone_data['id']; } elseif (isset($zone_data['zone_id'])) { $zone_id = $zone_data['zone_id']; } else { continue; } $zone = WC_Shipping_Zones::get_zone($zone_id); $zone_methods = $zone->get_shipping_methods( false ); foreach ( $zone_methods as $key => $shipping_method ) { if ( $shipping_method->id == 'betrs_shipping' ) { $shipping_method_options = get_option( $shipping_method->id . '_options-' . $shipping_method->instance_id ); if (isset($shipping_method_options['settings'])) { foreach ($shipping_method_options['settings'] as $zone_table_rate) { $rate_label = ! empty( $zone_table_rate['title'] ) ? $zone_table_rate['title'] : "{$shipping_method->title} ({$zone_table_rate['option_id']})"; $available_shipping_methods["betrs_shipping_{$shipping_method->instance_id}-{$zone_table_rate['option_id']}"] = "{$zone->get_zone_name()} - {$rate_label}"; } } } } } continue; } $method_title = !empty($shipping_methods[$key]->method_title) ? $shipping_methods[$key]->method_title : $shipping_methods[$key]->title; $available_shipping_methods[ $key ] = $method_title; // split flat rate by shipping class if ( ( $key == 'flat_rate' || $key == 'legacy_flat_rate' ) && version_compare( WOOCOMMERCE_VERSION, '2.4', '>=' ) ) { $shipping_classes = WC()->shipping->get_shipping_classes(); foreach ($shipping_classes as $shipping_class) { if ( ! isset( $shipping_class->term_id ) ) { continue; } $id = $shipping_class->term_id; $name = esc_html( "{$method_title} - {$shipping_class->name}" ); $method_class = esc_attr( $key ).":".$id; $available_shipping_methods[ $method_class ] = $name; } } } } ?> %s

', $description ); } } public function enhanced_select( $args ) { extract( $this->normalize_settings_args( $args ) ); ?> %s

', $description ); } } public function delivery_option_enable( $args ) { extract( $this->normalize_settings_args( $args ) ); // checkbox (enable) $cb_args = array( 'id' => "{$id}_enabled", 'class' => 'wcmp_delivery_option' ); // number (fee) $fee_args = array( 'id' => "{$id}_fee", 'type' => 'text', 'size' => '5', ); ?> checkbox( array_merge( $args, $cb_args ) ); ?>
: € text_input( array_merge( $args, $fee_args ) ); ?>
normalize_settings_args( $args ) ); ?>
$title) { // prepare args for input fields $common_args = array ( 'option_name' => "{$option_name}[{$key}]", ); // checkbox (enable) $cb_args = array( 'id' => 'enabled', ); // number (fee) $fee_args = array( 'id' => 'fee', 'type' => 'number', 'size' => '5', ); // textarea (description) $description_args = array( 'id' => 'description', 'width' => '50', 'height' => '4', ); ?>
checkbox( array_merge( $common_args, $cb_args ) ); ?>
normalize_settings_args( $args ) ); if ( $languages = $this->get_languages() ) { printf( '
', $option_name, $id) ?>
    $language_name ) { $translation_id = "{$option_name}_{$id}_{$lang_code}"; printf('
  • %s
  • ', $translation_id, $language_name ); } ?>
$language_name ) { $translation_id = "{$option_name}_{$id}_{$lang_code}"; printf( '
', $translation_id ); $args['lang'] = $lang_code; call_user_func( array( $this, $callback ), $args ); echo '
'; } ?>
$data) { $languages[$data['language_code']] = $data['native_name']; } } else { return false; } return $languages; } public function normalize_settings_args ( $args ) { $args['value'] = isset( $args['value'] ) ? $args['value'] : 1; $args['placeholder'] = isset( $args['placeholder'] ) ? $args['placeholder'] : ''; $args['class'] = isset( $args['class'] ) ? $args['class'] : ''; // get main settings array $option = get_option( $args['option_name'] ); $args['setting_name'] = "{$args['option_name']}[{$args['id']}]"; if (isset($args['lang'])) { // i18n settings name $args['setting_name'] = "{$args['setting_name']}[{$args['lang']}]"; // copy current option value if set if ( $args['lang'] == 'default' && !empty($option[$args['id']]) && !isset( $option[$args['id']]['default'] ) ) { // we're switching back from WPML to normal // try english first if ( isset( $option[$args['id']]['en'] ) ) { $args['current'] = $option[$args['id']]['en']; } else { // fallback to the first language if english not found $first = array_shift($option[$args['id']]); if (!empty($first)) { $args['current'] = $first; } } } else { if ( isset( $option[$args['id']][$args['lang']] ) ) { $args['current'] = $option[$args['id']][$args['lang']]; } elseif (isset( $option[$args['id']]['default'] )) { $args['current'] = $option[$args['id']]['default']; } } } else { // copy current option value if set if ( isset( $option[$args['id']] ) ) { $args['current'] = $option[$args['id']]; } } // falback to default or empty if no value in option if ( !isset($args['current']) ) { $args['current'] = isset( $args['default'] ) ? $args['default'] : ''; } return $args; } /** * Validate options. * * @param array $input options to valid. * * @return array validated options. */ public function validate( $input ) { // Create our array for storing the validated options. $output = array(); if (empty($input) || !is_array($input)) { return $input; } // Loop through each of the incoming options. foreach ( $input as $key => $value ) { // Check to see if the current option has a value. If so, process it. if ( isset( $input[$key] ) ) { if ( is_array( $input[$key] ) ) { foreach ( $input[$key] as $sub_key => $sub_value ) { $output[$key][$sub_key] = $input[$key][$sub_key]; } } else { $output[$key] = $input[$key]; } } } // Return the array processing any additional functions filtered by this action. return apply_filters( 'woocommerce_postnl_settings_validate_input', $input, $input ); } } endif; // class_exists return new WooCommerce_PostNL_Settings_Callbacks();