Skip to content

Commit

Permalink
Fix: Settings Links for Custom Shipping Zone in Plugins Page Not Showed
Browse files Browse the repository at this point in the history
Fixes: #21
  • Loading branch information
sofyansitorus committed Nov 7, 2021
1 parent 66485fa commit 3ff1811
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions includes/classes/class-woongkir.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,32 @@ public function load_textdomain() {
* @return array List of modified plugin action links.
*/
public function plugin_action_links( $links ) {
$zone_id = 0;

if ( ! class_exists( 'WC_Shipping_Zones' ) ) {
return $links;
}

$woongkir_links = array(
'<a href="' . esc_url(
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'shipping',
'zone_id' => $zone_id,
'woongkir_settings' => true,
),
admin_url( 'admin.php' )
)
) . '">' . __( 'Settings', 'woongkir' ) . '</a>',
);

$shipping_zones = WC_Shipping_Zones::get_zones();
$link_default_zone = '<a href="' . esc_url(
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'shipping',
'zone_id' => 0,
'woongkir_settings' => true,
),
admin_url( 'admin.php' )
)
) . '">' . __( 'Settings', 'woongkir' ) . '</a>';

$woongkir_links = array();

foreach ( WC_Shipping_Zones::get_zone_by()->get_shipping_methods() as $zone_shipping_method ) {
if ( $zone_shipping_method instanceof Woongkir_Shipping_Method ) {
$woongkir_links[] = $link_default_zone;
break;
}
}

foreach ( $shipping_zones as $zone ) {
foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
if ( empty( $zone['shipping_methods'] ) || empty( $zone['zone_id'] ) ) {
continue;
}
Expand All @@ -180,12 +183,22 @@ public function plugin_action_links( $links ) {
admin_url( 'admin.php' )
);

$woongkir_links[] = '<a href="' . esc_url(
$woongkir_links[ $zone['zone_id'] ] = '<a href="' . esc_url(
$link
// translators: %s is Shipping zone name.
) . '">' . sprintf( __( 'Settings: %s', 'woongkir' ), $zone['zone_name'] ) . '</a>';

break;
}
}

if ( ! empty( $woongkir_links[ $zone['zone_id'] ] ) ) {
break;
}
}

if ( ! $woongkir_links ) {
$woongkir_links[] = $link_default_zone;
}

return array_merge( $woongkir_links, $links );
Expand Down

0 comments on commit 3ff1811

Please sign in to comment.