Aufbau eine benutzerdefinierte Funktion, die sehr einfache SQL-Abfragen auf diese Weise nutzen:
function get_shipping_zone_from_method_rate_id($method_rate_id){
global $wpdb;
$data = explode(':', $method_rate_id);
$method_id = $data[0];
$instance_id = $data[1];
// The first SQL query
$zone_id = $wpdb->get_col("
SELECT wszm.zone_id
FROM {$wpdb->prefix}woocommerce_shipping_zone_methods as wszm
WHERE wszm.instance_id = '$instance_id'
AND wszm.method_id LIKE '$method_id'
");
$zone_id = reset($zone_id); // converting to string
// 1. Wrong Shipping method rate id
if(empty($zone_id))
{
return __("Error! doesn't exist…");
}
// 2. Default WC Zone name
elseif($zone_id == 0)
{
return __("All Other countries");
}
// 3. Created Zone name
else
{
// The 2nd SQL query
$zone_name = $wpdb->get_col("
SELECT wsz.zone_name
FROM {$wpdb->prefix}woocommerce_shipping_zones as wsz
WHERE wsz.zone_id = '$zone_id'
");
return reset($zone_name); // converting to string and returning the value
}
}
-Code geht in function.php Datei Ihres aktiven Kind Thema (oder Thema) oder auch in jeder Plugin-Datei.
Getestet und funktioniert.
Anwendungsbeispiel(Ausgang der Zonenname):
// Set HERE your shipping method rate id
$rate_id = 'flat_rate:3';
// Get the zone name
$zone_name = get_shipping_zone_from_method_rate_id($rate_id);
// Output zone name
echo $zone_name;
ausgezeichnet, danke! – Efbi