No Description

class-woo-custom-emails-assigned-messages.php 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. <?php
  2. /**
  3. * The WCE Assigned Messages settings page.
  4. *
  5. * @since 2.2.6
  6. */
  7. // Load table class from WP core.
  8. if( ! class_exists( 'WP_List_Table' ) ) {
  9. require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  10. }
  11. // Create reusable Class.
  12. class WCE_AssignedMessagesTable extends WP_List_Table {
  13. // Define found_data array.
  14. public $found_data = array();
  15. /*
  16. * Function to get WCE Message Statuses.
  17. */
  18. public function get_wcemessage_statuses( $this_id ) {
  19. $assignedmsgs = '';
  20. $wcemessage_id_onhold =
  21. $wcemessage_id_processing =
  22. $wcemessage_id_completed =
  23. $wcemessage_location_onhold =
  24. $wcemessage_location_processing =
  25. $wcemessage_location_completed =
  26. $wce_onhold_message_title =
  27. $wce_onhold_message_editURL =
  28. $wce_processing_message_title =
  29. $wce_processing_message_editURL =
  30. $wce_completed_message_title =
  31. $wce_completed_message_editURL =
  32. $this_wcemessage_id_onhold =
  33. $this_wcemessage_id_processing =
  34. $this_wcemessage_id_completed =
  35. $this_orderstatus_onhold =
  36. $this_orderstatus_processing =
  37. $this_orderstatus_completed =
  38. $this_location_onhold =
  39. $this_location_processing =
  40. $this_location_completed = '';
  41. // Get WCE Message meta.
  42. $wcemessage_id_onhold = (int) get_post_meta( $this_id, 'wcemessage_id_onhold', true );
  43. $wcemessage_location_onhold = get_post_meta( $this_id, 'location_onhold', true );
  44. $wcemessage_id_processing = (int) get_post_meta( $this_id, 'wcemessage_id_processing', true );
  45. $wcemessage_location_processing = get_post_meta( $this_id, 'location_processing', true );
  46. $wcemessage_id_completed = (int) get_post_meta( $this_id, 'wcemessage_id_completed', true );
  47. $wcemessage_location_completed = get_post_meta( $this_id, 'location_completed', true );
  48. // Check for On-Hold content.
  49. if ( $wcemessage_id_onhold > 0 ) {
  50. $this_orderstatus_onhold = '<span class="on-hold">On Hold</span>';
  51. $this_wcemessage_id_onhold = $wcemessage_id_onhold;
  52. $wce_onhold_message_title = get_the_title( $this_wcemessage_id_onhold );
  53. $wce_onhold_message_editURL = get_edit_post_link( $this_wcemessage_id_onhold );
  54. }
  55. // Check for Processing content.
  56. if ( $wcemessage_id_processing > 0 ) {
  57. $this_orderstatus_processing = '<span class="processing">Processing</span>';
  58. $this_wcemessage_id_processing = $wcemessage_id_processing;
  59. $wce_processing_message_title = get_the_title( $this_wcemessage_id_processing );
  60. $wce_processing_message_editURL = get_edit_post_link( $this_wcemessage_id_processing );
  61. }
  62. // Check for Completed content.
  63. if ( $wcemessage_id_completed > 0 ) {
  64. $this_orderstatus_completed = '<span class="completed">Completed</span>';
  65. $this_wcemessage_id_completed = $wcemessage_id_completed;
  66. $wce_completed_message_title = get_the_title( $this_wcemessage_id_completed );
  67. $wce_completed_message_editURL = get_edit_post_link( $this_wcemessage_id_completed );
  68. }
  69. // Determine Location string for On-Hold status.
  70. switch ( $wcemessage_location_onhold ) {
  71. case 'woocommerce_email_before_order_table':
  72. $this_location_onhold = 'Before Order Table';
  73. break;
  74. case 'woocommerce_email_after_order_table':
  75. $this_location_onhold = 'After Order Table';
  76. break;
  77. case 'woocommerce_email_order_meta':
  78. $this_location_onhold = 'After Order Meta';
  79. break;
  80. case 'woocommerce_email_customer_details':
  81. $this_location_onhold = 'After Customer Details';
  82. break;
  83. }
  84. // Determine Location string for Processing status.
  85. switch ( $wcemessage_location_processing ) {
  86. case 'woocommerce_email_before_order_table':
  87. $this_location_processing = 'Before Order Table';
  88. break;
  89. case 'woocommerce_email_after_order_table':
  90. $this_location_processing = 'After Order Table';
  91. break;
  92. case 'woocommerce_email_order_meta':
  93. $this_location_processing = 'After Order Meta';
  94. break;
  95. case 'woocommerce_email_customer_details':
  96. $this_location_processing = 'After Customer Details';
  97. break;
  98. }
  99. // Determine Location string for Completed status.
  100. switch ( $wcemessage_location_completed ) {
  101. case 'woocommerce_email_before_order_table':
  102. $this_location_completed = 'Before Order Table';
  103. break;
  104. case 'woocommerce_email_after_order_table':
  105. $this_location_completed = 'After Order Table';
  106. break;
  107. case 'woocommerce_email_order_meta':
  108. $this_location_completed = 'After Order Meta';
  109. break;
  110. case 'woocommerce_email_customer_details':
  111. $this_location_completed = 'After Customer Details';
  112. break;
  113. }
  114. $messages = array();
  115. $statuses = array();
  116. $locations = array();
  117. /* MESSAGES
  118. ----------------------------------- */
  119. // ON-HOLD.
  120. if ( $this_wcemessage_id_onhold ) {
  121. $messages[] = '<div class="on-hold"><span><a href="' . $wce_onhold_message_editURL . '" target="_blank">' . $wce_onhold_message_title . '</a></span></div>';
  122. }
  123. // PROCESSING.
  124. if ( $this_wcemessage_id_processing ) {
  125. $messages[] = '<div class="processing"><span><a href="' . $wce_processing_message_editURL . '" target="_blank">' . $wce_processing_message_title . '</a></span></div>';
  126. }
  127. // COMPLETED.
  128. if ( $this_wcemessage_id_completed ) {
  129. $messages[] = '<div class="completed"><span><a href="' . $wce_completed_message_editURL . '" target="_blank">' . $wce_completed_message_title . '</a></span></div>';
  130. }
  131. /* STATUSES
  132. ----------------------------------- */
  133. // ON-HOLD.
  134. if ( $this_wcemessage_id_onhold ) {
  135. $statuses[] = '<div class="on-hold">' . $this_orderstatus_onhold . '</div>';
  136. }
  137. // PROCESSING.
  138. if ( $this_wcemessage_id_processing ) {
  139. $statuses[] = '<div class="processing">' . $this_orderstatus_processing . '</div>';
  140. }
  141. // COMPLETED.
  142. if ( $this_wcemessage_id_completed ) {
  143. $statuses[] = '<div class="completed">' . $this_orderstatus_completed . '</div>';
  144. }
  145. /* LOCATIONS
  146. ----------------------------------- */
  147. // ON-HOLD.
  148. if ( $this_wcemessage_id_onhold ) {
  149. $locations[] = '<div class="on-hold">' . $this_location_onhold . '</div>';
  150. }
  151. // PROCESSING.
  152. if ( $this_wcemessage_id_processing ) {
  153. $locations[] = '<div class="processing">' . $this_location_processing . '</div>';
  154. }
  155. // COMPLETED.
  156. if ( $this_wcemessage_id_completed ) {
  157. $locations[] = '<div class="completed">' . $this_location_completed . '</div>';
  158. }
  159. return array (
  160. 'messages' => $messages,
  161. 'statuses' => $statuses,
  162. 'locations' => $locations,
  163. );
  164. }
  165. /*
  166. * Function to get WCE Messages.
  167. */
  168. public function get_wcemessages() {
  169. // Get paged var.
  170. $paged = get_query_var( 'paged', 1 );
  171. // Get Screen Options setting for number of posts to show.
  172. $user = get_current_user_id();
  173. $screen = get_current_screen();
  174. $option = $screen->get_option( 'per_page', 'option' );
  175. $per_page = get_user_meta($user, $option, true);
  176. if ( empty ( $per_page) || $per_page < 1 ) {
  177. $per_page = $screen->get_option( 'per_page', 'default' );
  178. }
  179. // Create query args.
  180. $wce_queryargs = array(
  181. 'post_type' => 'product',
  182. 'posts_per_page' => -1, // TODO: improve query!
  183. 'paged' => $paged,
  184. 'meta_query' => array(
  185. 'relation' => 'OR',
  186. array(
  187. 'key' => 'wcemessage_id_onhold',
  188. 'value' => '',
  189. 'compare' => '!=',
  190. ),
  191. array(
  192. 'key' => 'wcemessage_id_processing',
  193. 'value' => '',
  194. 'compare' => '!=',
  195. ),
  196. array(
  197. 'key' => 'wcemessage_id_completed',
  198. 'value' => '',
  199. 'compare' => '!=',
  200. ),
  201. ),
  202. 'update_post_term_cache' => false // false when taxonomy terms will not be utilized
  203. );
  204. // Create query.
  205. $wce_query = new WP_Query( $wce_queryargs );
  206. // Begin setting up array.
  207. if ( $wce_query->have_posts() ) {
  208. while ( $wce_query->have_posts() ) {
  209. $wce_query->the_post();
  210. $id = get_the_ID();
  211. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'thumbnail' );
  212. $imgsrc = '<img src="' . $thumbnail[0] . '" class="thumb" />';
  213. $title = '<div class="product-title">' . html_entity_decode( get_the_title() ) . '</div>';
  214. // Get array of all message statuses.
  215. $msgstatuses = $this->get_wcemessage_statuses( $id );
  216. // Create empty vars.
  217. $messages_content =
  218. $statuses_content =
  219. $locations_content = '';
  220. // List out all Messages.
  221. for ( $m = 0; $m < count( $msgstatuses['messages'] ); $m++ ) {
  222. $messages_content .= $msgstatuses['messages'][$m];
  223. }
  224. // List out all Statuses.
  225. for ( $s = 0; $s < count( $msgstatuses['statuses'] ); $s++ ) {
  226. $statuses_content .= $msgstatuses['statuses'][$s];
  227. }
  228. // List out all Locations.
  229. for ( $l = 0; $l < count( $msgstatuses['locations'] ); $l++ ) {
  230. $locations_content .= $msgstatuses['locations'][$l];
  231. }
  232. // Create array of items to export.
  233. $wce_msg_array[] = array(
  234. 'ID' => $id,
  235. 'thumb' => $imgsrc,
  236. 'producttitle' => $title,
  237. 'assignedmsgs' => $messages_content,
  238. 'orderstatus' => $statuses_content,
  239. 'msglocation' => $locations_content,
  240. );
  241. }
  242. wp_reset_postdata();
  243. }
  244. // Return array.
  245. return $wce_msg_array;
  246. }
  247. // Constructor.
  248. function __construct() {
  249. global $status, $page;
  250. parent::__construct( array(
  251. 'singular' => __( 'product', 'woocustomemails' ), //singular name of the listed records
  252. 'plural' => __( 'products', 'woocustomemails' ), //plural name of the listed records
  253. 'ajax' => false //does this table support ajax?
  254. ));
  255. }
  256. // Function to display Not Found message.
  257. function no_items() {
  258. _e( 'No products with assigned WCE Messages were found.' );
  259. }
  260. // Create all columns.
  261. function column_default( $item, $column_name ) {
  262. switch( $column_name ) {
  263. case 'ID':
  264. case 'thumb':
  265. case 'producttitle':
  266. case 'assignedmsgs':
  267. case 'orderstatus':
  268. case 'msglocation':
  269. return $item[ $column_name ];
  270. default:
  271. return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
  272. }
  273. }
  274. // Get the sortable columns.
  275. function get_sortable_columns() {
  276. $sortable_columns = array(
  277. 'ID' => array( 'ID', false ),
  278. 'producttitle' => array( 'producttitle', false ),
  279. );
  280. return $sortable_columns;
  281. }
  282. // Get the columns.
  283. function get_columns(){
  284. $columns = array(
  285. 'cb' => '<input type="checkbox" />',
  286. 'ID' => __( 'ID', 'woocustomemails' ),
  287. 'thumb' => '<span class="dashicons dashicons-format-image"></span>',
  288. 'producttitle' => __( 'Product Name', 'woocustomemails' ),
  289. 'assignedmsgs' => __( 'Assigned WCE Messages', 'woocustomemails' ),
  290. 'orderstatus' => __( 'Order Status', 'woocustomemails' ),
  291. 'msglocation' => __( 'Message Location', 'woocustomemails' ),
  292. );
  293. return $columns;
  294. }
  295. // Sorting.
  296. function usort_reorder( $a, $b ) {
  297. // If no sort, default to ID.
  298. $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'ID';
  299. // If no order, default to asc.
  300. $order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';
  301. // Determine sort order.
  302. $result = strcmp( $a[$orderby], $b[$orderby] );
  303. // Send final sort direction to usort.
  304. return ( $order === 'asc' ) ? $result : -$result;
  305. }
  306. // Display titles.
  307. function column_producttitle( $item ){
  308. $actions = array (
  309. 'edit' => sprintf (
  310. '<a href="%s">Edit</a>',
  311. get_edit_post_link( $item['ID'] )
  312. ),
  313. // 'delete' => sprintf (
  314. // '<a href="%s">Delete</a>',
  315. // get_delete_post_link( $item['ID'] )
  316. // ),
  317. );
  318. return sprintf (
  319. '%1$s %2$s',
  320. $item['producttitle'],
  321. $this->row_actions( $actions )
  322. );
  323. }
  324. // Get the bulk actions.
  325. function get_bulk_actions() {
  326. $actions = array(
  327. 'delete' => 'Delete'
  328. );
  329. return $actions;
  330. }
  331. // Add column checkboxes.
  332. function column_cb( $item ) {
  333. return sprintf(
  334. '<input type="checkbox" name="book[]" value="%s" />', $item['ID']
  335. );
  336. }
  337. // Function to prepare items for display in the Table.
  338. function prepare_items() {
  339. $columns = $this->get_columns();
  340. $hidden = array();
  341. $sortable = $this->get_sortable_columns();
  342. $this->_column_headers = array( $columns, $hidden, $sortable );
  343. $wce_querydata = $this->get_wcemessages();
  344. usort( $wce_querydata, array( &$this, 'usort_reorder' ) );
  345. $user = get_current_user_id();
  346. $screen = get_current_screen();
  347. $option = $screen->get_option( 'per_page', 'option' );
  348. $per_page = get_user_meta($user, $option, true);
  349. if ( empty ( $per_page) || $per_page < 1 ) {
  350. $per_page = $screen->get_option( 'per_page', 'default' );
  351. }
  352. $current_page = $this->get_pagenum();
  353. $total_items = count( $wce_querydata );
  354. // Assign found data var.
  355. $this->found_data = array_slice( $wce_querydata,( ( $current_page-1 )* $per_page ), $per_page );
  356. // Set pagination.
  357. $this->set_pagination_args( array(
  358. 'total_items' => $total_items, // Calculate the total number of items
  359. 'per_page' => $per_page // Determine how many items to show on a page
  360. ));
  361. // Set data to read.
  362. $this->items = $this->found_data;
  363. }
  364. } // End WCE_AssignedMessagesTable class.
  365. // function wce_add_assignedmsgs_settings_page() {
  366. //
  367. // $wce_assignedmessages_menu = add_submenu_page(
  368. // 'edit.php?post_type=woocustomemails',
  369. // __('Assigned Messages','woo_custom_emails_domain'), // page title
  370. // __('Assigned Messages','woo_custom_emails_domain'), // menu title
  371. // 'manage_options', // capability
  372. // 'woocustomemails_assigned', // menu slug
  373. // 'wcemessages_render_list_page'
  374. // );
  375. // add_action( "load-$wce_assignedmessages_menu", 'add_options' );
  376. //
  377. // add_action( 'admin_print_styles-' . $wce_assignedmessages_menu, 'wce_custom_admin_css' );
  378. //
  379. // function wce_custom_admin_css() {
  380. // wp_enqueue_style( 'wce-admin-styles', plugins_url( '/woocustomemails-admin-styles.css', __FILE__ ) );
  381. // }
  382. //
  383. // }
  384. // add_action( 'admin_menu', 'wce_add_assignedmsgs_settings_page' );
  385. // Add the Screen Options settings.
  386. function add_options() {
  387. global $woocustomemails;
  388. $option = 'per_page';
  389. $args = array(
  390. 'label' => 'Products',
  391. 'default' => 10,
  392. 'option' => 'products_per_page'
  393. );
  394. add_screen_option( $option, $args );
  395. $woocustomemails = new WCE_AssignedMessagesTable();
  396. }
  397. // Save the user's Screen Options setting for "per page" value.
  398. add_filter( 'set-screen-option', 'wce_save_screen_options', 10, 3 );
  399. function wce_save_screen_options( $status, $option, $value ) {
  400. if ( 'products_per_page' == $option ) {
  401. return $value;
  402. }
  403. return $status;
  404. }
  405. // Render the List Table.
  406. function wcemessages_render_list_page(){
  407. global $woocustomemails;
  408. echo '<div class="wrap"><h2>Woo Custom Emails - Assigned Messages</h2>';
  409. $woocustomemails->prepare_items();
  410. ?>
  411. <form method="post">
  412. <input type="hidden" name="page" value="wcemessages_list_table">
  413. <?php
  414. $woocustomemails->search_box( 'search', 'search_id' );
  415. $woocustomemails->display();
  416. echo '</form></div>';
  417. }
  418. // -------------------------------------------------------------------------- //
  419. // -------------------------------------------------------------------------- //
  420. // class Woo_Custom_Emails_Assigned_Products() {
  421. //
  422. // public function __construct(){
  423. //
  424. // // Add 'Assigned Messages' page under WCE menu
  425. // add_action( 'admin_menu', array( $this, 'add_woocustomemails_assignedmessages_menu' ) );
  426. //
  427. // }
  428. //
  429. // }
  430. // public function add_woocustomemails_assignedmessages_menu() {
  431. //
  432. // $wce_assignedmessages_menu = add_submenu_page(
  433. // 'edit.php?post_type=woocustomemails',
  434. // __('Assigned Messages','woo_custom_emails_domain'), // page title
  435. // __('Assigned Messages','woo_custom_emails_domain'), // menu title
  436. // 'manage_options', // capability
  437. // 'woocustomemails_assigned', // menu slug
  438. // array( $this, 'display_wce_assigned_page' )
  439. // );
  440. //
  441. // add_action( 'admin_print_styles-' . $wce_assignedmessages_menu, 'wce_custom_admin_css' );
  442. //
  443. // function wce_custom_admin_css() {
  444. // wp_enqueue_style( 'wce-admin-styles', plugins_url( '/woocustomemails-admin-styles.css', __FILE__ ) );
  445. // }
  446. //
  447. // }
  448. // public function woo_custom_emails_insert_db_testrow() {
  449. //
  450. // // Global var for WP db.
  451. // global $wpdb;
  452. //
  453. // // Show errors for development.
  454. // $wpdb->suppress_errors(false);
  455. // $wpdb->show_errors(true);
  456. //
  457. // // Custom Table name.
  458. // $table_name = $wpdb->prefix . 'wcepp_messages';
  459. //
  460. // // Product ID.
  461. // $product_id = 6;
  462. //
  463. // // Message ID for status: Processing.
  464. // $msg_processing = '16';
  465. //
  466. // // Message Location for status: Processing.
  467. // $msg_processing_loc = 'After Order Table';
  468. //
  469. // // Message ID for status: On-Hold.
  470. // $msg_onhold = '16';
  471. //
  472. // // Message Location for status: On-Hold.
  473. // $msg_onhold_loc = 'After Order Table';
  474. //
  475. // // Message ID for status: Completed.
  476. // $msg_completed = '16';
  477. //
  478. // // Message Location for status: Completed.
  479. // $msg_completed_loc = 'After Customer Details';
  480. //
  481. // // Create array of values to be entered.
  482. // $data_array = array(
  483. // 'product_id' => $product_id,
  484. // 'msg_processing' => $msg_processing,
  485. // 'msg_processing_loc' => $msg_processing_loc,
  486. // 'msg_onhold' => $msg_onhold,
  487. // 'msg_onhold_loc' => $msg_onhold_loc,
  488. // 'msg_completed' => $msg_completed,
  489. // 'msg_completed_loc' => $msg_completed_loc,
  490. // );
  491. //
  492. // // Start a new query to find existing rows.
  493. // $existingrows_query = "SELECT * FROM $table_name WHERE product_id = '$product_id'";
  494. //
  495. // // Get the results.
  496. // $query_results = $wpdb->get_results( $existingrows_query );
  497. //
  498. // // If the row does not exist...
  499. // if ( count( $query_results ) == 0 ) {
  500. // // ... insert the data.
  501. // $rowResult = $wpdb->insert( $table_name, $data_array );
  502. // $insert_latest_id = $wpdb->insert_id;
  503. // if ( ! $rowResult ) {
  504. // // Show Error message.
  505. // echo '<div id="message" class="updated fade"><p>😞 <b>NOT ADDED:</b> FAILED TO ADD DATA.</p></div>';
  506. // } else {
  507. // // Show Success message.
  508. // echo '<div id="message" class="updated fade"><p>😎 <b>ADDED:</b> ROW #' . $insert_latest_id . ' ADDED!</p></div>';
  509. // }
  510. // } else {
  511. // // ...the row exists, attempt to update.
  512. //
  513. // // Get current row info.
  514. // $therow = $query_results[0];
  515. // $rowid = $therow->id;
  516. // $product_id = $therow->product_id;
  517. // $old_msg_processing = $therow->msg_processing;
  518. // $old_msg_processing_loc = $therow->msg_processing_loc;
  519. // $old_msg_onhold = $therow->msg_onhold;
  520. // $old_msg_onhold_loc = $therow->msg_onhold_loc;
  521. // $old_msg_completed = $therow->msg_completed;
  522. // $old_msg_completed_loc = $therow->msg_completed_loc;
  523. //
  524. // // Tracking vars.
  525. // $changed_item =
  526. // $colname =
  527. // $colval = '';
  528. //
  529. // // Assign vars.
  530. // if ( $old_msg_processing !== $msg_processing ) {
  531. // $changed_item = 'Processing Message';
  532. // $colname = 'msg_processing';
  533. // $colval = $msg_processing;
  534. // } else if ( $old_msg_processing_loc !== $msg_processing_loc ) {
  535. // $changed_item = 'Processing Message Location';
  536. // $colname = 'msg_processing_loc';
  537. // $colval = $msg_processing_loc;
  538. // } else if ( $old_msg_onhold !== $msg_onhold ) {
  539. // $changed_item = 'On-Hold Message';
  540. // $colname = 'msg_onhold';
  541. // $colval = $msg_onhold;
  542. // } else if ( $old_msg_onhold_loc !== $msg_onhold_loc ) {
  543. // $changed_item = 'On-Hold Message Location';
  544. // $colname = 'msg_onhold_loc';
  545. // $colval = $msg_onhold_loc;
  546. // } else if ( $old_msg_completed !== $msg_completed ) {
  547. // $changed_item = 'Completed Message';
  548. // $colname = 'msg_completed';
  549. // $colval = $msg_completed;
  550. // } else if ( $old_msg_completed_loc !== $msg_completed_loc ) {
  551. // $changed_item = 'Completed Message Location';
  552. // $colname = 'msg_completed_loc';
  553. // $colval = $msg_completed_loc;
  554. // }
  555. //
  556. // // If nothing is changed...
  557. // if ( '' === $changed_item ) {
  558. // // ...show the Nothing Updated message.
  559. // echo '<div id="message" class="updated fade"><p>🤷🏼‍♂️ <b>NOTHING UPDATED:</b> NO VALUES CHANGED IN ROW #' . $therow->id . '.</p></div>';
  560. // } else {
  561. // // ...changes are present, run the update.
  562. // $wpdb->update(
  563. // $table_name,
  564. // array(
  565. // $colname => $colval
  566. // ),
  567. // array(
  568. // 'product_id' => $product_id,
  569. // )
  570. // );
  571. //
  572. // // Show Update message.
  573. // echo '<div id="message" class="updated fade"><p>🔁 <b>UPDATED:</b> VALUE OF <b>' . $changed_item . '</b> IN ROW #' . $therow->id . '.</p></div>';
  574. // }
  575. // }
  576. //
  577. //
  578. // }
  579. /**
  580. * Show the WCE Assigned Messages page content
  581. *
  582. * @since 2.2.6
  583. */
  584. // public function display_wce_assigned_page() {
  585. // $output = '';
  586. // ? >
  587. // <div class="wrap">
  588. //
  589. // <h1 class="wp-heading-inline">Woo Custom Emails - Assigned Messages</h1>
  590. //<? php
  591. // // Setup query arguments.
  592. // $paged = get_query_var( 'paged', 1 );
  593. // $args = array(
  594. // 'post_type' => 'product',
  595. // 'no_found_rows' => true,
  596. // 'posts_per_page' => 10,
  597. // 'paged' => $paged,
  598. // // 'orderby' => 'name', // (string) - Order posts by: name, date, rand.
  599. // // 'order' => 'asc', // (string) - Post order: asc, desc.
  600. // 'meta_query' => array(
  601. // 'relation' => 'OR',
  602. // array(
  603. // 'key' => 'wcemessage_id_onhold',
  604. // 'value' => '',
  605. // 'compare' => '!=',
  606. // ),
  607. // array(
  608. // 'key' => 'wcemessage_id_processing',
  609. // 'value' => '',
  610. // 'compare' => '!=',
  611. // ),
  612. // array(
  613. // 'key' => 'wcemessage_id_completed',
  614. // 'value' => '',
  615. // 'compare' => '!=',
  616. // ),
  617. // ),
  618. // );
  619. //
  620. // // Create query object.
  621. // $assigned_query = new WP_Query( $args );
  622. //
  623. // $total_posts = $assigned_query->post_count;
  624. //
  625. // $output .= '<div class="post-count">';
  626. // // $output .= '<p>You have <b>' . $total_posts . '</b> products with WCE Messages assigned.';
  627. //
  628. // // Message for 0 found products.
  629. // if ( $total_posts < 1 ) {
  630. // $output .= ' You can assign a WCE Message under the "Messages" tab when editing a product. <a href="' . get_bloginfo('url') . '/wp-admin/edit.php?post_type=product">See All Products &rarr;</a>';
  631. // }
  632. //
  633. // $output .= '</p></div>';
  634. //
  635. // // Open HTML output.
  636. // $output .= '<div class="assigned-wce-messages">';
  637. //
  638. // // If query object has posts...
  639. // if ( $assigned_query->have_posts() ) {
  640. //
  641. // // Open data table.
  642. // $output .= '<table>';
  643. // $output .= '<thead class="header">';
  644. //
  645. // // Product Count column.
  646. // $output .= '<td class="product-count">#</td>';
  647. //
  648. // // Product column.
  649. // $output .= '<td class="product-title">Product</td>';
  650. //
  651. // // Assigned Message Title column.
  652. // $output .= '<td class="assigned-message-title">Assigned WCE Messages</td>';
  653. //
  654. // // Assigned Message Order Status column.
  655. // $output .= '<td class="assigned-message-orderstatus">Order Status</td>';
  656. //
  657. // // Assigned Message Template Location column.
  658. // $output .= '<td class="assigned-message-templatelocation">Location</td>';
  659. //
  660. // $output .= '</thead>';
  661. // $output .= '<tbody>';
  662. //
  663. // $count = 1;
  664. //
  665. // // While query has posts...
  666. // while( $assigned_query->have_posts() ) {
  667. //
  668. // // Assign query object.
  669. // $assigned_query->the_post();
  670. //
  671. // // Assign global vars.
  672. // global $product, $post;
  673. //
  674. // // Assign total count.
  675. // $total_posts = $assigned_query->post_count;
  676. //
  677. // // Assign vars.
  678. // $this_id = get_the_ID();
  679. // $this_thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $this_id ), 'thumbnail' );
  680. // $this_title = $assigned_query->post->post_title;
  681. // $this_productlink = get_edit_post_link( $this_id );
  682. //
  683. // $wcemessage_id_onhold =
  684. // $wcemessage_id_processing =
  685. // $wcemessage_id_completed =
  686. // $wcemessage_location_onhold =
  687. // $wcemessage_location_processing =
  688. // $wcemessage_location_completed =
  689. // $wce_onhold_message_title =
  690. // $wce_onhold_message_editURL =
  691. // $wce_processing_message_title =
  692. // $wce_processing_message_editURL =
  693. // $wce_completed_message_title =
  694. // $wce_completed_message_editURL =
  695. // $this_wcemessage_id_onhold =
  696. // $this_wcemessage_id_processing =
  697. // $this_wcemessage_id_completed =
  698. // $this_orderstatus_onhold =
  699. // $this_orderstatus_processing =
  700. // $this_orderstatus_completed =
  701. // $this_location_onhold =
  702. // $this_location_processing =
  703. // $this_location_completed = '';
  704. //
  705. //
  706. // // Get WCE Message meta.
  707. // $wcemessage_id_onhold = (int) get_post_meta( $this_id, 'wcemessage_id_onhold', true );
  708. // $wcemessage_location_onhold = get_post_meta( $this_id, 'location_onhold', true );
  709. // $wcemessage_id_processing = (int) get_post_meta( $this_id, 'wcemessage_id_processing', true );
  710. // $wcemessage_location_processing = get_post_meta( $this_id, 'location_processing', true );
  711. // $wcemessage_id_completed = (int) get_post_meta( $this_id, 'wcemessage_id_completed', true );
  712. // $wcemessage_location_completed = get_post_meta( $this_id, 'location_completed', true );
  713. //
  714. // // Check for On-Hold content.
  715. // if ( $wcemessage_id_onhold > 0 ) {
  716. // $this_orderstatus_onhold = '<span class="on-hold">On Hold</span>';
  717. // $this_wcemessage_id_onhold = $wcemessage_id_onhold;
  718. // $wce_onhold_message_title = get_the_title( $this_wcemessage_id_onhold );
  719. // $wce_onhold_message_editURL = get_edit_post_link( $this_wcemessage_id_onhold );
  720. // }
  721. //
  722. // // Check for Processing content.
  723. // if ( $wcemessage_id_processing > 0 ) {
  724. // $this_orderstatus_processing = '<span class="processing">Processing</span>';
  725. // $this_wcemessage_id_processing = $wcemessage_id_processing;
  726. // $wce_processing_message_title = get_the_title( $this_wcemessage_id_processing );
  727. // $wce_processing_message_editURL = get_edit_post_link( $this_wcemessage_id_processing );
  728. // }
  729. //
  730. // // Check for Completed content.
  731. // if ( $wcemessage_id_completed > 0 ) {
  732. // $this_orderstatus_completed = '<span class="completed">Completed</span>';
  733. // $this_wcemessage_id_completed = $wcemessage_id_completed;
  734. // $wce_completed_message_title = get_the_title( $this_wcemessage_id_completed );
  735. // $wce_completed_message_editURL = get_edit_post_link( $this_wcemessage_id_completed );
  736. // }
  737. //
  738. // switch ( $wcemessage_location_onhold ) {
  739. // case 'woocommerce_email_before_order_table':
  740. // $this_location_onhold = 'Before Order Table';
  741. // break;
  742. // case 'woocommerce_email_after_order_table':
  743. // $this_location_onhold = 'After Order Table';
  744. // break;
  745. // case 'woocommerce_email_order_meta':
  746. // $this_location_onhold = 'After Order Meta';
  747. // break;
  748. // case 'woocommerce_email_customer_details':
  749. // $this_location_onhold = 'After Customer Details';
  750. // break;
  751. // }
  752. //
  753. // switch ( $wcemessage_location_processing ) {
  754. // case 'woocommerce_email_before_order_table':
  755. // $this_location_processing = 'Before Order Table';
  756. // break;
  757. // case 'woocommerce_email_after_order_table':
  758. // $this_location_processing = 'After Order Table';
  759. // break;
  760. // case 'woocommerce_email_order_meta':
  761. // $this_location_processing = 'After Order Meta';
  762. // break;
  763. // case 'woocommerce_email_customer_details':
  764. // $this_location_processing = 'After Customer Details';
  765. // break;
  766. // }
  767. //
  768. // switch ( $wcemessage_location_completed ) {
  769. // case 'woocommerce_email_before_order_table':
  770. // $this_location_completed = 'Before Order Table';
  771. // break;
  772. // case 'woocommerce_email_after_order_table':
  773. // $this_location_completed = 'After Order Table';
  774. // break;
  775. // case 'woocommerce_email_order_meta':
  776. // $this_location_completed = 'After Order Meta';
  777. // break;
  778. // case 'woocommerce_email_customer_details':
  779. // $this_location_completed = 'After Customer Details';
  780. // break;
  781. // }
  782. //
  783. // // Open table row.
  784. // $output .= '<tr class="product">';
  785. //
  786. // // Product Count column.
  787. // $output .= '<td class="product-count"> '. $count . '</td>';
  788. //
  789. // // Product Title column.
  790. // $output .= '<td class="product-title"><a href="' . $this_productlink . '" target="_blank"><img src="' . $this_thumb[0] . '" class="thumb" />' . $this_title . '</a></td>';
  791. //
  792. // // Assigned Messages column.
  793. // $output .= '<td class="assigned-message-title">';
  794. //
  795. // // ON-HOLD.
  796. // if ( $this_wcemessage_id_onhold ) {
  797. // $output .= '<div class="on-hold">';
  798. // $output .= '<a href="' . $wce_onhold_message_editURL . '" target="_blank">' . $wce_onhold_message_title . '</a>';
  799. // $output .= '</div>';
  800. // }
  801. //
  802. // // PROCESSING.
  803. // if ( $this_wcemessage_id_processing ) {
  804. // $output .= '<div class="processing">';
  805. // $output .= '<a href="' . $wce_processing_message_editURL . '" target="_blank">' . $wce_processing_message_title . '</a>';
  806. // $output .= '</div>';
  807. // }
  808. //
  809. // // COMPLETED.
  810. // if ( $this_wcemessage_id_completed ) {
  811. // $output .= '<div class="completed">';
  812. // $output .= '<a href="' . $wce_completed_message_editURL . '" target="_blank">' . $wce_completed_message_title . '</a>';
  813. // $output .= '</div>';
  814. // }
  815. //
  816. // $output .= '</td>';
  817. //
  818. // // Order Status column.
  819. // $output .= '<td class="assigned-message-orderstatus">';
  820. //
  821. // // ON-HOLD.
  822. // if ( $this_wcemessage_id_onhold ) {
  823. // $output .= '<div class="on-hold">' . $this_orderstatus_onhold . '</div>';
  824. // }
  825. //
  826. // // PROCESSING.
  827. // if ( $this_wcemessage_id_processing ) {
  828. // $output .= '<div class="processing">' . $this_orderstatus_processing . '</div>';
  829. // }
  830. //
  831. // // COMPLETED.
  832. // if ( $this_wcemessage_id_completed ) {
  833. // $output .= '<div class="completed">' . $this_orderstatus_completed . '</div>';
  834. // }
  835. //
  836. // $output .= '</td>';
  837. //
  838. // // Location column.
  839. // $output .= '<td class="assigned-message-templatelocation">';
  840. //
  841. // // $output .= $this_templatelocation;
  842. //
  843. // // ON-HOLD.
  844. // if ( $this_wcemessage_id_onhold ) {
  845. // $output .= '<div class="on-hold">' . $this_location_onhold . '</div>';
  846. // }
  847. //
  848. // // PROCESSING.
  849. // if ( $this_wcemessage_id_processing ) {
  850. // $output .= '<div class="processing">' . $this_location_processing . '</div>';
  851. // }
  852. //
  853. // // COMPLETED.
  854. // if ( $this_wcemessage_id_completed ) {
  855. // $output .= '<div class="completed">' . $this_location_completed . '</div>';
  856. // }
  857. //
  858. // $output .= '</td>';
  859. //
  860. // // Close table row.
  861. // $output .= '</tr>';
  862. //
  863. // $count++;
  864. //
  865. // }
  866. //
  867. // // Close table body.
  868. // $output .= '</tbody>';
  869. //
  870. // // Close data table.
  871. // $output .= '</table>';
  872. //
  873. // // Reset wp query.
  874. // wp_reset_postdata();
  875. // wp_reset_query();
  876. //
  877. // the_posts_pagination( array(
  878. // 'mid_size' => 1,
  879. // 'prev_text' => __('Prev', 'woo_custom_emails_domain'),
  880. // 'next_text' => __('Next', 'woo_custom_emails_domain'),
  881. // 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __('Page', 'woo_custom_emails_domain') . ' </span>',
  882. // ));
  883. //
  884. // } else {
  885. //
  886. // $output .= '<p class="alert"><b>Sorry, no Products found with assigned WCE Messages.</b></p>';
  887. //
  888. // }
  889. //
  890. // $output .= '</div><!-- // end .assigned-wce-messages // -->';
  891. //
  892. // echo $output;
  893. // ? >
  894. // </div><!-- // end .wrap // -->
  895. // <? php
  896. // }
  897. // /**
  898. // * Display the 'Add Test Data' field/button.
  899. // */
  900. // public function add_testrow_callback() {
  901. //
  902. // // Create a nonce.
  903. // wp_nonce_field('test_button_clicked');
  904. //
  905. // // Output a hidden field to track the value.
  906. // echo '<input type="hidden" value="true" name="test_button" />';
  907. //
  908. // // Output the button to perform the action.
  909. // submit_button('Add Test Data');
  910. // echo '<span class="description">' . __( 'Add a row of Test Data to the \'wcepp_messages\' db table.', 'woo_custom_emails_domain' ) . '</span>';
  911. // }
  912. // // Check whether the 'Add Test Data' button has been submitted and also check its nonce.
  913. // if ( isset( $_POST['test_button'] ) && check_admin_referer( 'test_button_clicked' ) ) {
  914. // // Run function to add Test Data.
  915. // $this->woo_custom_emails_insert_db_testrow();
  916. // }