mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
fix context for checkout. do not assign checkout context when already in a paypal session
This commit is contained in:
parent
74129c5914
commit
4a5e805534
2 changed files with 10 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue