Add method instances in COD, grouped by method
This commit is contained in:
parent
3dc5f2a277
commit
d86a948f04
|
@ -58,10 +58,40 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
||||||
* Initialise Gateway Settings Form Fields.
|
* Initialise Gateway Settings Form Fields.
|
||||||
*/
|
*/
|
||||||
public function init_form_fields() {
|
public function init_form_fields() {
|
||||||
$shipping_methods = array();
|
|
||||||
|
$options = array();
|
||||||
|
$data_store = WC_Data_Store::load( 'shipping-zone' );
|
||||||
|
$raw_zones = $data_store->get_zones();
|
||||||
|
|
||||||
|
foreach ( $raw_zones as $raw_zone ) {
|
||||||
|
$zones[] = new WC_Shipping_Zone( $raw_zone );
|
||||||
|
}
|
||||||
|
|
||||||
|
$zones[] = new WC_Shipping_Zone(0);
|
||||||
|
|
||||||
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
|
foreach ( WC()->shipping()->load_shipping_methods() as $method ) {
|
||||||
$shipping_methods[ $method->id ] = $method->get_method_title();
|
|
||||||
|
$options[ $method->get_method_title() ] = array();
|
||||||
|
|
||||||
|
$options[ $method->get_method_title() ][ $method->id ] = sprintf( __( 'Any "%1$s" method', 'woocommerce' ), $method->get_method_title() );
|
||||||
|
|
||||||
|
foreach ( $zones as $zone ) {
|
||||||
|
|
||||||
|
$shipping_method_instances = $zone->get_shipping_methods();
|
||||||
|
|
||||||
|
foreach ( $shipping_method_instances as $shipping_method_instance_id => $shipping_method_instance ) {
|
||||||
|
|
||||||
|
if ( $shipping_method_instance->id !== $method->id ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$option_id = $shipping_method_instance->get_rate_id();
|
||||||
|
$option_instance_title = sprintf( __( '%1$s (#%2$s)', 'woocommerce' ), $shipping_method_instance->get_title(), $shipping_method_instance_id );
|
||||||
|
$option_title = sprintf( __( '%1$s – %2$s', 'woocommerce' ), $zone->get_id() ? $zone->get_zone_name() : __( 'Other locations', 'woocommerce' ), $option_instance_title );
|
||||||
|
|
||||||
|
$options[ $method->get_method_title() ][ $option_id ] = $option_title;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->form_fields = array(
|
$this->form_fields = array(
|
||||||
|
@ -100,7 +130,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
|
||||||
'css' => 'width: 400px;',
|
'css' => 'width: 400px;',
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'description' => __( 'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'woocommerce' ),
|
'description' => __( 'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'woocommerce' ),
|
||||||
'options' => $shipping_methods,
|
'options' => $options,
|
||||||
'desc_tip' => true,
|
'desc_tip' => true,
|
||||||
'custom_attributes' => array(
|
'custom_attributes' => array(
|
||||||
'data-placeholder' => __( 'Select shipping methods', 'woocommerce' ),
|
'data-placeholder' => __( 'Select shipping methods', 'woocommerce' ),
|
||||||
|
|
Loading…
Reference in New Issue