| @@ -138,8 +138,9 @@ | ||
| 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 ); | |
| 142 | 143 | $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true ); |
| 143 | 144 | $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true ); |
| 144 | 145 | $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true ); |
| 145 | 146 | $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true ); |
| @@ -170,11 +171,13 @@ | ||
| 170 | 171 | id="vz-import-json-url" |
| 171 | 172 | name="url" |
| 172 | 173 | value="<?php echo esc_url( $url ); ?>" |
| 173 | 174 | placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>" |
| 174 | - class="visualizer-input json-form-element"> | |
| 175 | + class="visualizer-input json-form-element" | |
| 176 | + <?php echo $is_wc_source ? 'readonly' : ''; ?> | |
| 177 | + > | |
| 175 | 178 | <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button> |
| 176 | - | |
| 179 | + | |
| 177 | 180 | <div class="visualizer-json-subform"> |
| 178 | 181 | <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3> |
| 179 | 182 | <div class="json-wizard-headers"> |
| 180 | 183 | <div class="json-wizard-header"> |
| @@ -669,9 +672,14 @@ | ||
| 669 | 672 | ) |
| 670 | 673 | ); |
| 671 | 674 | |
| 672 | 675 | // this will allow us to open the correct source tab by default. |
| 673 | - $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); | |
| 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 | + } | |
| 674 | 682 | // both import from wp and import from db have the same source so we need to differentiate. |
| 675 | 683 | $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ); |
| 676 | 684 | // if filter config is present, then its import from wp. |
| 677 | 685 | if ( ! empty( $filter_config ) ) { |
| @@ -919,8 +927,106 @@ | ||
| 919 | 927 | </div> |
| 920 | 928 | </div> |
| 921 | 929 | </li> |
| 922 | 930 | |
| 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; ?> | |
| 923 | 1029 | <?php |
| 924 | 1030 | $save_query = esc_url( |
| 925 | 1031 | add_query_arg( |
| 926 | 1032 | array( |