| @@ -138,9 +138,8 @@ | ||
| 138 | 138 | admin_url( 'admin-ajax.php' ) |
| 139 | 139 | ) |
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - $is_wc_source = get_post_meta( $id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); | |
| 143 | 142 | $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true ); |
| 144 | 143 | $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true ); |
| 145 | 144 | $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true ); |
| 146 | 145 | $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true ); |
| @@ -171,13 +170,11 @@ | ||
| 171 | 170 | id="vz-import-json-url" |
| 172 | 171 | name="url" |
| 173 | 172 | value="<?php echo esc_url( $url ); ?>" |
| 174 | 173 | placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>" |
| 175 | - class="visualizer-input json-form-element" | |
| 176 | - <?php echo $is_wc_source ? 'readonly' : ''; ?> | |
| 177 | - > | |
| 174 | + class="visualizer-input json-form-element"> | |
| 178 | 175 | <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button> |
| 179 | - | |
| 176 | + | |
| 180 | 177 | <div class="visualizer-json-subform"> |
| 181 | 178 | <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3> |
| 182 | 179 | <div class="json-wizard-headers"> |
| 183 | 180 | <div class="json-wizard-header"> |
| @@ -672,14 +669,9 @@ | ||
| 672 | 669 | ) |
| 673 | 670 | ); |
| 674 | 671 | |
| 675 | 672 | // this will allow us to open the correct source tab by default. |
| 676 | - $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); | |
| 677 | - // Import from woocommerce report. | |
| 678 | - $is_woocommerce_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) ); | |
| 679 | - if ( ! empty( $is_woocommerce_source ) ) { | |
| 680 | - $source_of_chart .= '_wc'; | |
| 681 | - } | |
| 673 | + $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); | |
| 682 | 674 | // both import from wp and import from db have the same source so we need to differentiate. |
| 683 | 675 | $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ); |
| 684 | 676 | // if filter config is present, then its import from wp. |
| 685 | 677 | if ( ! empty( $filter_config ) ) { |
| @@ -927,106 +919,8 @@ | ||
| 927 | 919 | </div> |
| 928 | 920 | </div> |
| 929 | 921 | </li> |
| 930 | 922 | |
| 931 | - <!-- import from WooCommerce --> | |
| 932 | - <?php | |
| 933 | - if ( class_exists( 'WooCommerce', false ) ) : | |
| 934 | - $wc_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, true ) ); | |
| 935 | - $wc_source_list = apply_filters( | |
| 936 | - 'visualizer_woocommerce_report_endpoints', | |
| 937 | - array( | |
| 938 | - array( | |
| 939 | - 'name' => esc_html__( 'Sales', 'visualizer' ), | |
| 940 | - 'endpoint' => esc_attr( 'sales' ), | |
| 941 | - ), | |
| 942 | - array( | |
| 943 | - 'name' => esc_html__( 'Top Sellers', 'visualizer' ), | |
| 944 | - 'endpoint' => esc_attr( 'top_sellers' ), | |
| 945 | - ), | |
| 946 | - array( | |
| 947 | - 'name' => esc_html__( 'Coupons Totals', 'visualizer' ), | |
| 948 | - 'endpoint' => esc_attr( 'coupons/totals' ), | |
| 949 | - ), | |
| 950 | - array( | |
| 951 | - 'name' => esc_html__( 'Customers Totals', 'visualizer' ), | |
| 952 | - 'endpoint' => esc_attr( 'customers/totals' ), | |
| 953 | - ), | |
| 954 | - array( | |
| 955 | - 'name' => esc_html__( 'Orders Totals', 'visualizer' ), | |
| 956 | - 'endpoint' => esc_attr( 'orders/totals' ), | |
| 957 | - ), | |
| 958 | - array( | |
| 959 | - 'name' => esc_html__( 'Products Totals', 'visualizer' ), | |
| 960 | - 'endpoint' => esc_attr( 'products/totals' ), | |
| 961 | - ), | |
| 962 | - array( | |
| 963 | - 'name' => esc_html__( 'Reviews Totals', 'visualizer' ), | |
| 964 | - 'endpoint' => esc_attr( 'reviews/totals' ), | |
| 965 | - ), | |
| 966 | - ) | |
| 967 | - ); | |
| 968 | - ?> | |
| 969 | - <li class="viz-group visualizer_woocommerce_source<?php echo 'visualizer_source_json_wc' === $source_of_chart ? ' open' : ''; ?> <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wc-report' ); ?> "> | |
| 970 | - <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WooCommerce Reports', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2> | |
| 971 | - <div class="viz-group-content edit-data-content"> | |
| 972 | - <div> | |
| 973 | - <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a WooCommerce report API. For more info check <a href="https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#reports" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p> | |
| 974 | - <form id="vz-import-woo-report" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data"> | |
| 975 | - <div class="remote-file-section"> | |
| 976 | - <?php | |
| 977 | - $bttn_label = 'visualizer_source_json_wc' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' ); | |
| 978 | - ?> | |
| 979 | - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p> | |
| 980 | - <select name="time" id="vz-woo-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>"> | |
| 981 | - <?php | |
| 982 | - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true ); | |
| 983 | - $schedules = apply_filters( | |
| 984 | - 'visualizer_chart_schedules', array( | |
| 985 | - '-1' => __( 'One-time', 'visualizer' ), | |
| 986 | - ), | |
| 987 | - 'json', | |
| 988 | - $chart_id | |
| 989 | - ); | |
| 990 | - foreach ( $schedules as $num => $name ) { | |
| 991 | - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | |
| 992 | - $extra = $num == $hours ? 'selected' : ''; | |
| 993 | - ?> | |
| 994 | - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option> | |
| 995 | - <?php | |
| 996 | - } | |
| 997 | - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 ); | |
| 998 | - ?> | |
| 999 | - </select> | |
| 1000 | - <p class="viz-group-description"><?php _e( 'Select report endpoint', 'visualizer' ); ?></p> | |
| 1001 | - <select name="vz_woo_source" id="vz-woo-source" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>"> | |
| 1002 | - <option value=""></option> | |
| 1003 | - <?php | |
| 1004 | - if ( ! empty( $wc_source_list ) ) { | |
| 1005 | - foreach ( $wc_source_list as $api ) { | |
| 1006 | - if ( isset( $api['name'] ) && $api['endpoint'] ) { | |
| 1007 | - echo sprintf( '<option value="%2$s" %3$s>%1$s</option>', $api['name'], $api['endpoint'], selected( $wc_source, $api['endpoint'], false ) ); // phpcs:ignore | |
| 1008 | - } | |
| 1009 | - } | |
| 1010 | - } | |
| 1011 | - ?> | |
| 1012 | - </select> | |
| 1013 | - </div> | |
| 1014 | - | |
| 1015 | - <input type="button" id="woo-chart-button" class="button button-secondary show-chart-toggle" | |
| 1016 | - value="<?php echo $bttn_label; ?>" data-current="chart" | |
| 1017 | - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" | |
| 1018 | - data-t-chart="<?php echo $bttn_label; ?>" | |
| 1019 | - <?php empty( $wc_source ) ? 'disabled' : ''; ?> | |
| 1020 | - > | |
| 1021 | - <input type="button" id="woo-chart-save-button" class="button button-primary " | |
| 1022 | - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>" <?php empty( $wc_source ) ? 'disabled' : ''; ?>> | |
| 1023 | - </form> | |
| 1024 | - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wc-report' ); ?> | |
| 1025 | - </div> | |
| 1026 | - </div> | |
| 1027 | - </li> | |
| 1028 | - <?php endif; ?> | |
| 1029 | 923 | <?php |
| 1030 | 924 | $save_query = esc_url( |
| 1031 | 925 | add_query_arg( |
| 1032 | 926 | array( |