Removing selection priority
This option was added so you could sort methods in a custom order, but choose a different default. Doing this per zone would add extra complexity, and this has also proven problematic when a method registers multiple rates. This commit removes usage of the setting. We should use the display order and choose the top method by default. It think this balances ease of use with control.
This commit is contained in:
parent
041906e692
commit
9818796d3e
|
@ -29,7 +29,6 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
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' ) );
|
||||
}
|
||||
|
||||
|
@ -151,10 +150,6 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
'type' => 'multi_select_countries'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'shipping_methods',
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'shipping_options' ),
|
||||
|
||||
) );
|
||||
|
@ -187,64 +182,6 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output shipping method settings.
|
||||
*/
|
||||
public function shipping_methods_setting() {
|
||||
$selection_priority = get_option( 'woocommerce_shipping_method_selection_priority', array() );
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc"><?php _e( 'Shipping Methods', 'woocommerce' ) ?></th>
|
||||
<td class="forminp">
|
||||
<table class="wc_shipping widefat wp-list-table" cellspacing="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="sort"> </th>
|
||||
<th class="name"><?php _e( 'Name', 'woocommerce' ); ?></th>
|
||||
<th class="id"><?php _e( 'ID', 'woocommerce' ); ?></th>
|
||||
<th class="status"><?php _e( 'Enabled', 'woocommerce' ); ?></th>
|
||||
<th class="priority"><?php _e( 'Selection Priority', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Available methods will be chosen by default in this order. If multiple methods have the same priority, they will be sorted by cost.', 'woocommerce' ) ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( WC()->shipping->load_shipping_methods() as $key => $method ) : ?>
|
||||
<tr>
|
||||
<td width="1%" class="sort">
|
||||
<input type="hidden" name="method_order[<?php echo esc_attr( $method->id ); ?>]" value="<?php echo esc_attr( $method->id ); ?>" />
|
||||
</td>
|
||||
<td class="name">
|
||||
<?php if ( $method->has_settings() ) : ?><a href="<?php echo esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=' . strtolower( get_class( $method ) ) ) ); ?>"><?php endif; ?>
|
||||
<?php echo esc_html( $method->get_title() ); ?>
|
||||
<?php if ( $method->has_settings() ) : ?></a><?php endif; ?>
|
||||
</td>
|
||||
<td class="id">
|
||||
<?php echo esc_attr( $method->id ); ?>
|
||||
</td>
|
||||
<td class="status">
|
||||
<?php if ( 'yes' === $method->enabled ) : ?>
|
||||
<span class="status-enabled tips" data-tip="<?php esc_attr_e( 'Yes', 'woocommerce' ); ?>"><?php _e( 'Yes', 'woocommerce' ); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="na">-</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td width="1%" class="priority">
|
||||
<input type="number" step="1" min="0" name="method_priority[<?php echo esc_attr( $method->id ); ?>]" value="<?php echo isset( $selection_priority[ $method->id ] ) ? absint( $selection_priority[ $method->id ] ) : 1; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th colspan="4"><span class="description"><?php _e( 'Drag and drop the above shipping methods to control their display order.', 'woocommerce' ); ?></span></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings.
|
||||
*/
|
||||
|
@ -255,7 +192,6 @@ class WC_Settings_Shipping extends WC_Settings_Page {
|
|||
|
||||
if ( ! $current_section ) {
|
||||
WC_Admin_Settings::save_fields( $this->get_settings() );
|
||||
$wc_shipping->process_admin_options();
|
||||
|
||||
} else {
|
||||
foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) {
|
||||
|
|
|
@ -193,46 +193,24 @@ class WC_Shipping {
|
|||
* @return string
|
||||
*/
|
||||
private function get_default_method( $available_methods, $current_chosen_method = false ) {
|
||||
$selection_priority = get_option( 'woocommerce_shipping_method_selection_priority', array() );
|
||||
|
||||
if ( ! empty( $available_methods ) ) {
|
||||
|
||||
// Is a method already chosen?
|
||||
if ( ! empty( $current_chosen_method ) && ! isset( $available_methods[ $current_chosen_method ] ) ) {
|
||||
foreach ( $available_methods as $method_key => $method ) {
|
||||
if ( strpos( $method->id, $current_chosen_method ) === 0 ) {
|
||||
return $method->id;
|
||||
if ( ! empty( $current_chosen_method ) ) {
|
||||
if ( isset( $available_methods[ $current_chosen_method ] ) ) {
|
||||
return $available_methods[ $current_chosen_method ]->id;
|
||||
} else {
|
||||
foreach ( $available_methods as $method_key => $method ) {
|
||||
if ( strpos( $method->id, $current_chosen_method ) === 0 ) {
|
||||
return $method->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Order by priorities and costs
|
||||
$prioritized_methods = array();
|
||||
|
||||
foreach ( $available_methods as $method_key => $method ) {
|
||||
// Some IDs contain : if they have multiple rates so use $method->method_id
|
||||
$priority = isset( $selection_priority[ $method->method_id ] ) ? absint( $selection_priority[ $method->method_id ] ): 1;
|
||||
|
||||
if ( empty( $prioritized_methods[ $priority ] ) ) {
|
||||
$prioritized_methods[ $priority ] = array();
|
||||
}
|
||||
|
||||
$prioritized_methods[ $priority ][ $method_key ] = $method->cost;
|
||||
}
|
||||
|
||||
ksort( $prioritized_methods );
|
||||
$prioritized_methods = current( $prioritized_methods );
|
||||
asort( $prioritized_methods );
|
||||
|
||||
return current( array_keys( $prioritized_methods ) );
|
||||
return current( $available_methods )->id;
|
||||
}
|
||||
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate shipping costs.
|
||||
*
|
||||
* Calculate shipping for (multiple) packages of cart items.
|
||||
*
|
||||
* @param array $packages multi-dimensional array of cart items to calc shipping for
|
||||
|
@ -368,7 +346,6 @@ class WC_Shipping {
|
|||
|
||||
/**
|
||||
* Get packages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_packages() {
|
||||
|
@ -387,30 +364,6 @@ class WC_Shipping {
|
|||
$this->packages = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process admin options.
|
||||
*
|
||||
* Saves options on the shipping setting page.
|
||||
*/
|
||||
public function process_admin_options() {
|
||||
$method_order = isset( $_POST['method_order'] ) ? $_POST['method_order'] : '';
|
||||
$method_priority = isset( $_POST['method_priority'] ) ? $_POST['method_priority'] : '';
|
||||
$order = array();
|
||||
$selection_priority = array();
|
||||
|
||||
if ( is_array( $method_order ) && sizeof( $method_order ) > 0 ) {
|
||||
$loop = 0;
|
||||
foreach ( $method_order as $method_id ) {
|
||||
$order[ $method_id ] = $loop;
|
||||
$selection_priority[ $method_id ] = absint( $method_priority[ $method_id ] );
|
||||
$loop ++;
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'woocommerce_shipping_method_selection_priority', $selection_priority );
|
||||
update_option( 'woocommerce_shipping_method_order', $order );
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.6.0 Was previously used to determine sort order of methods, but this is now controlled by zones and thus unused.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue