getMethods() ) { return __( 'No shipping method is set up yet. Add shipping zones and methods under WooCommerce → Settings → Shipping, then choose here who may use each.', 'tier-pricing-table' ); } return __( 'Who may use each shipping method of each zone, for example free shipping for retail customers only. Leave a method empty to keep it available to everyone.', 'tier-pricing-table' ); } public function getSlug(): string { return 'shipping-methods'; } public function getSettings(): array { $settings = array(); foreach ( $this->getMethods() as $instanceId => $title ) { $settings[] = array( 'title' => $title, 'id' => CartRulesSettings::optionId( 'shipping_' . $instanceId ), 'type' => TPTCheckboxListOption::FIELD_TYPE, 'display' => 'checkboxes', 'options' => Roles::getOptions(), 'default' => '', ); } return $settings; } /** * @return array instance id => "Zone: Method", enabled methods only */ protected function getMethods(): array { if ( ! class_exists( WC_Shipping_Zones::class ) ) { return array(); } $zones = array(); foreach ( WC_Shipping_Zones::get_zones() as $zone ) { $zones[] = new WC_Shipping_Zone( (int) $zone['id'] ); } $zones[] = new WC_Shipping_Zone( 0 ); // locations not covered by the other zones $methods = array(); foreach ( $zones as $zone ) { foreach ( $zone->get_shipping_methods( true ) as $method ) { $methods[ (int) $method->get_instance_id() ] = wp_strip_all_tags( $zone->get_zone_name() . ': ' . $method->get_title() ); } } return $methods; } }