Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- remove_action( 'admin_notices', 'woothemes_updater_notice' );
- add_filter( 'woocommerce_create_account_default_checked', '__return_true' );
- add_filter('manage_edit-shop_order_columns', 'misha_order_items_column' );
- function misha_order_items_column( $order_columns ) {
- $order_columns['order_products'] = "Detalii comanda";
- return $order_columns;
- }
- add_action( 'manage_shop_order_posts_custom_column' , 'misha_order_items_column_cnt' );
- function misha_order_items_column_cnt( $colname ) {
- global $the_order; // the global order object
- if( $colname == 'order_products' ) {
- // get items from the order global object
- $order_items = $the_order->get_items();
- if ( !is_wp_error( $order_items ) ) {
- foreach( $order_items as $order_item ) {
- echo $order_item['quantity'] .' × <a href="' . admin_url('post.php?post=' . $order_item['product_id'] . '&action=edit' ) . '">'. $order_item['name'] .'</a><br />';
- // you can also use $order_item->variation_id parameter
- // by the way, $order_item['name'] will display variation name too
- }
- }
- }
- }
- add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column', 90 );
- function custom_shop_order_column( $columns )
- {
- $ordered_columns = array();
- foreach( $columns as $key => $column ){
- $ordered_columns[$key] = $column;
- if( 'order_date' == $key ){
- $ordered_columns['order_notes'] = __( 'Notes', 'woocommerce');
- }
- }
- return $ordered_columns;
- }
- add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_list_column_content', 10, 1 );
- function custom_shop_order_list_column_content( $column )
- {
- global $post, $the_order;
- $customer_note = $post->post_excerpt;
- if ( $column == 'order_notes' ) {
- if ( $the_order->get_customer_note() ) {
- echo '<span class="note-on customer tips" data-tip="' . wc_sanitize_tooltip( $the_order->get_customer_note() ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- }
- if ( $post->comment_count ) {
- $latest_notes = wc_get_order_notes( array(
- 'order_id' => $post->ID,
- 'limit' => 1,
- 'orderby' => 'date_created_gmt',
- ) );
- $latest_note = current( $latest_notes );
- if ( isset( $latest_note->content ) && 1 == $post->comment_count ) {
- echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $latest_note->content ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
- } elseif ( isset( $latest_note->content ) ) {
- // translators: %d: notes count
- 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>';
- } else {
- // translators: %d: notes count
- 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>';
- }
- }
- }
- }
- // Set Here the WooCommerce icon for your action button
- add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
- function add_custom_order_status_actions_button_css() {
- echo '<style>
- td.order_notes > .note-on { display: inline-block !important;}
- span.note-on.customer { margin-right: 4px !important;}
- span.note-on.customer::after { font-family: woocommerce !important; content: "\e026" !important;}
- </style>';
- echo '<script>
- $( document ).ready(function() {
- jQuery(\'span[duplicate="yes"]\').each(function( index ) {
- jQuery( this ).parent().parent().css("background-color","#f6f2cf");
- });
- jQuery(\'span[cancelled="yes"]\').each(function( index ) {
- jQuery( this ).parent().parent().css("background-color","#ffcfcb");
- });
- });
- </script>';
- global $ordersemailtotal;
- $ordersemailtotal = array();
- }
- function my_add_to_cart_redirect() {
- $checkout_url = wc_get_checkout_url();
- return $checkout_url;
- }
- add_filter('woocommerce_add_to_cart_redirect', 'my_add_to_cart_redirect', 10, 1 );
- add_filter( 'woocommerce_helper_suppress_admin_notices', '__return_true' );
- add_filter( 'wc_add_to_cart_message_html', '__return_false' );
- // Style for woocommerce orders
- add_action('admin_head', 'my_custom_fonts');
- function my_custom_fonts() {
- echo '<style>
- .order-status.status-on-hold{
- background: #00a0d2!important;
- color: #ffffff!important;
- }
- .order-status.status-pending{
- color: #fff;
- background: #E91E63;}
- .order-status.status-processing {
- background: #4be84b;
- color: #060606;
- }
- .order-status.status-completed {
- background: #5cace2;
- color: #ffffff;}
- .order-status.status-cancelled.tips {
- color: #fff;
- background: #e91e63;}
- .order-status.status-refuz.tips {
- color: #fff;
- background: #e91e63;
- }
- .order-status.status-verificare.tips{color: #000000;
- background: yellow;}
- </style>';
- }
- // Privacy button
- add_action( 'woocommerce_review_order_after_submit', 'bbloomer_privacy_message_below_checkout_button' );
- function bbloomer_privacy_message_below_checkout_button() {
- 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>';
- }
- /**
- * Optimize WooCommerce Scripts
- * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
- */
- add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_styles_scripts', 99 );
- function dequeue_woocommerce_styles_scripts() {
- if ( function_exists( 'is_woocommerce' ) ) {
- if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
- # Styles
- wp_dequeue_style( 'woocommerce-general' );
- wp_dequeue_style( 'woocommerce-layout' );
- wp_dequeue_style( 'woocommerce-smallscreen' );
- wp_dequeue_style( 'woocommerce_frontend_styles' );
- wp_dequeue_style( 'woocommerce_fancybox_styles' );
- wp_dequeue_style( 'woocommerce_chosen_styles' );
- wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
- # Scripts
- wp_dequeue_script( 'wc_price_slider' );
- wp_dequeue_script( 'wc-single-product' );
- wp_dequeue_script( 'wc-add-to-cart' );
- wp_dequeue_script( 'wc-cart-fragments' );
- wp_dequeue_script( 'wc-checkout' );
- wp_dequeue_script( 'wc-add-to-cart-variation' );
- wp_dequeue_script( 'wc-single-product' );
- wp_dequeue_script( 'wc-cart' );
- wp_dequeue_script( 'wc-chosen' );
- wp_dequeue_script( 'woocommerce' );
- wp_dequeue_script( 'prettyPhoto' );
- wp_dequeue_script( 'prettyPhoto-init' );
- wp_dequeue_script( 'jquery-blockui' );
- wp_dequeue_script( 'jquery-placeholder' );
- wp_dequeue_script( 'fancybox' );
- wp_dequeue_script( 'jqueryui' );
- }
- }
- }
- /**
- * recunoaste cand is comenzi multiple
- */
- add_action( 'woocommerce_admin_order_data_after_order_details', 'failed_orders_evd', 10, 2 );
- function failed_orders_evd( $order ) {
- $customer_orders = get_posts( array(
- 'numberposts' => -1,
- // 'meta_key' => '_customer_user',
- 'meta_value' => $order->get_billing_email(),
- 'post_type' => 'shop_order',
- 'post_status' => array('wc-processing','wc-verificare'),
- ) );
- $orders_count = '<strong style="color:red">' . count($customer_orders) . '</strong>';
- echo'<p style="margin-top:190px;font-size:18px;color: black; padding: 10px!important; background: #FFEB3B;">' . __( 'Comenzi in prelucrare: ' ) . $orders_count . '</p>';
- }
- /**
- add_action( 'woocommerce_admin_order_data_after_order_details', 'completed_orders_evd', 10, 2 );
- function completed_orders_evd( $order ) {
- $customer_orders = get_posts( array(
- 'numberposts' => -1,
- // 'meta_key' => '_customer_user',
- 'meta_value' => $order->get_billing_email(),
- 'post_type' => 'shop_order',
- 'post_status' => array('wc-completed'),
- ) );
- $orders_count = '<strong style="color:red">' . count($customer_orders) . '</strong>';
- echo'<p style="margin-top:10px;font-size:18px;color: black; padding: 10px!important; background: #8BC34A;">' . __( 'Comenzi finalizate: ' ) . $orders_count . '</p>';
- }
- * recunoaste cand is comenzi finalizate
- */
- /**
- Adauga o extra coloana - in cazul nostru, pentru telefon
- */
- function sv_wc_cogs_add_order_profit_column_header( $columns ) {
- $new_columns = array();
- foreach ( $columns as $column_name => $column_info ) {
- $new_columns[ $column_name ] = $column_info;
- if ( 'order_total' === $column_name ) {
- $new_columns['order_phone'] = __( 'Telefon', 'my-textdomain' );
- }
- }
- return $new_columns;
- }
- add_filter( 'manage_edit-shop_order_columns', 'sv_wc_cogs_add_order_profit_column_header', 20 );
- /**
- * Adds 'Telefon' column content to 'Orders' page immediately after 'Total' column.
- *
- * @param string[] $column name of column being displayed
- */
- function sv_wc_cogs_add_order_profit_column_content( $column ) {
- global $post;
- global $wpdb;
- if ( 'order_phone' === $column ) {
- $email = get_post_meta($post->ID, '_billing_email', true);
- $phone = get_post_meta($post->ID, '_billing_phone', true);
- $fanStatus = get_post_meta($post->ID, 'awb_fan_status_id', true); //43 retur || 6 refuz primire
- // // $order = wc_get_order( $post->ID );
- // // $order_data = $order->get_data(); // The Order data
- // // $phone = $order_data['billing']['phone'];
- // // $email = $order_data['billing']['email'];
- // // $idCustomer = $order->get_customer_id();
- // echo $phone.' '.$email.' '.$fanStatus;
- // $orderC = wc_get_order( $post->ID );
- // $order_dataC = $orderC->get_data(); // The Order data
- // $telefon_plata = $order_dataC['billing']['phone'];
- // $email = $order_datax['billing']['email'];
- $order_statusesC = array('wc-cancelled','wc-refunded','wc-refuz');
- // Getting current customer orders
- $customer_ordersC = wc_get_orders( array(
- 'customer' => $email,
- //'meta_key' => '_customer_user',
- //'meta_value' => $customer_user_id,
- 'post_status' => $order_statusesC,
- 'post_type' => 'shop_order',
- 'numberposts' => -1
- ) );
- $noOrdersC = count($customer_ordersC);
- if ( $noOrdersC > 0 ){
- // whoa you've got more than 10 orders
- echo '<span cancelled="yes">'.$phone.'</span>';
- } else {
- echo '<span cancelled="no">'.$phone.'</span>';
- }
- // break;
- //echo $phone.'<br/>';
- $orderOk = 0;
- $orderC = 0;
- //decomenteaza pentru teste
- // $queryWc = new WC_Order_Query();
- // $queryWc->set( 'customer', $email );
- // $ordersWc = $queryWc->get_orders();
- // foreach($ordersWc as $order) {
- // $order_data = $order->get_data(); // The Order data
- // if ($order_data['status'] === 'cancelled') {
- // $orderC += 1;
- // } else {
- // $orderOk += 1;
- // }
- // }
- // $noOrders = count($ordersWc);
- // echo 'T: '.$noOrders.' OK: '.$orderOk.' X: '.$orderC. '<br/>';
- // if ($orderOk > 1 ) {
- // // whoa you've got more than 10 orders
- // echo '<span duplicate="yes">Duplicate: <strong style="color:green !important; font-size:15px !important;">'.$orderOk.'</strong></span><br/>';
- // } else {
- // echo '<span duplicate="no">Duplicate: <strong style="color:green !important; font-size:15px !important;">'.$orderOk.'</strong></span><br/>';
- // }
- // if ($orderC > 2) {
- // // whoa you've got more than 10 orders
- // echo '<span cancelled="yes">Anulate: <strong style="color:red !important; font-size:15px !important;">'.$orderC.'</strong></span>';
- // } else {
- // echo '<span cancelled="no">Anulate: <strong style="color:red !important; font-size:15px !important;">'.$orderC.'</strong></span>';
- // }
- //pana aici decomentezi
- }
- }
- add_action( 'manage_shop_order_posts_custom_column', 'sv_wc_cogs_add_order_profit_column_content' );
- add_filter( 'manage_shop_order_posts_columns', 'set_custom_edit_post_columns',99,1 );
- function set_custom_edit_post_columns($columns) {
- $columns['orders_no'] = __( 'No.', 'your_text_domain' );
- return $columns;
- }
- add_action( 'manage_shop_order_posts_custom_column' , 'custom_cpost_column', 99, 2 );
- function custom_cpost_column( $column, $post_id ) {
- global $ordersemailtotal;
- $number_of_orders = 1;
- switch ( $column ) {
- case 'orders_no'://new-title=your column slug :
- $orderx = wc_get_order( $post_id );
- $order_datax = $orderx->get_data(); // The Order data
- $telefon_plata = $order_datax['billing']['phone'];
- $email = $order_datax['billing']['email'];
- $order_statuses = array('wc-on-hold', 'wc-pending', 'wc-processing', 'wc-verificare');
- //$order_statuses = array('wc-on-hold', 'wc-pending', 'wc-processing', 'wc-verificare', 'wc-completed');
- $current_time = strtotime("now");
- $old_time = strtotime("-2 weeks");
- //$order_statuses = wc_get_order_statuses();
- // Getting current customer orders
- $customer_orders = wc_get_orders( array(
- 'customer' => $email,
- //'meta_key' => '_customer_user',
- //'meta_value' => $customer_user_id,
- 'post_status' => $order_statuses,
- 'post_type' => 'shop_order',
- 'numberposts' => -1,
- // 'date_created' => ''.$old_time.'...'.$current_time.''
- // 'date_created' => '<' . $old_time,
- ) );
- $noOrders = count($customer_orders);
- //echo $noOrders;
- if ( $noOrders > $number_of_orders ){
- // whoa you've got more than 10 orders
- echo '<span duplicate="yes">'.$noOrders.'</span>';
- } else {
- echo '<span duplicate="no">'.$noOrders.'</span>';
- }
- break;
- }
- }
- /**
- * Adjusts the styles for the new 'Telefon' column.
- */
- function sv_wc_cogs_add_order_profit_column_style() {
- //$css = '.widefat .column-order_phone { width: 4%!important;white-space: pre-wrap;word-wrap: break-word; }';
- $cssDate = '.widefat .column-order_date, .widefat .column-order_phone {width: 5%!important;';
- wp_add_inline_style( 'woocommerce_admin_styles', $cssDate );
- }
- //add_action( 'admin_print_styles', 'sv_wc_cogs_add_order_profit_column_style' );
- /**
- * Register new status refuz & verificare
- **/
- function register_new_orders_status() {
- register_post_status( 'wc-refuz', array(
- 'label' => 'Refuz comanda',
- 'public' => true,
- 'exclude_from_search' => false,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'label_count' => _n_noop( 'Refuzată <span class="count">(%s)</span>', 'Refuzate <span class="count">(%s)</span>' )
- ) );
- register_post_status( 'wc-verificare', array(
- 'label' => 'Necesita verificare',
- 'public' => true,
- 'exclude_from_search' => false,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- 'label_count' => _n_noop( 'Necesita verificare <span class="count">(%s)</span>', 'Necesita verificare <span class="count">(%s)</span>' )
- ) );
- }
- add_action( 'init', 'register_new_orders_status' );
- // Add to list of WC Order statuses
- function add_new_orders_to_order_statuses( $order_statuses ) {
- $new_order_statuses = array();
- // add new order status after processing
- foreach ( $order_statuses as $key => $status ) {
- $new_order_statuses[ $key ] = $status;
- if ( 'wc-processing' === $key ) {
- $new_order_statuses['wc-refuz'] = 'Refuzata';
- $new_order_statuses['wc-verificare'] = 'Necesita verificare';
- }
- }
- return $new_order_statuses;
- }
- add_filter( 'wc_order_statuses', 'add_new_orders_to_order_statuses' );
- function rename_or_reorder_bulk_actions( $actions ) {
- $actions['mark_refuz'] = __( 'Schimbă starea la refuzată', 'textdomain' );
- $actions['mark_verificare'] = __( 'Schimbă starea la necesită verificare', 'textdomain' );
- return $actions;
- }
- add_filter( 'bulk_actions-edit-shop_order', 'rename_or_reorder_bulk_actions', 20 );
- add_action('woocommerce_checkout_process', 'check_phone_number_length');
- function check_phone_number_length() {
- global $woocommerce;
- if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['billing_phone'] ))){
- wc_add_notice( "<strong>Telefon</strong> Număr incorect ! Trebuie să conțină 10 cifre" ,'error' );
- }
- }
Add Comment
Please, Sign In to add comment