direct-checkout.php
3 years ago
lang-migration.php
3 years ago
migration.php
4 years ago
temp-migration.php
4 years ago
direct-checkout.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Compatibility\Migrations; |
| 4 | |
| 5 | defined( 'ABSPATH' ) || exit; |
| 6 | |
| 7 | use ShopEngine\Core\Builders\Action; |
| 8 | use ShopEngine\Core\Template_Cpt; |
| 9 | |
| 10 | /** |
| 11 | * This migrate is run to push the direct checkout button item inside the archive product widget |
| 12 | * @since 3.0.1 |
| 13 | */ |
| 14 | class Direct_Checkout |
| 15 | { |
| 16 | public function __construct() |
| 17 | { |
| 18 | $is_run_direct_checkout_migration = get_option( 'shopengine_direct_checkout_migration' ); |
| 19 | if ( !$is_run_direct_checkout_migration ) { |
| 20 | $args = [ |
| 21 | 'post_type' => Template_Cpt::TYPE, |
| 22 | 'post_status' => ['publish', 'draft', 'trash'], |
| 23 | 'posts_per_page' => -1, |
| 24 | 'meta_query' => [ |
| 25 | [ |
| 26 | 'key' => Action::get_meta_key_for_type(), |
| 27 | 'value' => ['shop', 'archive'], |
| 28 | 'compare' => 'IN' |
| 29 | ] |
| 30 | ] |
| 31 | ]; |
| 32 | |
| 33 | $wp_query = new \WP_Query( $args ); |
| 34 | $templates = $wp_query->posts; |
| 35 | |
| 36 | $direct_checkout = (object) [ |
| 37 | 'list_title' => 'Direct Checkout (PRO)', |
| 38 | 'list_key' => 'direct-checkout', |
| 39 | '_id' => '9c46638' |
| 40 | ]; |
| 41 | |
| 42 | foreach ( $templates as $template ) { |
| 43 | $elementor_json = get_post_meta( $template->ID, '_elementor_data', true ); |
| 44 | if ( !empty( $elementor_json ) ) { |
| 45 | $elementor_demo_array = json_decode( $elementor_json ); |
| 46 | foreach ( $elementor_demo_array as $section_key => $section ) { |
| 47 | foreach ( $section->elements as $column_key => $column ) { |
| 48 | foreach ( $column->elements as $widget_key => $widget ) { |
| 49 | if ( isset( $widget->widgetType ) && 'shopengine-archive-products' === $widget->widgetType ) { |
| 50 | |
| 51 | |
| 52 | // Return if the settings not found |
| 53 | if(!isset($widget->settings->shopengine_custom_ordering_list)) return; |
| 54 | |
| 55 | /** |
| 56 | * Convert std object to array |
| 57 | */ |
| 58 | $button_items = json_decode( json_encode( $widget->settings->shopengine_custom_ordering_list ), true ); |
| 59 | |
| 60 | /** |
| 61 | * Check if direct checkout doesn't already exist |
| 62 | */ |
| 63 | if ( !is_int( array_search( 'direct-checkout', array_column( $button_items, 'list_key' ) ) ) ) { |
| 64 | array_push( $elementor_demo_array[$section_key]->elements[$column_key]->elements[$widget_key]->settings->shopengine_custom_ordering_list, $direct_checkout ); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | update_post_meta( $template->ID, '_elementor_data', json_encode( $elementor_demo_array ) ); |
| 73 | } |
| 74 | } |
| 75 | update_option( 'shopengine_direct_checkout_migration', true ); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |