id = 'shipping'; $this->label = __( 'Shipping', 'woocommerce' ); add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); add_action( 'woocommerce_admin_field_shipping_methods', array( $this, 'shipping_methods_setting' ) ); add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); } /** * Get sections * * @return array */ public function get_sections() { $sections = array( '' => __( 'Shipping Options', 'woocommerce' ) ); // Load shipping methods so we can show any global options they may have $shipping_methods = WC()->shipping->load_shipping_methods(); foreach ( $shipping_methods as $method ) { if ( ! $method->has_settings() ) continue; $title = empty( $method->method_title ) ? ucwords( $method->id ) : ucwords( $method->method_title ); $sections[ strtolower( get_class( $method ) ) ] = esc_html( $title ); } return $sections; } /** * Get settings array * * @return array */ public function get_settings() { return apply_filters('woocommerce_shipping_settings', array( array( 'title' => __( 'Shipping Options', 'woocommerce' ), 'type' => 'title', 'id' => 'shipping_options' ), array( 'title' => __( 'Shipping Calculations', 'woocommerce' ), 'desc' => __( 'Enable shipping', 'woocommerce' ), 'id' => 'woocommerce_calc_shipping', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'start' ), array( 'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ), 'id' => 'woocommerce_enable_shipping_calc', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => '', 'autoload' => false ), array( 'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ), 'id' => 'woocommerce_shipping_cost_requires_address', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'end', 'autoload' => false ), array( 'title' => __( 'Shipping Method Display', 'woocommerce' ), 'desc' => __( 'This controls how multiple shipping methods are displayed on the frontend.', 'woocommerce' ), 'id' => 'woocommerce_shipping_method_format', 'css' => 'min-width:150px;', 'default' => '', 'type' => 'select', 'options' => array( '' => __( 'Radio buttons', 'woocommerce' ), 'select' => __( 'Select box', 'woocommerce' ), ), 'desc_tip' => true, 'autoload' => false ), array( 'title' => __( 'Shipping Destination', 'woocommerce' ), 'desc' => __( 'Only ship to the users billing address', 'woocommerce' ), 'id' => 'woocommerce_ship_to_billing_address_only', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'start', 'autoload' => false ), array( 'desc' => __( 'Ship to billing address by default', 'woocommerce' ), 'id' => 'woocommerce_ship_to_billing', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => '', 'autoload' => false ), array( 'desc' => __( 'Collect shipping address even when not required', 'woocommerce' ), 'id' => 'woocommerce_require_shipping_address', 'default' => 'no', 'type' => 'checkbox', 'checkboxgroup' => 'end', 'autoload' => false ), array( 'type' => 'shipping_methods', ), array( 'type' => 'sectionend', 'id' => 'shipping_options' ), )); // End shipping settings } /** * Output the settings */ public function output() { global $current_section; // Load shipping methods so we can show any global options they may have $shipping_methods = WC()->shipping->load_shipping_methods(); if ( $current_section ) { foreach ( $shipping_methods as $method ) { if ( strtolower( get_class( $method ) ) == $current_section && $method->has_settings() ) { $method->admin_options(); break; } } } else { $settings = $this->get_settings(); WC_Admin_Settings::output_fields( $settings ); } } /** * Output shipping method settings. * * @access public * @return void */ public function shipping_methods_setting() { ?>

shipping->load_shipping_methods() as $method ) { $default_shipping_method = esc_attr( get_option('woocommerce_default_shipping_method') ); echo ''; } ?>
id, false ) . ' />

' . $method->get_title() . '
' . __( 'Method ID', 'woocommerce' ) . ': ' . $method->id . '

'; if ( $method->enabled == 'yes' ) echo '' . __ ( 'Enabled', 'woocommerce' ) . ''; echo '
get_settings(); WC_Admin_Settings::save_fields( $settings ); WC()->shipping->process_admin_options(); } elseif ( class_exists( $current_section ) ) { $current_section_class = new $current_section(); do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section_class->id ); WC()->shipping()->init(); } } } endif; return new WC_Settings_Shipping();