HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: //var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Features/Shipping/Shipping.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Features\Shipping;

use Exception;
use GoDaddy\WordPress\MWC\Common\Components\Contracts\ComponentContract;
use GoDaddy\WordPress\MWC\Common\Components\Traits\HasComponentsTrait;
use GoDaddy\WordPress\MWC\Common\Features\AbstractFeature;
use GoDaddy\WordPress\MWC\Common\Helpers\ArrayHelper;
use GoDaddy\WordPress\MWC\Common\Repositories\WooCommerceRepository;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\API\API;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Interceptors\AddPhoneNumberToStoreAddressInterceptor;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Interceptors\CopyBillingPhoneAsShippingPhoneInterceptor;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Interceptors\RedirectToShippingDashboardInterceptor;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Interceptors\RequireBillingPhoneAtCheckoutInterceptor;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Interceptors\ShippingLabelsSettingsSectionInterceptor;
use GoDaddy\WordPress\MWC\Core\Features\Shipping\Services\ShippingAccountService;
use GoDaddy\WordPress\MWC\Shipping\Models\Account\Statuses\ConnectedStatus;

class Shipping extends AbstractFeature
{
    use HasComponentsTrait;

    /** @var class-string<ComponentContract>[] alphabetically ordered list of components to load */
    protected $componentClasses = [
        Lifecycle::class,
        API::class,
        ShippingLabelsSettingsSectionInterceptor::class,
        RedirectToShippingDashboardInterceptor::class,
        AddPhoneNumberToStoreAddressInterceptor::class,
        RequireBillingPhoneAtCheckoutInterceptor::class,
        CopyBillingPhoneAsShippingPhoneInterceptor::class,
    ];

    /**
     * Gets the feature name, matching the key used in configuration.
     *
     * @return string
     */
    public static function getName() : string
    {
        return 'shipping';
    }

    /**
     * Determines whether the class should load.
     *
     * @return bool
     */
    public static function shouldLoad() : bool
    {
        return static::shouldLoadFeature() && static::isBaseCountryEligible();
    }

    /**
     * Determines whether the store's base country is eligible to use the feature.
     *
     * @return bool
     */
    public static function isBaseCountryEligible() : bool
    {
        return ArrayHelper::contains(['us', 'gb', 'ca', 'au'], strtolower(WooCommerceRepository::getBaseCountry()));
    }

    /**
     * Determines whether the Shipping feature ever loaded on this site.
     *
     * @return bool
     */
    public static function loadedBefore() : bool
    {
        return get_option(Lifecycle::SHIPPING_PREVIOUSLY_LOADED_OPTION_NAME) === 'yes';
    }

    /**
     * Determines whether the Shipping account for this site is already connected.
     *
     * @return bool
     */
    public static function isAccountConnected() : bool
    {
        return ShippingAccountService::getNewInstance()->getAccount()->getStatus() instanceof ConnectedStatus;
    }

    /**
     * Initializes the feature.
     *
     * @throws Exception
     */
    public function load()
    {
        $this->loadComponents();
    }
}