API
4 months ago
Admin
1 day ago
Emails
1 year ago
Framework
1 day ago
Gateway
2 months ago
Handlers
1 day ago
Internal
1 month ago
Sync
4 weeks ago
Utilities
1 month ago
AJAX.php
2 years ago
API.php
2 months ago
Admin.php
2 months ago
Coupons.php
4 months ago
Functions.php
3 years ago
Gateway.php
3 months ago
Lifecycle.php
2 years ago
Plugin.php
1 month ago
Settings.php
4 months ago
WC_Order_Square.php
2 years ago
WC_Payments_Compatibility.php
1 year ago
WC_Payments_Compatibility.php
78 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class for WooPayments compatibility. |
| 4 | */ |
| 5 | |
| 6 | namespace WooCommerce\Square; |
| 7 | |
| 8 | use WooCommerce\Square\Handlers\Product; |
| 9 | |
| 10 | /** |
| 11 | * WC_Payments_Compatibility Class |
| 12 | * |
| 13 | * @version 4.7.3 |
| 14 | */ |
| 15 | class WC_Payments_Compatibility { |
| 16 | |
| 17 | /** |
| 18 | * Initialize the WooPayments Compatibility class. |
| 19 | * |
| 20 | * @since 4.7.3 |
| 21 | */ |
| 22 | public function init() { |
| 23 | add_filter( 'wcpay_payment_request_is_product_supported', array( $this, 'wcpay_is_product_supported' ), 10, 2 ); |
| 24 | add_filter( 'wcpay_woopay_button_is_product_supported', array( $this, 'wcpay_is_product_supported' ), 10, 2 ); |
| 25 | add_filter( 'wcpay_payment_request_is_cart_supported', array( $this, 'wcpay_is_product_supported' ), 10, 2 ); |
| 26 | add_filter( 'wcpay_platform_checkout_button_are_cart_items_supported', array( $this, 'platform_checkout_button_are_cart_items_supported' ) ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Filter whether to display express pay buttons on product pages. |
| 31 | * |
| 32 | * Runs on the `wcpay_payment_request_is_product_supported` and |
| 33 | * `wcpay_woopay_button_is_product_supported` filters. |
| 34 | * |
| 35 | * @since 4.7.3 |
| 36 | * |
| 37 | * @param bool $is_supported Whether express pay buttons are supported on product pages. |
| 38 | * @param \WC_Product $product The product object. |
| 39 | * |
| 40 | * @return bool Modified support status. |
| 41 | */ |
| 42 | public function wcpay_is_product_supported( $is_supported, $product ) { |
| 43 | if ( Product::is_gift_card( $product ) ) { |
| 44 | // Express pay buttons are not supported on product pages. |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | return $is_supported; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Filter whether to display WooPay express pay buttons on cart pages. |
| 53 | * |
| 54 | * Hide the express WooPay button on cart pages containing Square Gift Cards. |
| 55 | * |
| 56 | * Runs on the `wcpay_platform_checkout_button_are_cart_items_supported` filter. |
| 57 | * |
| 58 | * @param bool $is_supported Whether express WooPay buttons are supported on cart pages. |
| 59 | * |
| 60 | * @return bool Modified support status. |
| 61 | */ |
| 62 | public function platform_checkout_button_are_cart_items_supported( $is_supported ) { |
| 63 | if ( ! WC()->cart ) { |
| 64 | return $is_supported; |
| 65 | } |
| 66 | |
| 67 | foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { |
| 68 | $product = $cart_item['data']; |
| 69 | |
| 70 | if ( Product::is_gift_card( $product ) ) { |
| 71 | return false; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return $is_supported; |
| 76 | } |
| 77 | } |
| 78 |