diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php index 97cda7f75..0f87a62c5 100644 --- a/modules.local/ppcp-button/src/Assets/SmartButton.php +++ b/modules.local/ppcp-button/src/Assets/SmartButton.php @@ -6,18 +6,22 @@ namespace Inpsyde\PayPalCommerce\Button\Assets; use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; +use Inpsyde\PayPalCommerce\Session\SessionHandler; class SmartButton { private $moduleUrl; + private $sessionHandler; private $isSandbox; public function __construct( string $moduleUrl, + SessionHandler $sessionHandler, bool $isSandbox ) { $this->moduleUrl = $moduleUrl; + $this->sessionHandler = $sessionHandler; $this->isSandbox = $isSandbox; } @@ -112,7 +116,7 @@ class SmartButton if (is_cart()) { $context = 'cart'; } - if (is_checkout()) { + if (is_checkout() && ! $this->sessionHandler->order()) { $context = 'checkout'; } return $context; diff --git a/modules.local/ppcp-button/src/ButtonModule.php b/modules.local/ppcp-button/src/ButtonModule.php index 9090ee670..68f95f376 100644 --- a/modules.local/ppcp-button/src/ButtonModule.php +++ b/modules.local/ppcp-button/src/ButtonModule.php @@ -29,20 +29,22 @@ class ButtonModule implements ModuleInterface */ public function run(ContainerInterface $container) { - $smartButton = $container->get('button.smart-button'); /** * @var SmartButton $smartButton */ add_action( 'wp', - function () use ($smartButton) { + function () use ($container) { if (is_admin()) { return; } + $smartButton = $container->get('button.smart-button'); $smartButton->renderWrapper(); } ); - add_action('wp_enqueue_scripts', function () use ($smartButton) { + add_action('wp_enqueue_scripts', function () use ($container) { + + $smartButton = $container->get('button.smart-button'); $smartButton->enqueue(); });