WC_GZD_Trusted_Shops_Admin

The WooCommerce Germanized WC GZD Trusted Shops Admin class.

Defined (1)

The class is defined in the following location(s).

/includes/trusted-shops/class-wc-gzd-trusted-shops-admin.php  
  1. class WC_GZD_Trusted_Shops_Admin { 
  2.  
  3. protected static $_instance = null; 
  4.  
  5. public $base = null; 
  6.  
  7. public $script_prefix = ''; 
  8.  
  9. public static function instance( $base ) { 
  10. if ( is_null( self::$_instance ) ) 
  11. self::$_instance = new self( $base ); 
  12. return self::$_instance; 
  13.  
  14. private function __construct( $base ) { 
  15.  
  16. $this->base = $base; 
  17. $this->script_prefix = str_replace( '_', '-', $this->base->option_prefix ); 
  18.  
  19. // Register Section 
  20. add_filter( 'woocommerce_gzd_settings_sections', array( $this, 'register_section' ), 1 ); 
  21. add_filter( 'woocommerce_gzd_get_settings_trusted_shops', array( $this, 'get_settings' ) ); 
  22. add_filter( 'woocommerce_gzd_get_sidebar_trusted_shops', array( $this, 'get_sidebar' ) ); 
  23. add_action( 'woocommerce_gzd_before_save_section_trusted_shops', array( $this, 'before_save' ), 0, 1 ); 
  24. add_action( 'woocommerce_gzd_after_save_section_trusted_shops', array( $this, 'after_save' ), 0, 1 ); 
  25.  
  26. // Default settings 
  27. add_filter( 'woocommerce_gzd_installation_default_settings', array( $this, 'set_installation_settings' ), 10, 1 ); 
  28.  
  29. // After Install 
  30. add_action( 'woocommerce_gzd_installed', array( $this, 'create_attribute' ) ); 
  31.  
  32. // Review Collector 
  33. add_action( 'wc_germanized_settings_section_after_trusted_shops', array( $this, 'review_collector_export' ), 0 ); 
  34. add_action( 'admin_init', array( $this, 'review_collector_export_csv' ) ); 
  35.  
  36. add_action( 'woocommerce_gzd_load_trusted_shops_script', array( $this, 'load_scripts' ) ); 
  37.  
  38. public function create_attribute() { 
  39.  
  40. $attributes = array(  
  41. 'gtin' => _x( 'GTIN', 'trusted-shops', 'woocommerce-germanized' ),  
  42. 'brand' => _x( 'Brand', 'trusted-shops', 'woocommerce-germanized' ),  
  43. 'mpn' => _x( 'MPN', 'trusted-shops', 'woocommerce-germanized' ),  
  44. ); 
  45.  
  46. // Create the taxonomy 
  47. global $wpdb; 
  48. delete_transient( 'wc_attribute_taxonomies' ); 
  49.  
  50. foreach ( $attributes as $attribute_name => $title ) { 
  51. if ( ! in_array( 'pa_' . $attribute_name, wc_get_attribute_taxonomy_names() ) ) { 
  52. $attribute = array( 
  53. 'attribute_label' => $title,  
  54. 'attribute_name' => $attribute_name,  
  55. 'attribute_type' => 'text',  
  56. 'attribute_orderby' => 'menu_order',  
  57. 'attribute_public' => 0 
  58. ); 
  59.  
  60. $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); 
  61. delete_transient( 'wc_attribute_taxonomies' ); 
  62.  
  63. public function set_installation_settings( $settings ) { 
  64. return array_merge( $settings, $this->get_settings() ); 
  65.  
  66. public function load_scripts() { 
  67.  
  68. $screen = get_current_screen(); 
  69. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  70. $assets_path = $this->base->plugin->plugin_url() . '/assets/'; 
  71. $admin_script_path = $assets_path . 'js/admin/'; 
  72.  
  73. wp_register_style( 'woocommerce-' . $this->script_prefix . 'trusted-shops-admin', $assets_path . 'css/woocommerce-' . $this->script_prefix . 'trusted-shops-admin' . $suffix . '.css', false, $this->base->plugin->version ); 
  74. wp_enqueue_style( 'woocommerce-' . $this->script_prefix . 'trusted-shops-admin' ); 
  75.  
  76. wp_register_script( 'wc-' . $this->script_prefix . 'admin-trusted-shops', $admin_script_path . 'trusted-shops' . $suffix . '.js', array( 'jquery', 'woocommerce_settings' ), $this->base->plugin->version, true ); 
  77. wp_localize_script( 'wc-' . $this->script_prefix . 'admin-trusted-shops', 'trusted_shops_params', array( 
  78. 'option_prefix' => $this->base->option_prefix,  
  79. 'script_prefix' => $this->script_prefix,  
  80. ) ); 
  81.  
  82. wp_enqueue_script( 'wc-' . $this->script_prefix . 'admin-trusted-shops' ); 
  83.  
  84.  
  85. public function register_section( $sections ) { 
  86. $sections[ 'trusted_shops' ] = _x( 'Trusted Shops Options', 'trusted-shops', 'woocommerce-germanized' ); 
  87. return $sections; 
  88.  
  89. /** 
  90. * Get Trusted Shops related Settings for Admin Interface 
  91. * @return array 
  92. */ 
  93. public function get_settings() { 
  94.  
  95. $payment_options = array( '' => __( 'None', 'woocommerce-germanized' ) ) + $this->base->gateways; 
  96. $attributes = wc_get_attribute_taxonomies(); 
  97. $linked_attributes = array(); 
  98.  
  99. // Set attributes 
  100. foreach ( $attributes as $attribute ) { 
  101. $linked_attributes[ $attribute->attribute_name ] = $attribute->attribute_label; 
  102.  
  103. $options = array( 
  104.  
  105. array( 'title' => _x( 'Trusted Shops Integration', 'trusted-shops', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'trusted_shops_options' ),  
  106.  
  107. array( 
  108. 'title' => _x( 'Trusted Shops ID', 'trusted-shops', 'woocommerce-germanized' ),  
  109. 'desc' => _x( 'The Trusted Shops ID is a unique identifier for your shop. You can find your Trusted Shops ID in your confirmation email after signing up.', 'trusted-shops', 'woocommerce-germanized' ),  
  110. 'desc_tip' => true,  
  111. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_id',  
  112. 'type' => 'text',  
  113. 'css' => 'min-width:300px;',  
  114. ),  
  115.  
  116. array( 
  117. 'title' => _x( 'Mode', 'trusted-shops', 'woocommerce-germanized' ),  
  118. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_integration_mode',  
  119. 'type' => 'select',  
  120. 'class' => 'chosen_select',  
  121. 'options' => array(  
  122. 'standard' => _x( 'Standard Mode', 'trusted-shops', 'woocommerce-germanized' ),  
  123. 'expert' => _x( 'Expert Mode', 'trusted-shops', 'woocommerce-germanized' ),  
  124. ),  
  125. 'default' => 'standard' 
  126. ),  
  127.  
  128. array( 'type' => 'sectionend', 'id' => 'trusted_shops_options' ),  
  129.  
  130. array( 'title' => _x( 'Configure your Trustbadge', 'trusted-shops', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'trusted_shops_badge_options', 'desc' => sprintf( _x( '<a href="%s" target="_blank">Here</a> you can find a step-by-step introduction.', 'trusted-shops', 'woocommerce-germanized' ), $this->get_trusted_url( $this->base->urls[ 'integration' ] ) ) ),  
  131.  
  132. array( 
  133. 'title' => _x( 'Variant', 'trusted-shops', 'woocommerce-germanized' ),  
  134. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_trustbadge_variant',  
  135. 'type' => 'select',  
  136. 'class' => 'chosen_select',  
  137. 'options' => array(  
  138. 'hide_reviews' => _x( 'Display Trustbadge without review stars', 'trusted-shops', 'woocommerce-germanized' ),  
  139. 'standard' => _x( 'Display Trustbadge with review stars', 'trusted-shops', 'woocommerce-germanized' ),  
  140. 'disable' => _x( 'Don*t show Trustbadge', 'trusted-shops', 'woocommerce-germanized' ),  
  141. ),  
  142. 'default' => 'standard' 
  143. ),  
  144.  
  145. array( 
  146. 'title' => _x( 'Y-Offset', 'trusted-shops', 'woocommerce-germanized' ),  
  147. 'desc_tip' => _x( 'Adjust the y-axis position of your Trustbadge from 0-250 (pixel) vertically on low right hand side of your shop.', 'trusted-shops', 'woocommerce-germanized' ),  
  148. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_trustbadge_y',  
  149. 'type' => 'number',  
  150. 'desc' => __( 'px', 'trusted-shops', 'woocommerce-germanized' ),  
  151. 'default' => '0',  
  152. 'css' => 'max-width:60px;',  
  153. ),  
  154.  
  155. array( 
  156. 'title' => _x( 'Trustbadge code', 'trusted-shops', 'woocommerce-germanized' ),  
  157. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_trustbadge_code',  
  158. 'type' => 'textarea',  
  159. 'desc_tip' => true,  
  160. 'desc' => _x( 'Use shortcodes e.g. {variant} to dynamically insert your options. You may of couse replace them with static code.', 'trusted-shops', 'woocommerce-germanized' ),  
  161. 'css' => 'width: 100%; min-height: 150px',  
  162. 'default' => $this->base->get_trustbadge_code( false ),  
  163. ),  
  164.  
  165. array( 'type' => 'sectionend', 'id' => 'trusted_shops_badge_options' ),  
  166.  
  167. array( 'title' => _x( 'Configure Product Reviews', 'trusted-shops', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'trusted_shops_reviews_options' ),  
  168.  
  169. array( 
  170. 'title' => _x( 'Product Reviews', 'trusted-shops', 'woocommerce-germanized' ),  
  171. 'desc' => _x( 'Collect Product Reviews. This options replaces default WooCommerce Reviews.', 'trusted-shops', 'woocommerce-germanized' ),  
  172. 'desc_tip' => _x( 'More Traffic, less returns: Make sure to unlock unlimited Product Reviews in your Trusted Shops plan.', 'trusted-shops', 'woocommerce-germanized' ),  
  173. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_enable_reviews',  
  174. 'type' => 'checkbox',  
  175. 'default' => 'no' 
  176. ),  
  177.  
  178. array( 
  179. 'title' => _x( 'Product Review Sticker', 'trusted-shops', 'woocommerce-germanized' ),  
  180. 'desc' => _x( 'Show Product Reviews on Product Detail page on Reviews tab.', 'trusted-shops', 'woocommerce-germanized' ),  
  181. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_enable',  
  182. 'type' => 'checkbox',  
  183. 'default' => 'no' 
  184. ),  
  185.  
  186. array( 
  187. 'title' => _x( 'Border Color', 'trusted-shops', 'woocommerce-germanized' ),  
  188. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_border_color',  
  189. 'type' => 'color',  
  190. 'default' => '#FFDC0F',  
  191. ),  
  192.  
  193. array( 
  194. 'title' => _x( 'Star Color', 'trusted-shops', 'woocommerce-germanized' ),  
  195. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_star_color',  
  196. 'type' => 'color',  
  197. 'default' => '#C0C0C0',  
  198. ),  
  199.  
  200. array( 
  201. 'title' => _x( 'Star Size', 'trusted-shops', 'woocommerce-germanized' ),  
  202. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_star_size',  
  203. 'type' => 'number',  
  204. 'default' => '15',  
  205. 'desc' => __( 'px', 'trusted-shops', 'woocommerce-germanized' ),  
  206. 'css' => 'max-width:60px;',  
  207. ),  
  208.  
  209. array( 
  210. 'title' => _x( 'Product Sticker Code', 'trusted-shops', 'woocommerce-germanized' ),  
  211. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_code',  
  212. 'type' => 'textarea',  
  213. 'css' => 'width: 100%; min-height: 150px',  
  214. 'default' => $this->base->get_product_sticker_code( false ),  
  215. ),  
  216.  
  217. array( 
  218. 'title' => _x( 'Product Review Stars', 'trusted-shops', 'woocommerce-germanized' ),  
  219. 'desc' => _x( 'Show Star ratings on Product Detail Page below your Product Name.', 'trusted-shops', 'woocommerce-germanized' ),  
  220. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_enable',  
  221. 'type' => 'checkbox',  
  222. 'default' => 'no' 
  223. ),  
  224.  
  225. array( 
  226. 'title' => _x( 'Star Color', 'trusted-shops', 'woocommerce-germanized' ),  
  227. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_star_color',  
  228. 'type' => 'color',  
  229. 'default' => '#FFDC0F',  
  230. ),  
  231.  
  232. array( 
  233. 'title' => _x( 'Star Size', 'trusted-shops', 'woocommerce-germanized' ),  
  234. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_star_size',  
  235. 'type' => 'number',  
  236. 'default' => '15',  
  237. 'desc' => __( 'px', 'trusted-shops', 'woocommerce-germanized' ),  
  238. 'css' => 'max-width:60px;',  
  239. ),  
  240.  
  241. array( 
  242. 'title' => _x( 'Font Size', 'trusted-shops', 'woocommerce-germanized' ),  
  243. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_font_size',  
  244. 'type' => 'number',  
  245. 'desc' => __( 'px', 'trusted-shops', 'woocommerce-germanized' ),  
  246. 'default' => '12',  
  247. 'css' => 'max-width:60px;',  
  248. ),  
  249.  
  250. array( 
  251. 'title' => _x( 'GTIN Attribute', 'trusted-shops', 'woocommerce-germanized' ),  
  252. 'desc' => sprintf( _x( 'This is the product identification code for trade items. If you use Google Shopping and want to display your review stars in Shopping and payed product ads, this information is necessary for Google. Please choose from the product attributes which you have manually customized <a href="%s">here</a>.', 'trusted-shops', 'woocommerce-germanized' ), admin_url( 'edit.php?post_type=product&page=product_attributes' ) ),  
  253. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_gtin_attribute',  
  254. 'css' => 'min-width:250px;',  
  255. 'default' => 'gtin',  
  256. 'type' => 'select',  
  257. 'class' => 'chosen_select',  
  258. 'options' => $linked_attributes,  
  259. ),  
  260.  
  261. array( 
  262. 'title' => _x( 'Brand Attribute', 'trusted-shops', 'woocommerce-germanized' ),  
  263. 'desc' => sprintf( _x( 'This is the brand name of the product. By setting this variable you can improve your data analysis possibilities. If you create individual products and do not have a GTIN, you can pass the brand name along with the MPN to use Google Integration. Please choose from the product attributes which you have manually customized <a href="%s">here</a>.', 'trusted-shops', 'woocommerce-germanized' ), admin_url( 'edit.php?post_type=product&page=product_attributes' ) ),  
  264. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_brand_attribute',  
  265. 'css' => 'min-width:250px;',  
  266. 'default' => 'brand',  
  267. 'type' => 'select',  
  268. 'class' => 'chosen_select',  
  269. 'options' => $linked_attributes,  
  270. ),  
  271.  
  272. array( 
  273. 'title' => _x( 'MPN Attribute', 'trusted-shops', 'woocommerce-germanized' ),  
  274. 'desc' => sprintf( _x( 'Number that associates the product to its manufacturer. If you create individual products and do not have a GTIN, you can pass the MPN along with the brand name to use Google Integration. Please choose from the product attributes which you have manually customized <a href="%s">here</a>.', 'trusted-shops', 'woocommerce-germanized' ), admin_url( 'edit.php?post_type=product&page=product_attributes' ) ),  
  275. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_mpn_attribute',  
  276. 'css' => 'min-width:250px;',  
  277. 'default' => 'mpn',  
  278. 'type' => 'select',  
  279. 'class' => 'chosen_select',  
  280. 'options' => $linked_attributes,  
  281. ),  
  282.  
  283. array( 
  284. 'title' => _x( 'Product Review Code', 'trusted-shops', 'woocommerce-germanized' ),  
  285. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_code',  
  286. 'type' => 'textarea',  
  287. 'css' => 'width: 100%; min-height: 150px',  
  288. 'default' => $this->base->get_product_widget_code( false ),  
  289. ),  
  290.  
  291. array( 'type' => 'sectionend', 'id' => 'trusted_shops_reviews_options' ),  
  292.  
  293. array( 'title' => _x( 'Additional Options', 'trusted-shops', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'trusted_shops_additional_options' ),  
  294.  
  295. array( 
  296. 'title' => _x( 'Review Widget', 'trusted-shops', 'woocommerce-germanized' ),  
  297. 'desc' => _x( 'Enable Review Widget', 'trusted-shops', 'woocommerce-germanized' ),  
  298. 'desc_tip' => sprintf( _x( 'This option will enable a Widget which shows your Trusted Shops Reviews as a graphic. You may configure your Widgets <a href="%s">here</a>.', 'trusted-shops', 'woocommerce-germanized' ), admin_url( 'widgets.php' ) ),  
  299. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_review_widget_enable',  
  300. 'type' => 'checkbox',  
  301. 'default' => 'yes',  
  302. 'autoload' => false 
  303. ),  
  304.  
  305. array( 
  306. 'title' => _x( 'Rich Snippets', 'trusted-shops', 'woocommerce-germanized' ),  
  307. 'desc' => _x( 'Enable Rich Snippets Widget.', 'trusted-shops', 'woocommerce-germanized' ),  
  308. 'desc_tip' => _x( 'This option will update your reviews received via Trusted Shops once per day and enables a Widget to show your reviews as Rich Snippets', 'trusted-shops', 'woocommerce-germanized' ),  
  309. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_rich_snippets_enable',  
  310. 'type' => 'checkbox',  
  311. 'default' => 'yes',  
  312. 'autoload' => false 
  313. ),  
  314.  
  315. ); 
  316.  
  317. if ( $this->base->supports( 'reminder' ) ) { 
  318.  
  319. $options = array_merge( $options, array( 
  320.  
  321. array( 
  322. 'title' => _x( 'Review Reminder', 'trusted-shops', 'woocommerce-germanized' ),  
  323. 'desc' => sprintf( _x( 'Send a one-time email review reminder to your customers.', 'trusted-shops', 'woocommerce-germanized' ), admin_url( 'widgets.php' ) ),  
  324. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_review_reminder_enable',  
  325. 'type' => 'checkbox',  
  326. 'default' => 'no',  
  327. 'autoload' => false 
  328. ),  
  329.  
  330. array( 
  331. 'title' => _x( 'Days until reminder', 'trusted-shops', 'woocommerce-germanized' ),  
  332. 'desc' => _x( 'Decide how many days after an order the email review reminder will be sent.', 'trusted-shops', 'woocommerce-germanized' ),  
  333. 'desc_tip' => true,  
  334. 'default' => 7,  
  335. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_review_reminder_days',  
  336. 'type' => 'number',  
  337. 'custom_attributes' => array( 'min' => 0, 'step' => 1 ),  
  338.  
  339. ) ); 
  340.  
  341.  
  342. $options = array_merge( $options, array( 
  343.  
  344. array( 'type' => 'sectionend', 'id' => 'trusted_shops_additional_options' ),  
  345.  
  346. array( 'title' => _x( 'Assign payment methods', 'trusted-shops', 'woocommerce-germanized' ), 'type' => 'title', 'id' => 'trusted_shops_payment_options' ),  
  347.  
  348. ) ); 
  349.  
  350. $payment_gateways = WC()->payment_gateways->payment_gateways(); 
  351.  
  352. foreach ( $payment_gateways as $gateway ) { 
  353.  
  354. $default = ''; 
  355.  
  356. switch ( $gateway->id ) { 
  357. case 'bacs': 
  358. $default = 'prepayment'; 
  359. break; 
  360. case 'paypal': 
  361. $default = 'paypal'; 
  362. break; 
  363. case 'cod': 
  364. $default = 'cash_on_delivery'; 
  365. break; 
  366. case 'cheque': 
  367. $default = 'cash_on_delivery'; 
  368. break; 
  369. case 'mijireh_checkout': 
  370. $default = 'credit_card'; 
  371. break; 
  372. case 'direct-debit': 
  373. $default = 'direct_debit'; 
  374. break; 
  375. default: 
  376. $default = $gateway->id; 
  377.  
  378. array_push( $options, array( 
  379. 'title' => empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title,  
  380. 'desc' => sprintf( _x( 'Choose a Trusted Shops Payment Gateway linked to WooCommerce Payment Gateway %s', 'trusted-shops', 'woocommerce-germanized' ), empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title ),  
  381. 'desc_tip' => true,  
  382. 'id' => 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_gateway_' . $gateway->id,  
  383. 'css' => 'min-width:250px;',  
  384. 'default' => $default,  
  385. 'type' => 'select',  
  386. 'class' => 'chosen_select',  
  387. 'options' => $payment_options,  
  388. 'autoload' => false 
  389. ) ); 
  390.  
  391. array_push( $options, array( 'type' => 'sectionend', 'id' => 'trusted_shops_options' ) ); 
  392.  
  393. return $options; 
  394.  
  395.  
  396. public function get_sidebar() { 
  397. ob_start(); 
  398. ?> 
  399. <div class="wc-gzd-admin-settings-sidebar wc-gzd-admin-settings-sidebar-trusted-shops"> 
  400. <h3><?php echo _x( 'About Trusted Shops', 'trusted-shops', 'woocommerce-germanized' ); ?></h3> 
  401. <a href="<?php echo $this->get_signup_url( $this->base->urls[ 'signup' ] ); ?>" target="_blank"><img style="width: 100%; height: auto" src="<?php echo $this->base->plugin->plugin_url(); ?>/assets/images/trusted-shops-b.jpg" /></a> 
  402. <a class="button button-primary" href="<?php echo $this->get_signup_url( $this->base->urls[ 'signup' ] ); ?>" target="_blank"><?php echo _x( 'Get your account', 'trusted-shops', 'woocommerce-germanized' ); ?></a> 
  403. <div class="wc-gzd-trusted-shops-expert-mode-note"> 
  404. <p><?php echo _x( 'Use additional options to customize your Trusted Shops Integration or use the latest code version here. E.g.:', 'trusted-shops', 'woocommerce-germanized' ); ?></p> 
  405. <ul> 
  406. <li><?php echo _x( 'Place your Trustbadge wherever you want', 'trusted-shops', 'woocommerce-germanized' ); ?></li> 
  407. <li><?php echo _x( 'Deactivate mobile use', 'trusted-shops', 'woocommerce-germanized' ); ?></li> 
  408. <li><?php echo _x( 'Jump from your Product Reviews stars directly to your Product Reviews', 'trusted-shops', 'woocommerce-germanized' ); ?></li> 
  409. </ul> 
  410. <p><?php echo sprintf( _x( '<a href="%s" target="_blank">Learn more</a> about <a href="%s" target="_blank">Trustbadge</a> options and <a href="%s" target="_blank">Product Reviews</a> configuration.', 'trusted-shops', 'woocommerce-germanized' ), $this->get_trusted_url( $this->base->urls[ 'integration' ] ), $this->base->urls[ 'trustbadge_custom' ], $this->base->urls[ 'reviews' ] ); ?></p> 
  411. </div> 
  412. </div> 
  413. <?php 
  414.  
  415. $html = ob_get_clean(); 
  416. return $html; 
  417.  
  418. public function before_save( $settings ) { 
  419. if ( ! empty( $settings ) ) { 
  420.  
  421. foreach ( $settings as $setting ) { 
  422.  
  423. // Update reviews & snippets if new ts id has been inserted 
  424. if ( isset( $_POST[ 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_id' ] ) && $_POST[ 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_id' ] != $this->base->id ) { 
  425. update_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_snippets', 1 ); 
  426. update_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_reviews', 1 ); 
  427.  
  428. if ( $setting[ 'id' ] == 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_review_widget_enable' ) { 
  429. if ( ! empty( $_POST[ 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_review_widget_enable' ] ) && ! $this->base->is_review_widget_enabled() ) 
  430. update_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_reviews', 1 ); 
  431. } elseif ( $setting[ 'id' ] == 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_rich_snippets_enable' ) { 
  432. if ( ! empty( $_POST[ 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_rich_snippets_enable' ] ) && ! $this->base->is_rich_snippets_enabled() ) 
  433. update_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_snippets', 1 ); 
  434.  
  435. public function after_save( $settings ) { 
  436.  
  437. $this->base->refresh(); 
  438.  
  439. if ( get_option( 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_integration_mode' ) === 'standard' ) { 
  440. // Delete code snippets 
  441. delete_option( 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_trustbadge_code' ); 
  442. delete_option( 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_sticker_code' ); 
  443. delete_option( 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_product_widget_code' ); 
  444.  
  445. // Disable Reviews if Trusted Shops review collection has been enabled 
  446. if ( get_option( 'woocommerce_' . $this->base->option_prefix . 'trusted_shops_enable_reviews' ) === 'yes' ) 
  447. update_option( 'woocommerce_enable_review_rating', 'no' ); 
  448.  
  449. if ( get_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_reviews' ) ) { 
  450. $this->base->get_dependency( 'schedule' )->update_review_widget(); 
  451.  
  452. if ( get_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_snippets' ) ) 
  453. $this->base->get_dependency( 'schedule' )->update_reviews(); 
  454.  
  455. delete_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_reviews' ); 
  456. delete_option( '_woocommerce_' . $this->base->option_prefix . 'trusted_shops_update_snippets' ); 
  457.  
  458. public function review_collector_export_csv() { 
  459.  
  460. if ( ! isset( $_GET[ 'action' ] ) || $_GET[ 'action' ] != 'wc_' . $this->base->option_prefix . 'trusted-shops-export' || ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wc_' . $this->base->option_prefix . 'trusted-shops-export' && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'wc_' . $this->base->option_prefix . 'trusted-shops-export' ) ) ) 
  461. return; 
  462.  
  463. $interval_d = ( ( isset( $_GET[ 'interval' ] ) && ! empty( $_GET[ 'interval' ] ) ) ? absint( $_GET[ 'interval' ] ) : 30 ); 
  464.  
  465. header( 'Content-Description: File Transfer' ); 
  466. header( 'Content-Disposition: attachment; filename=review-collector.csv' ); 
  467. header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true ); 
  468. header( 'Cache-Control: no-cache, no-store, must-revalidate' );  
  469. header( 'Pragma: no-cache' ); 
  470. header( 'Expires: 0' );  
  471.  
  472. $date = date( 'Y-m-d', strtotime( '-' . $interval_d . ' days') ); 
  473. $order_query = new WP_Query( 
  474. array(  
  475. 'post_type' => 'shop_order',  
  476. 'post_status' => array( 'wc-completed' ),  
  477. 'showposts' => -1,  
  478. 'date_query' => array( 
  479. array( 
  480. 'after' => $date,  
  481. ),  
  482. ),  
  483. ); 
  484.  
  485. $data = array(); 
  486.  
  487. while ( $order_query->have_posts() ) { 
  488. $order_query->next_post(); 
  489. $order = wc_get_order( $order_query->post->ID ); 
  490. array_push( $data, array(  
  491. wc_gzd_get_crud_data( $order, 'billing_email' ),  
  492. wc_gzd_get_crud_data( $order, 'id' ),  
  493. wc_gzd_get_crud_data( $order, 'billing_first_name' ),  
  494. wc_gzd_get_crud_data( $order, 'billing_last_name' )  
  495. ) ); 
  496.  
  497. $write = $this->prepare_csv_data( $data ); 
  498. $df = fopen( "php://output", 'w' ); 
  499. foreach ( $write as $row ) 
  500. fwrite( $df, $row ); 
  501. fclose( $df ); 
  502.  
  503. exit(); 
  504.  
  505. public function prepare_csv_data( $row ) { 
  506. foreach ( $row as $key => $row_data ) { 
  507. foreach ( $row_data as $rkey => $rvalue ) 
  508. $row[ $key ][ $rkey ] = $this->encode_csv_data( str_replace( '"', '\"', $rvalue ) ); 
  509. $row[ $key ] = implode( ", ", $row[ $key ] ) . "\n"; 
  510. return $row; 
  511.  
  512. public function encode_csv_data( $string ) { 
  513. return iconv( get_option( 'blog_charset' ), 'Windows-1252', $string ); 
  514.  
  515. public function review_collector_export() { 
  516. ?> 
  517. <h3><?php echo _x( 'Review Collector', 'trusted-shops', 'woocommerce-germanized' ); ?></h3> 
  518. <table class="form-table"> 
  519. <tbody> 
  520. <tr valign="top"> 
  521. <th scope="row" class="titledesc"> 
  522. <label for="woocommerce_gzd_trusted_shops_review_collector"><?php echo _x( 'Export customer data', 'trusted-shops', 'woocommerce-germanized' ); ?></label> 
  523. </th> 
  524. <td class="forminp forminp-select"> 
  525. <select name="woocommerce_<?php echo $this->base->option_prefix; ?>trusted_shops_review_collector" id="woocommerce_<?php echo $this->base->option_prefix; ?>trusted_shops_review_collector" class="chosen_select"> 
  526. <option value="30"><?php echo _x( '30 days', 'trusted-shops', 'woocommerce-germanized' ); ?></option> 
  527. <option value="60"><?php echo _x( '60 days', 'trusted-shops', 'woocommerce-germanized' ); ?></option> 
  528. <option value="90"><?php echo _x( '90 days', 'trusted-shops', 'woocommerce-germanized' ); ?></option> 
  529. </select> 
  530. <p><a class="button button-secondary" id="wc-gzd-trusted-shops-export" data-href-org="<?php echo admin_url( '?action=wc_' . $this->base->option_prefix . 'trusted-shops-export&_wpnonce=' . wp_create_nonce( 'wc_' . $this->base->option_prefix . 'trusted-shops-export' ) ); ?>" href="#"><?php echo _x( 'Start export', 'trusted-shops', 'woocommerce-germanized' ); ?></a></p> 
  531. <p class="description"><?php printf( _x( 'Export your customer data and ask consumers for a review with the Trusted Shops <a href="%s" target="_blank">Review Collector</a>.', 'trusted-shops', 'woocommerce-germanized' ), 'https://www.trustedshops.com/tsb2b/sa/ratings/batchRatingRequest.seam?prefLang=' . substr( get_bloginfo( 'language' ), 0, 2 ) ); ?></p> 
  532. </td> 
  533. </tr> 
  534. </tbody> 
  535. </table> 
  536. <?php 
  537.  
  538. private function get_signup_url( $url, $args = array() ) { 
  539.  
  540. $args = array_merge( $this->base->signup_params, $args ); 
  541.  
  542. $args = wp_parse_args( $args, array( 
  543. 'utm_content' => 'marketing-page',  
  544. 'utm_medium' => 'software-app',  
  545. ) ); 
  546.  
  547. return add_query_arg( $args, $url ); 
  548.  
  549. private function get_trusted_url( $url, $args = array() ) { 
  550.  
  551. $args = array_merge( $this->base->et_params, $args ); 
  552.  
  553. $args = wp_parse_args( $args, array( 
  554. 'utm_term' => substr( get_locale(), 0, 2 ),  
  555. 'utm_medium' => 'link',  
  556. 'utm_source' => 'shopsoftwarebackend',  
  557. 'shop_id' => $this->base->ID,  
  558. ) ); 
  559.  
  560. return add_query_arg( $args, $url ); 
  561.