woocommerce.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Compatibility\Woocommerce; |
| 5 | |
| 6 | use Jet_Form_Builder\Compatibility\Woocommerce\Methods\Wc_Product_Modification\Wc_Product_Modifier; |
| 7 | |
| 8 | class Woocommerce { |
| 9 | |
| 10 | public static function register() { |
| 11 | if ( ! function_exists( 'WC' ) ) { |
| 12 | return; |
| 13 | } |
| 14 | new static(); |
| 15 | } |
| 16 | |
| 17 | private function __construct() { |
| 18 | add_filter( |
| 19 | 'jet-form-builder/action/insert-post/modifiers', |
| 20 | array( $this, 'add_modifiers' ) |
| 21 | ); |
| 22 | |
| 23 | add_filter( |
| 24 | 'jet-form-builder/editor/config', |
| 25 | array( $this, 'add_property_to_editor' ) |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | public function add_modifiers( array $modifiers ): array { |
| 30 | $modifiers[] = new Wc_Product_Modifier(); |
| 31 | |
| 32 | return $modifiers; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @param array $config |
| 37 | * |
| 38 | * @return array |
| 39 | * @since 3.0.4 |
| 40 | * |
| 41 | * We pass the value to js config to make sure that WooCommerce |
| 42 | * is installed in the Insert Post action script |
| 43 | */ |
| 44 | public function add_property_to_editor( array $config ): array { |
| 45 | $config['wooExist'] = true; |
| 46 | |
| 47 | return $config; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | } |
| 52 |