2013-07-26 14:36:28 +00:00
< ? php
/**
2015-11-03 13:53:50 +00:00
* WooCommerce Shipping Settings
2013-07-26 14:36:28 +00:00
*
2014-08-31 08:22:03 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
2013-07-26 14:36:28 +00:00
* @ version 2.1 . 0
*/
2014-09-20 19:55:47 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-07-26 14:36:28 +00:00
if ( ! class_exists ( 'WC_Settings_Shipping' ) ) :
/**
2015-11-03 13:31:20 +00:00
* WC_Settings_Shipping .
2013-07-26 14:36:28 +00:00
*/
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_settings_save_' . $this -> id , array ( $this , 'save' ) );
}
/**
2015-11-03 13:31:20 +00:00
* Get sections .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_sections () {
$sections = array (
2014-08-31 08:22:03 +00:00
'' => __ ( 'Shipping Options' , 'woocommerce' )
2013-07-26 14:36:28 +00:00
);
2015-01-23 13:05:35 +00:00
if ( ! defined ( 'WC_INSTALLING' ) ) {
// Load shipping methods so we can show any global options they may have
$shipping_methods = WC () -> shipping -> load_shipping_methods ();
2013-07-26 14:36:28 +00:00
2015-01-23 13:05:35 +00:00
foreach ( $shipping_methods as $method ) {
if ( ! $method -> has_settings () ) {
continue ;
}
$title = empty ( $method -> method_title ) ? ucfirst ( $method -> id ) : $method -> method_title ;
$sections [ strtolower ( get_class ( $method ) ) ] = esc_html ( $title );
}
2013-07-26 14:36:28 +00:00
}
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
}
/**
2015-11-03 13:31:20 +00:00
* Get settings array .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_settings () {
2014-08-31 08:22:03 +00:00
2014-09-12 11:20:06 +00:00
$settings = apply_filters ( 'woocommerce_shipping_settings' , array (
2013-07-26 14:36:28 +00:00
array ( 'title' => __ ( 'Shipping Options' , 'woocommerce' ), 'type' => 'title' , 'id' => 'shipping_options' ),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Shipping Calculations' , 'woocommerce' ),
'desc' => __ ( 'Enable shipping' , 'woocommerce' ),
'id' => 'woocommerce_calc_shipping' ,
2015-04-29 13:55:12 +00:00
'default' => 'no' ,
2014-08-31 08:22:03 +00:00
'type' => 'checkbox' ,
'checkboxgroup' => 'start'
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Enable the shipping calculator on the cart page' , 'woocommerce' ),
'id' => 'woocommerce_enable_shipping_calc' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => '' ,
2013-07-26 14:36:28 +00:00
'autoload' => false
),
array (
2014-08-31 08:22:03 +00:00
'desc' => __ ( 'Hide shipping costs until an address is entered' , 'woocommerce' ),
'id' => 'woocommerce_shipping_cost_requires_address' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
2013-07-26 14:36:28 +00:00
'autoload' => false
),
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' ,
2015-01-06 17:39:09 +00:00
'default' => 'billing' ,
2014-04-08 15:28:27 +00:00
'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' ),
2015-06-16 13:51:36 +00:00
'billing_only' => __ ( 'Only ship to the customer\'s billing address' , 'woocommerce' ),
2014-04-08 15:28:27 +00:00
),
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 (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Restrict shipping to Location(s)' , 'woocommerce' ),
'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' ) ),
'id' => 'woocommerce_ship_to_countries' ,
'default' => '' ,
'type' => 'select' ,
2015-01-12 16:29:01 +00:00
'class' => 'wc-enhanced-select' ,
2014-08-31 08:22:03 +00:00
'desc_tip' => false ,
'options' => array (
2013-08-02 15:54:28 +00:00
'' => __ ( 'Ship to all countries you sell to' , 'woocommerce' ),
'all' => __ ( 'Ship to all countries' , 'woocommerce' ),
'specific' => __ ( 'Ship to specific countries only' , 'woocommerce' )
)
),
array (
2014-08-31 08:22:03 +00:00
'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' => 'sectionend' , 'id' => 'shipping_options' ),
2014-09-12 11:20:06 +00:00
) );
return apply_filters ( 'woocommerce_get_settings_' . $this -> id , $settings );
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Output the settings .
2013-07-26 14:36:28 +00:00
*/
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 ) {
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
foreach ( $shipping_methods as $method ) {
2014-08-31 08:22:03 +00:00
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 );
}
}
/**
2015-11-03 13:31:20 +00:00
* Save settings .
2013-07-26 14:36:28 +00:00
*/
public function save () {
2015-01-19 13:19:41 +00:00
global $current_section ;
2013-07-26 14:36:28 +00:00
2015-05-29 16:38:25 +00:00
$wc_shipping = WC_Shipping :: instance ();
2013-07-26 14:36:28 +00:00
2015-05-29 16:38:25 +00:00
if ( ! $current_section ) {
WC_Admin_Settings :: save_fields ( $this -> get_settings () );
2013-07-26 14:36:28 +00:00
2015-05-29 16:38:25 +00:00
} else {
foreach ( $wc_shipping -> get_shipping_methods () as $method_id => $method ) {
if ( $current_section === sanitize_title ( get_class ( $method ) ) ) {
do_action ( 'woocommerce_update_options_' . $this -> id . '_' . $method -> id );
}
}
2013-07-26 14:36:28 +00:00
}
2014-11-11 16:22:26 +00:00
2015-01-19 13:19:41 +00:00
// Increments the transient version to invalidate cache
WC_Cache_Helper :: get_transient_version ( 'shipping' , true );
2013-07-26 14:36:28 +00:00
}
}
endif ;
2013-08-16 11:12:47 +00:00
return new WC_Settings_Shipping ();