woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Ensure WC session when Single Product Checkout is not set #845

Closed chickenn00dle closed 3 years ago

chickenn00dle commented 3 years ago

Issue: #842


Description

This adds the ensure_session callback to an order-pay hook when Single Product Checkout is disabled.

Previously, in cases where a guest checks out via the order-pay page (via a payment link sent from the merchant), and Single Product Checkout is not enabled, no session is set and so the method responsible for processing once we return from PayPal returned early, and guests ended up at an empty cart page (See https://github.com/woocommerce/woocommerce-gateway-paypal-express-checkout/issues/842#issuecomment-759990913 for details).

This PR fixes that by adding the ensure_session cb to a hook specific to the order-pay page. We avoid adding this when Single Product Checkout is enabled as this cb is already added to a more generic hook in this case.

Steps to test:

  1. Disable Checkout on Single Product in WooCommerce > Settings > Payments > PayPal Checkout
  2. Create a manual order for a guest customer
  3. Using the payment link, pay for this order in a private window using PPEC
  4. On trunk, you will be redirected to an empty cart page. On this branch, the payment will be successful.

Documentation

Changelog entry

Fix - Ensures a session cookie is set when guests pay for manual orders.

Closes #842

danharper83 commented 3 years ago

I think it should be.

add_action( 'woocommerce_pay_order_after_submit', array( $this, 'maybe_ensure_session' ) );

The other part of the file is also using ensure_session when it should be maybe_ensure_session()