Guest User

Untitled

a guest
Dec 11th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.31 KB | None | 0 0
  1. <?php
  2.  
  3. remove_action( 'admin_notices', 'woothemes_updater_notice' );
  4.  
  5. add_filter( 'woocommerce_create_account_default_checked', '__return_true' );
  6.  
  7. add_filter('manage_edit-shop_order_columns', 'misha_order_items_column' );
  8. function misha_order_items_column( $order_columns ) {
  9. $order_columns['order_products'] = "Detalii comanda";
  10. return $order_columns;
  11. }
  12.  
  13. add_action( 'manage_shop_order_posts_custom_column' , 'misha_order_items_column_cnt' );
  14. function misha_order_items_column_cnt( $colname ) {
  15. global $the_order; // the global order object
  16.  
  17. if( $colname == 'order_products' ) {
  18.  
  19. // get items from the order global object
  20. $order_items = $the_order->get_items();
  21.  
  22. if ( !is_wp_error( $order_items ) ) {
  23. foreach( $order_items as $order_item ) {
  24.  
  25. echo $order_item['quantity'] .'&nbsp;&times;&nbsp;<a href="' . admin_url('post.php?post=' . $order_item['product_id'] . '&action=edit' ) . '">'. $order_item['name'] .'</a><br />';
  26. // you can also use $order_item->variation_id parameter
  27. // by the way, $order_item['name'] will display variation name too
  28.  
  29. }
  30. }
  31.  
  32. }
  33.  
  34. }
  35.  
  36. add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 90 );
  37. function custom_shop_order_column( $columns )
  38. {
  39. $ordered_columns = array();
  40.  
  41. foreach( $columns as $key => $column ){
  42. $ordered_columns[$key] = $column;
  43. if( 'order_date' == $key ){
  44. $ordered_columns['order_notes'] = __( 'Notes', 'woocommerce');
  45. }
  46. }
  47.  
  48. return $ordered_columns;
  49. }
  50.  
  51. add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 1 );
  52. function custom_shop_order_list_column_content( $column )
  53. {
  54. global $post, $the_order;
  55.  
  56. $customer_note = $post->post_excerpt;
  57.  
  58. if ( $column == 'order_notes' ) {
  59.  
  60. if ( $the_order->get_customer_note() ) {
  61. echo '<span class="note-on customer tips" data-tip="' . wc_sanitize_tooltip( $the_order->get_customer_note() ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
  62. }
  63.  
  64. if ( $post->comment_count ) {
  65.  
  66. $latest_notes = wc_get_order_notes( array(
  67. 'order_id' => $post->ID,
  68. 'limit' => 1,
  69. 'orderby' => 'date_created_gmt',
  70. ) );
  71.  
  72. $latest_note = current( $latest_notes );
  73.  
  74. if ( isset( $latest_note->content ) && 1 == $post->comment_count ) {
  75. echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
  76. } elseif ( isset( $latest_note->content ) ) {
  77. // translators: %d: notes count
  78. echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content . '<br/><small style="display:block">' . sprintf( _n( 'Plus %d other note', 'Plus %d other notes', ( $post->comment_count - 1 ), 'woocommerce' ), $post->comment_count - 1 ) . '</small>' ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
  79. } else {
  80. // translators: %d: notes count
  81. echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( sprintf( _n( '%d note', '%d notes', $post->comment_count, 'woocommerce' ), $post->comment_count ) ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
  82. }
  83. }
  84. }
  85. }
  86.  
  87. // Set Here the WooCommerce icon for your action button
  88. add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
  89. function add_custom_order_status_actions_button_css() {
  90. echo '<style>
  91. td.order_notes > .note-on { display: inline-block !important;}
  92. span.note-on.customer { margin-right: 4px !important;}
  93. span.note-on.customer::after { font-family: woocommerce !important; content: "\e026" !important;}
  94. </style>';
  95. echo '<script>
  96. $( document ).ready(function() {
  97. jQuery(\'span[duplicate="yes"]\').each(function( index ) {
  98. jQuery( this ).parent().parent().css("background-color","#f6f2cf");
  99. });
  100. jQuery(\'span[cancelled="yes"]\').each(function( index ) {
  101. jQuery( this ).parent().parent().css("background-color","#ffcfcb");
  102. });
  103. });
  104. </script>';
  105.  
  106. global $ordersemailtotal;
  107. $ordersemailtotal = array();
  108. }
  109.  
  110. function my_add_to_cart_redirect() {
  111. $checkout_url = wc_get_checkout_url();
  112. return $checkout_url;
  113. }
  114. add_filter('woocommerce_add_to_cart_redirect', 'my_add_to_cart_redirect', 10, 1 );
  115.  
  116. add_filter( 'woocommerce_helper_suppress_admin_notices', '__return_true' );
  117.  
  118. add_filter( 'wc_add_to_cart_message_html', '__return_false' );
  119.  
  120.  
  121. // Style for woocommerce orders
  122.  
  123. add_action('admin_head', 'my_custom_fonts');
  124.  
  125. function my_custom_fonts() {
  126. echo '<style>
  127. .order-status.status-on-hold{
  128. background: #00a0d2!important;
  129. color: #ffffff!important;
  130. }
  131. .order-status.status-pending{
  132. color: #fff;
  133. background: #E91E63;}
  134.  
  135. .order-status.status-processing {
  136. background: #4be84b;
  137. color: #060606;
  138. }
  139.  
  140. .order-status.status-completed {
  141. background: #5cace2;
  142. color: #ffffff;}
  143.  
  144. .order-status.status-cancelled.tips {
  145. color: #fff;
  146. background: #e91e63;}
  147.  
  148. .order-status.status-refuz.tips {
  149. color: #fff;
  150. background: #e91e63;
  151. }
  152.  
  153. .order-status.status-verificare.tips{color: #000000;
  154. background: yellow;}
  155.  
  156. </style>';
  157. }
  158.  
  159. // Privacy button
  160.  
  161. add_action( 'woocommerce_review_order_after_submit', 'bbloomer_privacy_message_below_checkout_button' );
  162.  
  163. function bbloomer_privacy_message_below_checkout_button() {
  164. echo '<p style="margin-top:20px;font-style: italic;"><small>Datele personale vor fi folosite pentru a procesa comanda și pentru alte scopuri descrise în <a href="/prelucrarea-datelor-cu-caracter-personal/" target=_blank">politica de confidențialitate.</a></small></p>';
  165. }
  166.  
  167. /**
  168. * Optimize WooCommerce Scripts
  169. * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
  170. */
  171. add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99 );
  172.  
  173. function dequeue_woocommerce_styles_scripts() {
  174. if ( function_exists( 'is_woocommerce' ) ) {
  175. if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
  176. # Styles
  177. wp_dequeue_style( 'woocommerce-general' );
  178. wp_dequeue_style( 'woocommerce-layout' );
  179. wp_dequeue_style( 'woocommerce-smallscreen' );
  180. wp_dequeue_style( 'woocommerce_frontend_styles' );
  181. wp_dequeue_style( 'woocommerce_fancybox_styles' );
  182. wp_dequeue_style( 'woocommerce_chosen_styles' );
  183. wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
  184. # Scripts
  185. wp_dequeue_script( 'wc_price_slider' );
  186. wp_dequeue_script( 'wc-single-product' );
  187. wp_dequeue_script( 'wc-add-to-cart' );
  188. wp_dequeue_script( 'wc-cart-fragments' );
  189. wp_dequeue_script( 'wc-checkout' );
  190. wp_dequeue_script( 'wc-add-to-cart-variation' );
  191. wp_dequeue_script( 'wc-single-product' );
  192. wp_dequeue_script( 'wc-cart' );
  193. wp_dequeue_script( 'wc-chosen' );
  194. wp_dequeue_script( 'woocommerce' );
  195. wp_dequeue_script( 'prettyPhoto' );
  196. wp_dequeue_script( 'prettyPhoto-init' );
  197. wp_dequeue_script( 'jquery-blockui' );
  198. wp_dequeue_script( 'jquery-placeholder' );
  199. wp_dequeue_script( 'fancybox' );
  200. wp_dequeue_script( 'jqueryui' );
  201. }
  202. }
  203. }
  204.  
  205. /**
  206. * recunoaste cand is comenzi multiple
  207. */
  208.  
  209. add_action( 'woocommerce_admin_order_data_after_order_details', 'failed_orders_evd', 10, 2 );
  210. function failed_orders_evd( $order ) {
  211.  
  212. $customer_orders = get_posts( array(
  213. 'numberposts' => -1,
  214. // 'meta_key' => '_customer_user',
  215. 'meta_value' => $order->get_billing_email(),
  216. 'post_type' => 'shop_order',
  217. 'post_status' => array('wc-processing','wc-verificare'),
  218. ) );
  219.  
  220. $orders_count = '<strong style="color:red">' . count($customer_orders) . '</strong>';
  221.  
  222. echo'<p style="margin-top:190px;font-size:18px;color: black; padding: 10px!important; background: #FFEB3B;">' . __( 'Comenzi in prelucrare: ' ) . $orders_count . '</p>';
  223.  
  224. }
  225.  
  226. /**
  227.  
  228.  
  229. add_action( 'woocommerce_admin_order_data_after_order_details', 'completed_orders_evd', 10, 2 );
  230. function completed_orders_evd( $order ) {
  231.  
  232. $customer_orders = get_posts( array(
  233. 'numberposts' => -1,
  234. // 'meta_key' => '_customer_user',
  235. 'meta_value' => $order->get_billing_email(),
  236. 'post_type' => 'shop_order',
  237. 'post_status' => array('wc-completed'),
  238. ) );
  239.  
  240. $orders_count = '<strong style="color:red">' . count($customer_orders) . '</strong>';
  241.  
  242. echo'<p style="margin-top:10px;font-size:18px;color: black; padding: 10px!important; background: #8BC34A;">' . __( 'Comenzi finalizate: ' ) . $orders_count . '</p>';
  243.  
  244. }
  245.  
  246. * recunoaste cand is comenzi finalizate
  247. */
  248.  
  249. /**
  250. Adauga o extra coloana - in cazul nostru, pentru telefon
  251. */
  252. function sv_wc_cogs_add_order_profit_column_header( $columns ) {
  253.  
  254. $new_columns = array();
  255.  
  256. foreach ( $columns as $column_name => $column_info ) {
  257.  
  258. $new_columns[ $column_name ] = $column_info;
  259.  
  260. if ( 'order_total' === $column_name ) {
  261. $new_columns['order_phone'] = __( 'Telefon', 'my-textdomain' );
  262. }
  263. }
  264.  
  265. return $new_columns;
  266. }
  267. add_filter( 'manage_edit-shop_order_columns', 'sv_wc_cogs_add_order_profit_column_header', 20 );
  268.  
  269.  
  270.  
  271. /**
  272. * Adds 'Telefon' column content to 'Orders' page immediately after 'Total' column.
  273. *
  274. * @param string[] $column name of column being displayed
  275. */
  276. function sv_wc_cogs_add_order_profit_column_content( $column ) {
  277. global $post;
  278. global $wpdb;
  279.  
  280. if ( 'order_phone' === $column ) {
  281.  
  282. $email = get_post_meta($post->ID, '_billing_email', true);
  283. $phone = get_post_meta($post->ID, '_billing_phone', true);
  284. $fanStatus = get_post_meta($post->ID, 'awb_fan_status_id', true); //43 retur || 6 refuz primire
  285.  
  286. // // $order = wc_get_order( $post->ID );
  287. // // $order_data = $order->get_data(); // The Order data
  288. // // $phone = $order_data['billing']['phone'];
  289. // // $email = $order_data['billing']['email'];
  290. // // $idCustomer = $order->get_customer_id();
  291.  
  292. // echo $phone.' '.$email.' '.$fanStatus;
  293.  
  294. // $orderC = wc_get_order( $post->ID );
  295. // $order_dataC = $orderC->get_data(); // The Order data
  296. // $telefon_plata = $order_dataC['billing']['phone'];
  297. // $email = $order_datax['billing']['email'];
  298.  
  299. $order_statusesC = array('wc-cancelled','wc-refunded','wc-refuz');
  300.  
  301. // Getting current customer orders
  302. $customer_ordersC = wc_get_orders( array(
  303. 'customer' => $email,
  304. //'meta_key' => '_customer_user',
  305. //'meta_value' => $customer_user_id,
  306. 'post_status' => $order_statusesC,
  307. 'post_type' => 'shop_order',
  308. 'numberposts' => -1
  309. ) );
  310.  
  311. $noOrdersC = count($customer_ordersC);
  312.  
  313. if ( $noOrdersC > 0 ){
  314. // whoa you've got more than 10 orders
  315. echo '<span cancelled="yes">'.$phone.'</span>';
  316. } else {
  317. echo '<span cancelled="no">'.$phone.'</span>';
  318. }
  319. // break;
  320.  
  321.  
  322. //echo $phone.'<br/>';
  323.  
  324. $orderOk = 0;
  325. $orderC = 0;
  326.  
  327. //decomenteaza pentru teste
  328.  
  329. // $queryWc = new WC_Order_Query();
  330. // $queryWc->set( 'customer', $email );
  331. // $ordersWc = $queryWc->get_orders();
  332.  
  333. // foreach($ordersWc as $order) {
  334. // $order_data = $order->get_data(); // The Order data
  335. // if ($order_data['status'] === 'cancelled') {
  336. // $orderC += 1;
  337. // } else {
  338. // $orderOk += 1;
  339. // }
  340. // }
  341. // $noOrders = count($ordersWc);
  342.  
  343. // echo 'T: '.$noOrders.' OK: '.$orderOk.' X: '.$orderC. '<br/>';
  344.  
  345.  
  346. // if ($orderOk > 1 ) {
  347. // // whoa you've got more than 10 orders
  348. // echo '<span duplicate="yes">Duplicate: <strong style="color:green !important; font-size:15px !important;">'.$orderOk.'</strong></span><br/>';
  349. // } else {
  350. // echo '<span duplicate="no">Duplicate: <strong style="color:green !important; font-size:15px !important;">'.$orderOk.'</strong></span><br/>';
  351. // }
  352.  
  353. // if ($orderC > 2) {
  354. // // whoa you've got more than 10 orders
  355. // echo '<span cancelled="yes">Anulate: <strong style="color:red !important; font-size:15px !important;">'.$orderC.'</strong></span>';
  356. // } else {
  357. // echo '<span cancelled="no">Anulate: <strong style="color:red !important; font-size:15px !important;">'.$orderC.'</strong></span>';
  358. // }
  359.  
  360. //pana aici decomentezi
  361.  
  362. }
  363. }
  364. add_action( 'manage_shop_order_posts_custom_column', 'sv_wc_cogs_add_order_profit_column_content' );
  365.  
  366.  
  367. add_filter( 'manage_shop_order_posts_columns', 'set_custom_edit_post_columns',99,1 );
  368. function set_custom_edit_post_columns($columns) {
  369. $columns['orders_no'] = __( 'No.', 'your_text_domain' );
  370. return $columns;
  371. }
  372. add_action( 'manage_shop_order_posts_custom_column' , 'custom_cpost_column', 99, 2 );
  373. function custom_cpost_column( $column, $post_id ) {
  374. global $ordersemailtotal;
  375. $number_of_orders = 1;
  376.  
  377. switch ( $column ) {
  378.  
  379. case 'orders_no'://new-title=your column slug :
  380.  
  381. $orderx = wc_get_order( $post_id );
  382. $order_datax = $orderx->get_data(); // The Order data
  383. $telefon_plata = $order_datax['billing']['phone'];
  384. $email = $order_datax['billing']['email'];
  385. $order_statuses = array('wc-on-hold', 'wc-pending', 'wc-processing', 'wc-verificare');
  386. //$order_statuses = array('wc-on-hold', 'wc-pending', 'wc-processing', 'wc-verificare', 'wc-completed');
  387. $current_time = strtotime("now");
  388. $old_time = strtotime("-2 weeks");
  389.  
  390. //$order_statuses = wc_get_order_statuses();
  391.  
  392. // Getting current customer orders
  393. $customer_orders = wc_get_orders( array(
  394. 'customer' => $email,
  395. //'meta_key' => '_customer_user',
  396. //'meta_value' => $customer_user_id,
  397. 'post_status' => $order_statuses,
  398. 'post_type' => 'shop_order',
  399. 'numberposts' => -1,
  400. // 'date_created' => ''.$old_time.'...'.$current_time.''
  401. // 'date_created' => '<' . $old_time,
  402.  
  403. ) );
  404.  
  405. $noOrders = count($customer_orders);
  406.  
  407. //echo $noOrders;
  408.  
  409. if ( $noOrders > $number_of_orders ){
  410. // whoa you've got more than 10 orders
  411. echo '<span duplicate="yes">'.$noOrders.'</span>';
  412. } else {
  413. echo '<span duplicate="no">'.$noOrders.'</span>';
  414. }
  415. break;
  416. }
  417. }
  418.  
  419.  
  420. /**
  421. * Adjusts the styles for the new 'Telefon' column.
  422. */
  423. function sv_wc_cogs_add_order_profit_column_style() {
  424.  
  425. //$css = '.widefat .column-order_phone { width: 4%!important;white-space: pre-wrap;word-wrap: break-word; }';
  426. $cssDate = '.widefat .column-order_date, .widefat .column-order_phone {width: 5%!important;';
  427. wp_add_inline_style( 'woocommerce_admin_styles', $cssDate );
  428. }
  429. //add_action( 'admin_print_styles', 'sv_wc_cogs_add_order_profit_column_style' );
  430.  
  431.  
  432. /**
  433. * Register new status refuz & verificare
  434. **/
  435. function register_new_orders_status() {
  436. register_post_status( 'wc-refuz', array(
  437. 'label' => 'Refuz comanda',
  438. 'public' => true,
  439. 'exclude_from_search' => false,
  440. 'show_in_admin_all_list' => true,
  441. 'show_in_admin_status_list' => true,
  442. 'label_count' => _n_noop( 'Refuzată <span class="count">(%s)</span>', 'Refuzate <span class="count">(%s)</span>' )
  443. ) );
  444. register_post_status( 'wc-verificare', array(
  445. 'label' => 'Necesita verificare',
  446. 'public' => true,
  447. 'exclude_from_search' => false,
  448. 'show_in_admin_all_list' => true,
  449. 'show_in_admin_status_list' => true,
  450. 'label_count' => _n_noop( 'Necesita verificare <span class="count">(%s)</span>', 'Necesita verificare <span class="count">(%s)</span>' )
  451. ) );
  452. }
  453. add_action( 'init', 'register_new_orders_status' );
  454. // Add to list of WC Order statuses
  455. function add_new_orders_to_order_statuses( $order_statuses ) {
  456. $new_order_statuses = array();
  457. // add new order status after processing
  458. foreach ( $order_statuses as $key => $status ) {
  459. $new_order_statuses[ $key ] = $status;
  460. if ( 'wc-processing' === $key ) {
  461. $new_order_statuses['wc-refuz'] = 'Refuzata';
  462. $new_order_statuses['wc-verificare'] = 'Necesita verificare';
  463. }
  464. }
  465. return $new_order_statuses;
  466. }
  467. add_filter( 'wc_order_statuses', 'add_new_orders_to_order_statuses' );
  468.  
  469.  
  470. function rename_or_reorder_bulk_actions( $actions ) {
  471. $actions['mark_refuz'] = __( 'Schimbă starea la refuzată', 'textdomain' );
  472. $actions['mark_verificare'] = __( 'Schimbă starea la necesită verificare', 'textdomain' );
  473. return $actions;
  474. }
  475. add_filter( 'bulk_actions-edit-shop_order', 'rename_or_reorder_bulk_actions', 20 );
  476.  
  477. add_action('woocommerce_checkout_process', 'check_phone_number_length');
  478. function check_phone_number_length() {
  479. global $woocommerce;
  480. if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['billing_phone'] ))){
  481. wc_add_notice( "<strong>Telefon</strong> Număr incorect ! Trebuie să conțină 10 cifre" ,'error' );
  482. }
  483. }
Add Comment
Please, Sign In to add comment