Merge pull request #14784 from woocommerce/fix/14769

get_settings for shipping and checkout need to support sections for the API
This commit is contained in:
Claudio Sanches 2017-04-28 12:49:53 -03:00 committed by GitHub
commit c48ddfbab8
2 changed files with 214 additions and 206 deletions

View File

@ -61,191 +61,195 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
* *
* @return array * @return array
*/ */
public function get_settings() { public function get_settings( $current_section = '' ) {
$settings = apply_filters( 'woocommerce_payment_gateways_settings', array( $settings = array();
array( if ( '' === $current_section ) {
'title' => __( 'Checkout process', 'woocommerce' ), $settings = apply_filters( 'woocommerce_payment_gateways_settings', array(
'type' => 'title',
'id' => 'checkout_process_options',
),
array( array(
'title' => __( 'Coupons', 'woocommerce' ), 'title' => __( 'Checkout process', 'woocommerce' ),
'desc' => __( 'Enable the use of coupons', 'woocommerce' ), 'type' => 'title',
'id' => 'woocommerce_enable_coupons', 'id' => 'checkout_process_options',
'default' => 'yes', ),
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
),
array( array(
'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ), 'title' => __( 'Coupons', 'woocommerce' ),
'id' => 'woocommerce_calc_discounts_sequentially', 'desc' => __( 'Enable the use of coupons', 'woocommerce' ),
'default' => 'no', 'id' => 'woocommerce_enable_coupons',
'type' => 'checkbox', 'default' => 'yes',
'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ), 'type' => 'checkbox',
'checkboxgroup' => 'end', 'checkboxgroup' => 'start',
'autoload' => false, 'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
), ),
array( array(
'title' => __( 'Checkout process', 'woocommerce' ), 'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ),
'desc' => __( 'Enable guest checkout', 'woocommerce' ), 'id' => 'woocommerce_calc_discounts_sequentially',
'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'woocommerce' ), 'default' => 'no',
'id' => 'woocommerce_enable_guest_checkout', 'type' => 'checkbox',
'default' => 'yes', 'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ),
'type' => 'checkbox', 'checkboxgroup' => 'end',
'checkboxgroup' => 'start', 'autoload' => false,
'autoload' => false, ),
),
array( array(
'desc' => __( 'Force secure checkout', 'woocommerce' ), 'title' => __( 'Checkout process', 'woocommerce' ),
'id' => 'woocommerce_force_ssl_checkout', 'desc' => __( 'Enable guest checkout', 'woocommerce' ),
'default' => 'no', 'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'woocommerce' ),
'type' => 'checkbox', 'id' => 'woocommerce_enable_guest_checkout',
'checkboxgroup' => '', 'default' => 'yes',
'show_if_checked' => 'option', 'type' => 'checkbox',
'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ), 'checkboxgroup' => 'start',
), 'autoload' => false,
),
'unforce_ssl_checkout' => array( array(
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ), 'desc' => __( 'Force secure checkout', 'woocommerce' ),
'id' => 'woocommerce_unforce_ssl_checkout', 'id' => 'woocommerce_force_ssl_checkout',
'default' => 'no', 'default' => 'no',
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => 'end', 'checkboxgroup' => '',
'show_if_checked' => 'yes', 'show_if_checked' => 'option',
), 'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ),
),
array( 'unforce_ssl_checkout' => array(
'type' => 'sectionend', 'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
'id' => 'checkout_process_options', 'id' => 'woocommerce_unforce_ssl_checkout',
), 'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),
array( array(
'title' => __( 'Checkout pages', 'woocommerce' ), 'type' => 'sectionend',
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ), 'id' => 'checkout_process_options',
'type' => 'title', ),
'id' => 'checkout_page_options',
),
array( array(
'title' => __( 'Cart page', 'woocommerce' ), 'title' => __( 'Checkout pages', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ), 'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ),
'id' => 'woocommerce_cart_page_id', 'type' => 'title',
'type' => 'single_select_page', 'id' => 'checkout_page_options',
'default' => '', ),
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array( array(
'title' => __( 'Checkout page', 'woocommerce' ), 'title' => __( 'Cart page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ), 'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ),
'id' => 'woocommerce_checkout_page_id', 'id' => 'woocommerce_cart_page_id',
'type' => 'single_select_page', 'type' => 'single_select_page',
'default' => '', 'default' => '',
'class' => 'wc-enhanced-select-nostd', 'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;', 'css' => 'min-width:300px;',
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Terms and conditions', 'woocommerce' ), 'title' => __( 'Checkout page', 'woocommerce' ),
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ), 'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ),
'id' => 'woocommerce_terms_page_id', 'id' => 'woocommerce_checkout_page_id',
'default' => '', 'type' => 'single_select_page',
'class' => 'wc-enhanced-select-nostd', 'default' => '',
'css' => 'min-width:300px;', 'class' => 'wc-enhanced-select-nostd',
'type' => 'single_select_page', 'css' => 'min-width:300px;',
'desc_tip' => true, 'desc_tip' => true,
'autoload' => false, ),
),
array( array(
'type' => 'sectionend', 'title' => __( 'Terms and conditions', 'woocommerce' ),
'id' => 'checkout_page_options', 'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
), 'id' => 'woocommerce_terms_page_id',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'type' => 'single_select_page',
'desc_tip' => true,
'autoload' => false,
),
array( 'title' => __( 'Checkout endpoints', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ), 'id' => 'account_endpoint_options' ), array(
'type' => 'sectionend',
'id' => 'checkout_page_options',
),
array( array( 'title' => __( 'Checkout endpoints', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ), 'id' => 'account_endpoint_options' ),
'title' => __( 'Pay', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Pay" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_pay_endpoint',
'type' => 'text',
'default' => 'order-pay',
'desc_tip' => true,
),
array( array(
'title' => __( 'Order received', 'woocommerce' ), 'title' => __( 'Pay', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Order received" page.', 'woocommerce' ), 'desc' => __( 'Endpoint for the "Checkout &rarr; Pay" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_order_received_endpoint', 'id' => 'woocommerce_checkout_pay_endpoint',
'type' => 'text', 'type' => 'text',
'default' => 'order-received', 'default' => 'order-pay',
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Add payment method', 'woocommerce' ), 'title' => __( 'Order received', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Add payment method" page.', 'woocommerce' ), 'desc' => __( 'Endpoint for the "Checkout &rarr; Order received" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_add_payment_method_endpoint', 'id' => 'woocommerce_checkout_order_received_endpoint',
'type' => 'text', 'type' => 'text',
'default' => 'add-payment-method', 'default' => 'order-received',
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Delete payment method', 'woocommerce' ), 'title' => __( 'Add payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ), 'desc' => __( 'Endpoint for the "Checkout &rarr; Add payment method" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_delete_payment_method_endpoint', 'id' => 'woocommerce_myaccount_add_payment_method_endpoint',
'type' => 'text', 'type' => 'text',
'default' => 'delete-payment-method', 'default' => 'add-payment-method',
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'title' => __( 'Set default payment method', 'woocommerce' ), 'title' => __( 'Delete payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ), 'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint', 'id' => 'woocommerce_myaccount_delete_payment_method_endpoint',
'type' => 'text', 'type' => 'text',
'default' => 'set-default-payment-method', 'default' => 'delete-payment-method',
'desc_tip' => true, 'desc_tip' => true,
), ),
array( array(
'type' => 'sectionend', 'title' => __( 'Set default payment method', 'woocommerce' ),
'id' => 'checkout_endpoint_options', 'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ),
), 'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint',
'type' => 'text',
'default' => 'set-default-payment-method',
'desc_tip' => true,
),
array( array(
'title' => __( 'Payment gateways', 'woocommerce' ), 'type' => 'sectionend',
'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce' ), 'id' => 'checkout_endpoint_options',
'type' => 'title', ),
'id' => 'payment_gateways_options',
),
array( array(
'type' => 'payment_gateways', 'title' => __( 'Payment gateways', 'woocommerce' ),
), 'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce' ),
'type' => 'title',
'id' => 'payment_gateways_options',
),
array( array(
'type' => 'sectionend', 'type' => 'payment_gateways',
'id' => 'payment_gateways_options', ),
),
) ); array(
'type' => 'sectionend',
'id' => 'payment_gateways_options',
),
if ( wc_site_is_https() ) { ) );
unset( $settings['unforce_ssl_checkout'] );
if ( wc_site_is_https() ) {
unset( $settings['unforce_ssl_checkout'] );
}
} }
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
} }
/** /**

View File

@ -71,61 +71,65 @@ class WC_Settings_Shipping extends WC_Settings_Page {
* *
* @return array * @return array
*/ */
public function get_settings() { public function get_settings( $current_section = '' ) {
$settings = apply_filters( 'woocommerce_shipping_settings', array( $settings = array();
array( 'title' => __( 'Shipping options', 'woocommerce' ), 'type' => 'title', 'id' => 'shipping_options' ), if ( '' === $current_section ) {
$settings = apply_filters( 'woocommerce_shipping_settings', array(
array( array( 'title' => __( 'Shipping options', 'woocommerce' ), 'type' => 'title', 'id' => 'shipping_options' ),
'title' => __( 'Calculations', 'woocommerce' ),
'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
'id' => 'woocommerce_enable_shipping_calc',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array( array(
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ), 'title' => __( 'Calculations', 'woocommerce' ),
'id' => 'woocommerce_shipping_cost_requires_address', 'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
'default' => 'no', 'id' => 'woocommerce_enable_shipping_calc',
'type' => 'checkbox', 'default' => 'yes',
'checkboxgroup' => 'end', 'type' => 'checkbox',
'autoload' => false, 'checkboxgroup' => 'start',
), 'autoload' => false,
array(
'title' => __( 'Shipping destination', 'woocommerce' ),
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_destination',
'default' => 'billing',
'type' => 'radio',
'options' => array(
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
), ),
'autoload' => false,
'desc_tip' => true,
'show_if_checked' => 'option',
),
array( array(
'title' => __( 'Debug mode', 'woocommerce' ), 'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
'desc' => __( 'Enable debug mode', 'woocommerce' ), 'id' => 'woocommerce_shipping_cost_requires_address',
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ), 'default' => 'no',
'id' => 'woocommerce_shipping_debug_mode', 'type' => 'checkbox',
'default' => 'no', 'checkboxgroup' => 'end',
'type' => 'checkbox', 'autoload' => false,
'autoload' => false, ),
),
array( 'type' => 'sectionend', 'id' => 'shipping_options' ), array(
'title' => __( 'Shipping destination', 'woocommerce' ),
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_destination',
'default' => 'billing',
'type' => 'radio',
'options' => array(
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
),
'autoload' => false,
'desc_tip' => true,
'show_if_checked' => 'option',
),
) ); array(
'title' => __( 'Debug mode', 'woocommerce' ),
'desc' => __( 'Enable debug mode', 'woocommerce' ),
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
'id' => 'woocommerce_shipping_debug_mode',
'default' => 'no',
'type' => 'checkbox',
'autoload' => false,
),
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); array( 'type' => 'sectionend', 'id' => 'shipping_options' ),
) );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
} }
/** /**