Changeset 3349699
- Timestamp:
- 08/25/2025 12:20:47 PM (7 months ago)
- Location:
- wiser-review/trunk
- Files:
-
- 5 edited
-
assets/css/wiserrw-admin.css (modified) (1 diff)
-
assets/js/wiserw-js.js (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
views/wiserw-plugin-settings.php (modified) (2 diffs)
-
wiser-review.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wiser-review/trunk/assets/css/wiserrw-admin.css
r3296997 r3349699 142 142 gap: 15px; 143 143 } 144 .wiserrw_type.reset_sych { 145 display:flex; 146 gap: 10px; 147 } -
wiser-review/trunk/assets/js/wiserw-js.js
r3296997 r3349699 192 192 }); 193 193 }) 194 jQuery('.wiserrw_synch_products').click(function (e) { 195 e.preventDefault(); 196 jQuery(this).attr('disabled', 'disabled'); 197 wiserrw_synch_products(1); 198 }); 199 jQuery('.wiserrw_reset_products').click(function (e) { 200 e.preventDefault(); 201 jQuery(this).attr('disabled', 'disabled'); 202 wiserrw_reset_products(); 203 }); 204 194 205 }) 206 207 function wiserrw_reset_products() { 208 var request = { 209 action: 'wiserrw_reset_products', 210 security: jQuery('.wiserrw_exporter').val(), 211 }; 212 jQuery.post(ajaxurl, request).done(function (data_raw) { 213 var data = JSON.parse(data_raw); 214 jQuery('.wiserrw_synch_products').removeAttr('disabled'); 215 jQuery('.wiserrw_sych_response').html(''); 216 jQuery('.wiserrw_reset_response').html("<div class='notice'>" + data.message + "</div>"); 217 }); 218 } 219 function wiserrw_synch_products(page, total_pages) { 220 var end = false; 221 var per_page = 50; 222 var request = { 223 action: 'wiserrw_sync_products', 224 security: jQuery('.wiserrw_exporter').val(), 225 page: page, 226 per_page: per_page 227 }; 228 229 230 if (total_pages === 0) { 231 end = true; 232 } 233 234 if (total_pages) { 235 request['total_pages'] = total_pages; 236 if (page > total_pages) { 237 end = true; 238 } 239 } 240 241 if (!end) { 242 jQuery.post(ajaxurl, request).done(function (data_raw) { 243 var data = JSON.parse(data_raw); 244 jQuery('.wiserrw_sych_response').html("<div class='notice'>" + data.message + "</div>"); 245 wiserrw_synch_products(data.next_page, data.total_pages); 246 }); 247 248 } 249 } -
wiser-review/trunk/readme.txt
r3345259 r3349699 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.4 8 Stable tag: 1. 88 Stable tag: 1.9 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 115 115 = 1.7 = 116 116 Fix- we separate the shortcode and toggle display, star rating position, data-lgin support 117 118 = 1.8 = 119 Grouping sync & Google shopping review feed enabled at WiserReview account -
wiser-review/trunk/views/wiserw-plugin-settings.php
r3344241 r3349699 16 16 $wiserrw_data = isset( $_POST['wiserrw_data'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wiserrw_data'] ) ) : array(); 17 17 update_option( 'wiserrw_api_settings', $wiserrw_data ); 18 } 18 } 19 19 } 20 20 $wiserrw_api_settings = get_option( 'wiserrw_api_settings' ); … … 243 243 244 244 </div> 245 </td> 246 </tr> 247 </tbody> 248 </table> 249 </form> 250 251 </div> 252 253 <div class="post-type-shop_order wiserrw_main_page_container"> 254 <?php 255 $wiserrw_api_settings = get_option( 'wiserrw_api_settings' ); 256 $api_key = $wiserrw_api_settings['wiserrw_api_key']; 257 $api_data = wiserrw_validate_api( $api_key ); 258 $wsid = $api_data->data->wsid; 259 ?> 260 <form action="#" method="post" name="wiserrw_products_form" id="wiserrw_products_form"> 261 <input type="hidden" class="wiserrw_exporter" value="<?php echo wp_create_nonce( 'wiserrw_export_products' ); ?>"> 262 <table class="form-table wc_gateways widefat"> 263 <thead> 264 <tr> 265 <th class="name">Sync products for grouping review</th> 266 </tr> 267 </thead> 268 <tbody> 269 <tr> 270 <td> 271 <div class="wiserrw_type reset_sych"> 272 <button class="button button-primary wiserrw_synch_products">Sync Products</button> 273 <button class="button button-primary wiserrw_reset_products">Reset status</button> 274 </div> 275 276 </td> 277 <td> 278 279 </td> 280 </tr> 281 <tr> 282 <td colspan="2"> 283 284 <div class="wiserrw_sych_response"> 285 286 </div> 287 <div class="wiserrw_reset_response"> 288 289 </div> 290 291 </td> 292 <td> 293 245 294 </td> 246 295 </tr> -
wiser-review/trunk/wiser-review.php
r3345259 r3349699 4 4 * Plugin URI: https://wiserreview.com 5 5 * Description: Wiser Review module helps you collect and display product reviews, star ratings, and nudges. It also automates review requests via email to boost custom engagement and conversions. 6 * Version: 1. 86 * Version: 1.9 7 7 * Author: Wiser Notify 8 8 * Requires Plugins: woocommerce … … 22 22 define( 'WISERRW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 23 23 define( 'WISERRW_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 24 define( 'WISERRW_PLUGIN_VERSION', 1.0 ); 24 define( 'WISERRW_PLUGIN_VERSION', 1.8 ); 25 define( 'WISERRW_API_HOST', 'https://api.wiserreview.com/api/woocommerce/' ); 25 26 26 27 if ( ! function_exists( 'wiserrw_scripts' ) ) { … … 29 30 */ 30 31 function wiserrw_scripts() { 31 wp_enqueue_style( 'wiserrw-admin-styles', plugins_url( '/assets/css/wiserrw-admin.css', WISERRW_PLUGIN_FILE ), array(), WISERRW_PLUGIN_VERSION);32 wp_register_script( 'wiserrw-admin-script', plugins_url( '/assets/js/wiserw-js.js', WISERRW_PLUGIN_FILE ), array(), WISERRW_PLUGIN_VERSION);32 wp_enqueue_style( 'wiserrw-admin-styles', plugins_url( '/assets/css/wiserrw-admin.css', WISERRW_PLUGIN_FILE ), array(), time() ); 33 wp_register_script( 'wiserrw-admin-script', plugins_url( '/assets/js/wiserw-js.js', WISERRW_PLUGIN_FILE ), array(), time() ); 33 34 wp_localize_script( 34 35 'wiserrw-admin-script', … … 723 724 } 724 725 add_action( 'wp_ajax_wiserrw_fetch_order_count', 'wiserrw_fetch_order_count' ); 726 727 function wiserrw_count_products_with_reviews() { 728 global $wpdb; 729 730 return $wpdb->get_var( " 731 SELECT count(ID) 732 FROM {$wpdb->posts} 733 WHERE post_type = 'product' 734 AND post_status = 'publish'" ); 735 } 736 737 function wiserrw_get_products( $page, $per_page ) { 738 global $wpdb; 739 $offset = ( $page - 1 ) * $per_page; 740 741 return $wpdb->get_results( $wpdb->prepare( " 742 SELECT ID, 743 post_title as title, 744 post_name as slug, 745 comment_count 746 FROM {$wpdb->posts} 747 WHERE post_type = 'product' 748 AND post_status = 'publish' 749 LIMIT %d, %d 750 ", $offset, $per_page ), ARRAY_A ); 751 } 752 function wiserrw_sync_products() { 753 $wiserrw_api_settings = get_option( 'wiserrw_api_settings' ); 754 $full_product_synced = get_option( 'wiserrw_all_products_synced' ); 755 $api_host = constant( 'WISERRW_API_HOST' ); 756 $per_page = $_REQUEST['per_page'] ?:50; 757 $api_key = $wiserrw_api_settings['wiserrw_api_key']; 758 $api_data = wiserrw_validate_api( $api_key ); 759 $wsid = $api_data->data->wsid; 760 $arrsku = array(); 761 if ( isset( $_REQUEST['total_pages'] ) ) { 762 $total_pages = (int) sanitize_text_field( $_REQUEST['total_pages'] ); // Input var okay. 763 } else { 764 $count = wiserrw_count_products_with_reviews(); 765 $total_pages = $count / $per_page; 766 $total_pages = (int) $total_pages; 767 if ( $count % $per_page ) { 768 $total_pages ++; 769 } 770 } 771 772 $page = (int) sanitize_text_field( $_REQUEST['page'] ); 773 $finished = 0; 774 775 if ( $page <= $total_pages ) { 776 $message = "Synced $page / $total_pages pages"; 777 778 $products = wiserrw_get_products( $page, $per_page ); 779 $products_json = array(); 780 781 foreach ( $products as $prod ) { 782 $products_arr = array(); 783 $id = $prod['ID']; 784 $registered = get_post_meta( $id, '_wiserrw_product_registered' ); 785 if ( ! empty( $registered ) ) { 786 continue; 787 } 788 $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'shop_single' ); 789 $small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'thumbnail' ); 790 $medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'shop_catalog' ); 791 792 $terms = get_the_terms( $id, 'product_tag' ); 793 $term_array = array(); 794 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { 795 foreach ( $terms as $term ) { 796 $term_array[] = $term->name; 797 } 798 } 799 800 801 $pr = wc_get_product( $id ); 802 $variants = array(); 803 804 if ( $pr->is_type( 'variable' ) ) { 805 $prod_variation = new WC_Product_Variable( $id ); 806 foreach ( $prod_variation->get_available_variations() as $variation ) { 807 $variant = array(); 808 809 $gtin = get_post_meta( $variation['variation_id'], 'hwp_var_gtin', 1 ) ?: get_post_meta( $id, 'hwp_product_gtin', 1 ) ?: $pr->get_attribute('GTIN') ?: $pr->get_attribute('EAN') ?: $pr->get_attribute('ISBN') ?: get_post_meta( $id, '_global_unique_id', 1 ); 810 811 if ( ! empty( $gtin ) ) { 812 $variant['barcode'] = $gtin; 813 } 814 815 if ( ! empty( $variation['sku'] ) ) { 816 $variant['sku'] = $variation['sku']; 817 $arrsku[] = $variation['sku']; 818 } 819 820 if ( ! empty( $variant) ) { 821 $variants[] = $variant; 822 } 823 } 824 } else { 825 $pr_sku = $pr->get_sku(); 826 $variant = array(); 827 $gtin = get_post_meta( $id, 'hwp_product_gtin', 1 ) ?: $pr->get_attribute('GTIN') ?: $pr->get_attribute('EAN') ?: $pr->get_attribute('ISBN') ?: get_post_meta( $id, '_global_unique_id', 1 ); 828 829 if( $pr_sku != '' ){ 830 $arrsku[] = $pr_sku; 831 } 832 if ( ! empty( $gtin ) ) { 833 $variant['barcode'] = $gtin; 834 } 835 836 if ( ! empty( $pr_sku ) ) { 837 $variant['sku'] = $pr_sku; 838 } 839 840 if ( ! empty($variant) ) { 841 $variants[] = $variant; 842 } 843 } 844 845 $vendor = get_bloginfo( 'name' ); 846 if ( empty( $vendor ) ) { 847 $vendor = $domain; 848 } 849 850 $cats = get_the_terms( $id, 'product_cat' ); 851 $cat = $vendor; 852 if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { 853 $cat = $cats[0]->name; 854 } 855 856 $title = $prod['title']; 857 if ( empty($title) ) { 858 $title = $cat; 859 } 860 861 $product_json = array( 862 'pid' => $prod['ID'], 863 'arrsku' => $arrsku, 864 'shp' => get_site_url(), 865 'wsid' => $wsid, 866 'pn' => $title, 867 'piu' => $image_url[0], 868 'pu' => get_permalink($prod['ID']), 869 'barcode' => $gtin, 870 ); 871 872 $products_json[] = $product_json; 873 update_post_meta( $id, '_wiserrw_product_registered', '1' ); 874 } 875 876 $data = array( 877 'method' => 'POST', 878 'blocking' => true, 879 'headers' => array( 'Content-Type' => 'application/json' ), 880 'body' => json_encode( array( 881 'products' => $products_json 882 ) ) 883 ); 884 $url = $api_host . 'productWebhook?wsid='.$wsid.'&key='.$api_key; 885 $response = wp_safe_remote_post( $url, $data ); 886 887 } else { 888 $message = 'Finished'; 889 $finished = 1; 890 } 891 892 if ( $page == $total_pages ) { 893 update_option( 'wiserrw_all_products_synced', 1 ); 894 } 895 896 $page ++; 897 $result = array( 898 'next_page' => $page, 899 'total_pages' => $total_pages, 900 'message' => $message, 901 'url' => $url, 902 'response' => $response, 903 'products' => $products_json, 904 'finished' => $finished, 905 ); 906 907 echo wp_json_encode( $result ); 908 wp_die(); 909 } 910 add_action( 'wp_ajax_wiserrw_sync_products', 'wiserrw_sync_products' ); 911 add_action( 'wp_ajax_wiserrw_sync_products', 'wiserrw_sync_products' ); 912 913 function wiserrw_reset_products() { 914 global $wpdb; 915 $sql = "DELETE FROM wp_postmeta WHERE meta_key = '_wiserrw_product_registered'"; 916 $message = 'All Products Sync Status Cleard'; 917 $deleted = $wpdb->query($sql); 918 $deleted_count = intval($wpdb->rows_affected); 919 $result = array( 920 'message' => $message, 921 ); 922 923 echo wp_json_encode( $result ); 924 wp_die(); 925 } 926 add_action( 'wp_ajax_wiserrw_reset_products', 'wiserrw_reset_products' ); 927 add_action( 'wp_ajax_wiserrw_reset_products', 'wiserrw_reset_products' ); 928 929 function wiserrw_product_delete_hook( $p_id ) { 930 if ( get_post_type( $p_id ) === 'product' ) { 931 $wiserrw_api_settings = get_option( 'wiserrw_api_settings' ); 932 $api_host = constant( 'WISERRW_API_HOST' ); 933 $api_key = $wiserrw_api_settings['wiserrw_api_key']; 934 $api_data = wiserrw_validate_api( $api_key ); 935 $wsid = $api_data->data->wsid; 936 $url = $api_host . 'productWebhook/'.$p_id.'?wsid='.$wsid.'&key='.$api_key; 937 $data = array( 938 'method' => 'DELETE' 939 ); 940 $response = wp_remote_request( $url, $data ); 941 } 942 943 } 944 add_action( 'deleted_post', 'wiserrw_product_delete_hook' ); 945 add_action( 'trashed_post', 'wiserrw_product_delete_hook' ); 946 947 function wiserrw_product_update_hook( $product ) { 948 $p_id = $product->get_id(); 949 delete_post_meta( $id, '_wiserrw_product_registered' ); 950 if ( wp_is_post_autosave( $p_id ) || wp_is_post_revision( $p_id ) ) { 951 return; 952 } 953 $wiserrw_api_settings = get_option( 'wiserrw_api_settings' ); 954 $api_host = constant( 'WISERRW_API_HOST' ); 955 $api_key = $wiserrw_api_settings['wiserrw_api_key']; 956 $api_data = wiserrw_validate_api( $api_key ); 957 $wsid = $api_data->data->wsid; 958 $url = $api_host . 'productWebhook?wsid='.$wsid.'&key='.$api_key; 959 $registered = get_post_meta( $p_id, '_wiserrw_product_registered', true ); 960 $arrsku = array(); 961 $pr = wc_get_product( $p_id ); 962 963 964 $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $p_id ), 'shop_single' ); 965 $small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $p_id ), 'thumbnail' ); 966 $medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $p_id ), 'shop_catalog' ); 967 968 if ( $pr->is_type( 'variable' ) ) { 969 $prod_variation = new WC_Product_Variable( $id ); 970 foreach ( $prod_variation->get_available_variations() as $variation ) { 971 $variant = array(); 972 973 $gtin = get_post_meta( $variation['variation_id'], 'hwp_var_gtin', 1 ) ?: get_post_meta( $id, 'hwp_product_gtin', 1 ) ?: $pr->get_attribute('GTIN') ?: $pr->get_attribute('EAN') ?: $pr->get_attribute('ISBN') ?: get_post_meta( $p_id, '_global_unique_id', 1 ); 974 975 if ( ! empty( $gtin ) ) { 976 $variant['barcode'] = $gtin; 977 } 978 979 if ( ! empty( $variation['sku'] ) ) { 980 $variant['sku'] = $variation['sku']; 981 $arrsku[] = $variation['sku']; 982 } 983 984 if ( ! empty( $variant) ) { 985 $variants[] = $variant; 986 } 987 } 988 } else { 989 $pr_sku = $pr->get_sku(); 990 $variant = array(); 991 $gtin = get_post_meta( $p_id, 'hwp_product_gtin', 1 ) ?: $pr->get_attribute('GTIN') ?: $pr->get_attribute('EAN') ?: $pr->get_attribute('ISBN') ?: get_post_meta( $p_id, '_global_unique_id', 1 ); 992 993 if( $pr_sku != '' ){ 994 $arrsku[] = $pr_sku; 995 } 996 997 if ( ! empty( $gtin ) ) { 998 $variant['barcode'] = $gtin; 999 } 1000 1001 if ( ! empty( $pr_sku ) ) { 1002 $variant['sku'] = $pr_sku; 1003 } 1004 1005 if ( ! empty($variant) ) { 1006 $variants[] = $variant; 1007 } 1008 } 1009 1010 1011 $cats = get_the_terms( $p_id, 'product_cat' ); 1012 $cat = $vendor; 1013 if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) { 1014 $cat = $cats[0]->name; 1015 } 1016 1017 $title = $pr->get_name(); 1018 if ( empty($title) ) { 1019 $title = $cat; 1020 } 1021 1022 $product_json = array( 1023 'pid' => (string)$p_id, 1024 'arrsku' => $arrsku, 1025 'shp' => get_site_url(), 1026 'wsid' => $wsid, 1027 'pn' => $title, 1028 'piu' => $image_url[0], 1029 'pu' => get_permalink($p_id), 1030 'barcode' => $gtin, 1031 ); 1032 $products_json[] = $product_json; 1033 $data = array( 1034 'method' => 'POST', 1035 'blocking' => true, 1036 'headers' => array( 'Content-Type' => 'application/json' ), 1037 'body' => json_encode( array( 1038 'products' => $products_json 1039 ) ) 1040 ); 1041 $url = $api_host . 'productWebhook?wsid='.$wsid.'&key='.$api_key; 1042 $response = wp_safe_remote_post( $url, $data ); 1043 } 1044 add_action( 'woocommerce_after_product_object_save', 'wiserrw_product_update_hook', 99, 1 ); 1045
Note: See TracChangeset
for help on using the changeset viewer.