Skip to content

Commit

Permalink
Not load assets if not enabled at mollie P-192
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaymo committed Jul 27, 2023
1 parent eb8dcaa commit e09e312
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Assets/AssetsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,30 @@ public function registerBlockScripts(string $pluginUrl, string $pluginPath): voi
/**
* Enqueue Frontend only scripts
*
* @param $container Container
* @return void
*/
public function enqueueFrontendScripts()
public function enqueueFrontendScripts($container)
{
if (is_admin() || !mollieWooCommerceIsCheckoutContext()) {
return;
}
wp_enqueue_style('mollie-gateway-icons');
$isBillieEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_billie_settings', 'enabled');
if ($isBillieEnabled) {
$allMethodsEnabledAtMollie = $container->get('gateway.paymentMethodsEnabledAtMollie');
$isBillieEnabledAtMollie = in_array('billie', $allMethodsEnabledAtMollie, true);
if ($isBillieEnabled && $isBillieEnabledAtMollie) {
wp_enqueue_script('mollie-billie-classic-handles');
}
$isIn3Enabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_in3_settings', 'enabled');
if ($isIn3Enabled) {
$isIn3EnabledAtMollie = in_array('in3', $allMethodsEnabledAtMollie, true);
if ($isIn3Enabled && $isIn3EnabledAtMollie) {
wp_enqueue_script('mollie-in3-classic-handles');
}

$applePayGatewayEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_applepay_settings', 'enabled');

if (!$applePayGatewayEnabled) {
$isAppleEnabledAtMollie = in_array('applepay', $allMethodsEnabledAtMollie, true);
if (!$applePayGatewayEnabled || !$isAppleEnabledAtMollie) {
return;
}
wp_enqueue_style('unabledButton');
Expand Down Expand Up @@ -640,7 +644,10 @@ function () use ($container, $hasBlocksEnabled, $settingsHelper, $pluginUrl, $pl
self::registerFrontendScripts($pluginUrl, $pluginPath);

// Enqueue Scripts
add_action('wp_enqueue_scripts', [$this, 'enqueueFrontendScripts']);
add_action('wp_enqueue_scripts', function () use ($container) {
$this->enqueueFrontendScripts($container);

});
add_action('wp_enqueue_scripts', function () use ($settingsHelper) {
$this->enqueueComponentsAssets($settingsHelper);
});
Expand Down

0 comments on commit e09e312

Please sign in to comment.