woocommerce.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Compatibility\Woocommerce; |
| 5 | |
| 6 | use JFB_Compatibility\Woocommerce\Methods\Wc_Product_Modification\Wc_Product_Modifier; |
| 7 | use JFB_Components\Compatibility\Base_Compat_Handle_Trait; |
| 8 | use JFB_Components\Compatibility\Base_Compat_Url_Trait; |
| 9 | use JFB_Components\Module\Base_Module_Handle_It; |
| 10 | use JFB_Components\Module\Base_Module_It; |
| 11 | use JFB_Components\Module\Base_Module_Url_It; |
| 12 | |
| 13 | // If this file is called directly, abort. |
| 14 | if ( ! defined( 'WPINC' ) ) { |
| 15 | die; |
| 16 | } |
| 17 | |
| 18 | class Woocommerce implements Base_Module_Url_It, Base_Module_It, Base_Module_Handle_It { |
| 19 | |
| 20 | use Base_Compat_Url_Trait; |
| 21 | use Base_Compat_Handle_Trait; |
| 22 | |
| 23 | public function rep_item_id() { |
| 24 | return 'woocommerce'; |
| 25 | } |
| 26 | |
| 27 | public function condition(): bool { |
| 28 | return function_exists( 'WC' ); |
| 29 | } |
| 30 | |
| 31 | public function init_hooks() { |
| 32 | add_filter( |
| 33 | 'jet-form-builder/action/insert-post/modifiers', |
| 34 | array( $this, 'add_modifiers' ) |
| 35 | ); |
| 36 | add_action( 'jet-form-builder/editor-assets/before', array( $this, 'enqueue_admin_assets' ) ); |
| 37 | } |
| 38 | |
| 39 | public function remove_hooks() { |
| 40 | remove_filter( |
| 41 | 'jet-form-builder/action/insert-post/modifiers', |
| 42 | array( $this, 'add_modifiers' ) |
| 43 | ); |
| 44 | remove_action( 'jet-form-builder/editor-assets/before', array( $this, 'enqueue_admin_assets' ) ); |
| 45 | } |
| 46 | |
| 47 | public function add_modifiers( array $modifiers ): array { |
| 48 | $modifiers[] = new Wc_Product_Modifier(); |
| 49 | |
| 50 | return $modifiers; |
| 51 | } |
| 52 | |
| 53 | public function enqueue_admin_assets() { |
| 54 | wp_enqueue_script( |
| 55 | $this->get_handle(), |
| 56 | $this->get_url( 'assets/build/js/editor.js' ), |
| 57 | array(), |
| 58 | jet_form_builder()->get_version(), |
| 59 | true |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 |