EtchService.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Etch; |
| 4 | |
| 5 | /** |
| 6 | * Controls the Etch Builder integration. |
| 7 | */ |
| 8 | class EtchService { |
| 9 | /** |
| 10 | * Bootstrap the Etch Builder integration. |
| 11 | * |
| 12 | * @return void |
| 13 | */ |
| 14 | public function bootstrap(): void { |
| 15 | add_filter( 'sc_cart_disabled', [ $this, 'disableCartForEtchBuilder' ] ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Determine if we should handle the cart via Etch Builder. |
| 20 | * |
| 21 | * @param bool $disabled Whether the cart is disabled. |
| 22 | * |
| 23 | * @return bool |
| 24 | */ |
| 25 | public function disableCartForEtchBuilder( bool $disabled ): bool { |
| 26 | if ( $this->isEtchBuilderActive() ) { |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | // Preserve the existing disabled state. |
| 31 | return (bool) $disabled; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Check if the Etch Builder is active. |
| 36 | * |
| 37 | * @return bool |
| 38 | */ |
| 39 | private function isEtchBuilderActive(): bool { |
| 40 | return function_exists( 'etch_run_plugin' ) && isset( $_GET['etch'] ) && 'magic' === $_GET['etch']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 41 | } |
| 42 | } |
| 43 |