2013-07-26 14:36:28 +00:00
< ? php
/**
* WooCommerce Shipping Settings
*
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
* @ version 2.1 . 0
*/
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
if ( ! class_exists ( 'WC_Settings_Shipping' ) ) :
/**
* WC_Settings_Shipping
*/
class WC_Settings_Shipping extends WC_Settings_Page {
/**
* Constructor .
*/
public function __construct () {
$this -> 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 ;
2013-10-25 15:44:17 +00:00
$title = empty ( $method -> method_title ) ? ucfirst ( $method -> id ) : $method -> method_title ;
2013-07-26 14:36:28 +00:00
$sections [ strtolower ( get_class ( $method ) ) ] = esc_html ( $title );
}
2014-02-17 14:30:37 +00:00
return apply_filters ( 'woocommerce_get_sections_' . $this -> id , $sections );
2013-07-26 14:36:28 +00:00
}
/**
* 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 (
2014-04-08 15:28:27 +00:00
'title' => __ ( 'Shipping Display Mode' , 'woocommerce' ),
'desc' => __ ( 'This controls how multiple shipping methods are displayed on the frontend.' , 'woocommerce' ),
'id' => 'woocommerce_shipping_method_format' ,
'default' => '' ,
'type' => 'radio' ,
2013-07-26 14:36:28 +00:00
'options' => array (
2014-04-08 15:28:27 +00:00
'' => __ ( 'Display shipping methods with "radio" buttons' , 'woocommerce' ),
'select' => __ ( 'Display shipping methods in a dropdown' , 'woocommerce' ),
2013-07-26 14:36:28 +00:00
),
2014-04-08 15:28:27 +00:00
'desc_tip' => true ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-04-08 15:28:27 +00:00
'title' => __ ( 'Shipping Destination' , 'woocommerce' ),
'desc' => __ ( 'This controls which shipping address is used by default.' , 'woocommerce' ),
2014-04-08 15:29:29 +00:00
'id' => 'woocommerce_ship_to_destination' ,
2014-04-08 15:28:27 +00:00
'default' => 'shipping' ,
'type' => 'radio' ,
'options' => array (
2014-04-08 15:29:29 +00:00
'shipping' => __ ( 'Default to shipping address' , 'woocommerce' ),
2014-04-08 15:28:27 +00:00
'billing' => __ ( 'Default to billing address' , 'woocommerce' ),
'billing_only' => __ ( 'Only ship to the users billing address' , 'woocommerce' ),
),
2013-08-02 15:54:28 +00:00
'autoload' => false ,
2014-04-08 15:28:27 +00:00
'desc_tip' => true ,
2013-08-02 15:54:28 +00:00
'show_if_checked' => 'option' ,
2013-07-26 14:36:28 +00:00
),
array (
2013-08-02 15:54:28 +00:00
'title' => __ ( 'Restrict shipping to Location(s)' , 'woocommerce' ),
2013-10-22 16:26:18 +00:00
'desc' => sprintf ( __ ( 'Choose which countries you want to ship to, or choose to ship to all <a href="%s">locations you sell to</a>.' , 'woocommerce' ), admin_url ( 'admin.php?page=wc-settings&tab=general' ) ),
2013-08-02 15:54:28 +00:00
'id' => 'woocommerce_ship_to_countries' ,
'default' => '' ,
'type' => 'select' ,
'class' => 'chosen_select' ,
'desc_tip' => false ,
'options' => array (
'' => __ ( 'Ship to all countries you sell to' , 'woocommerce' ),
'all' => __ ( 'Ship to all countries' , 'woocommerce' ),
'specific' => __ ( 'Ship to specific countries only' , 'woocommerce' )
)
),
array (
'title' => __ ( 'Specific Countries' , 'woocommerce' ),
'desc' => '' ,
'id' => 'woocommerce_specific_ship_to_countries' ,
'css' => '' ,
'default' => '' ,
'type' => 'multi_select_countries'
2013-07-26 14:36:28 +00:00
),
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 ) {
2013-08-08 11:38:20 +00:00
if ( strtolower ( get_class ( $method ) ) == strtolower ( $current_section ) && $method -> has_settings () ) {
2013-07-26 14:36:28 +00:00
$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 () {
2013-10-01 09:02:22 +00:00
$default_shipping_method = esc_attr ( get_option ( 'woocommerce_default_shipping_method' ) );
2013-07-26 14:36:28 +00:00
?>
< tr valign = " top " >
< th scope = " row " class = " titledesc " >< ? php _e ( 'Shipping Methods' , 'woocommerce' ) ?> </th>
< td class = " forminp " >
< table class = " wc_shipping widefat " cellspacing = " 0 " >
< thead >
< tr >
2013-09-09 16:15:58 +00:00
< th class = " default " >< ? php _e ( 'Default' , 'woocommerce' ); ?> </th>
< th class = " name " >< ? php _e ( 'Name' , 'woocommerce' ); ?> </th>
< th class = " id " >< ? php _e ( 'ID' , 'woocommerce' ); ?> </th>
< th class = " status " >< ? php _e ( 'Status' , 'woocommerce' ); ?> </th>
< th class = " settings " >& nbsp ; </ th >
2013-07-26 14:36:28 +00:00
</ tr >
</ thead >
2013-09-09 16:15:58 +00:00
< tfoot >
2013-10-01 12:13:14 +00:00
< tr >
< th width = " 1% " class = " default " >
< input type = " radio " name = " default_shipping_method " value = " " < ? php checked ( $default_shipping_method , '' ); ?> />
</ th >
2014-04-23 13:24:20 +00:00
< th >< ? php _e ( 'Automatic' , 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'The cheapest available shipping method will be selected by default.', 'woocommerce' ); ?>">[?]</a></th>
2013-10-01 12:13:14 +00:00
< th colspan = " 3 " >< span class = " description " >< ? php _e ( 'Drag and drop the above shipping methods to control their display order.' , 'woocommerce' ); ?> </span></th>
</ tr >
</ tfoot >
2013-07-26 14:36:28 +00:00
< tbody >
< ? php
2013-09-09 16:15:58 +00:00
foreach ( WC () -> shipping -> load_shipping_methods () as $key => $method ) {
2013-07-26 14:36:28 +00:00
echo ' < tr >
2013-09-09 16:15:58 +00:00
< td width = " 1% " class = " default " >
2013-11-20 19:11:59 +00:00
< input type = " radio " name = " default_shipping_method " value = " ' . esc_attr( $method->id ) . ' " ' . checked( $default_shipping_method, $method->id, false ) . ' />
< input type = " hidden " name = " method_order[] " value = " ' . esc_attr( $method->id ) . ' " />
2013-09-09 16:15:58 +00:00
</ td >
< td class = " name " >
' . $method->get_title() . '
</ td >
< td class = " id " >
' . $method->id . '
</ td >
< td class = " status " > ' ;
2013-07-26 14:36:28 +00:00
if ( $method -> enabled == 'yes' )
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled' , 'woocommerce' ) . '">' . __ ( 'Enabled' , 'woocommerce' ) . '</span>' ;
2013-09-09 16:15:58 +00:00
else
echo '-' ;
2013-07-26 14:36:28 +00:00
echo ' </ td >
2014-02-20 15:16:53 +00:00
< td class = " settings " > ' ;
if ( $method -> has_settings ) {
echo '<a class="button" href="' . admin_url ( 'admin.php?page=wc-settings&tab=shipping§ion=' . strtolower ( get_class ( $method ) ) ) . '">' . __ ( 'Settings' , 'woocommerce' ) . '</a>' ;
}
echo ' </ td >
2013-07-26 14:36:28 +00:00
</ tr > ' ;
}
?>
</ tbody >
</ table >
</ td >
</ tr >
< ? php
}
/**
* Save settings
*/
public function save () {
global $current_section ;
if ( ! $current_section ) {
$settings = $this -> 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 );
}
}
}
endif ;
2013-08-16 11:12:47 +00:00
return new WC_Settings_Shipping ();