| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Packetery\Module\Dashboard; |
| 6 |
|
| 7 |
use Packetery\Module\Framework\WcAdapter; |
| 8 |
use Packetery\Module\Shipping\ShippingProvider; |
| 9 |
use WC_Shipping_Zone; |
| 10 |
use WC_Shipping_Zone_Data_Store; |
| 11 |
|
| 12 |
class DashboardHelper { |
| 13 |
|
| 14 |
/** |
| 15 |
* @var WcAdapter |
| 16 |
*/ |
| 17 |
private $wcAdapter; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
WcAdapter $wcAdapter |
| 21 |
) { |
| 22 |
$this->wcAdapter = $wcAdapter; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Tells if there is Packeta shipping method configured and active. |
| 27 |
* |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public function isPacketaShippingMethodActive(): bool { |
| 31 |
/** @var WC_Shipping_Zone_Data_Store $shippingDataStore */ |
| 32 |
$shippingDataStore = $this->wcAdapter->dataStoreLoad( 'shipping-zone' ); |
| 33 |
|
| 34 |
$shippingZones = $shippingDataStore->get_zones(); |
| 35 |
|
| 36 |
foreach ( $shippingZones as $shippingZoneId ) { |
| 37 |
$shippingZone = new WC_Shipping_Zone( $shippingZoneId ); |
| 38 |
$shippingZoneMethods = $shippingZone->get_shipping_methods( true ); |
| 39 |
foreach ( $shippingZoneMethods as $method ) { |
| 40 |
if ( ShippingProvider::isPacketaMethod( $method->id ) ) { |
| 41 |
return true; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return false; |
| 47 |
} |
| 48 |
} |
| 49 |
|