Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. <?php
  2. /**
  3. * Robimy pole Telefon wymaganym
  4. */
  5.  
  6. add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
  7.  
  8. function wc_npr_filter_phone( $address_fields ) {
  9. $address_fields['billing_phone']['required'] = true;
  10. return $address_fields;
  11.  
  12.  
  13. }
  14.  
  15. /**
  16. * Wyłączamy długość hasła
  17. */
  18. function wc_ninja_remove_password_strength() {
  19. if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
  20. wp_dequeue_script( 'wc-password-strength-meter' );
  21. }
  22. }
  23. add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );
  24.  
  25. /**
  26. * WPML support. Converts the raw price in the default currency into the selected currency.
  27. * https://wpml.org/wcml-hook/wcml_raw_price_amount/
  28. */
  29. function vpc_selected_currency_price( $price ) {
  30. return apply_filters( 'wcml_raw_price_amount', $price );
  31. }
  32. add_filter( 'vpc_options_price', 'vpc_selected_currency_price' );
  33.  
  34.  
  35. /*zmiana nazwy statusu Processing na Payment accepted*/
  36.  
  37. function wc_renaming_order_status( $order_statuses ) {
  38. foreach ( $order_statuses as $key => $status ) {
  39. $new_order_statuses[ $key ] = $status;
  40. if ( 'wc-processing' === $key ) {
  41. $order_statuses['wc-processing'] = _x( 'Payment accepted', 'Order status', 'woocommerce' );
  42. }
  43. }
  44. return $order_statuses;
  45. }
  46. add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
  47.  
  48.  
  49. // Rename order status 'Completed' to 'Order Received' in admin main view - different hook, different value than the other places
  50. function wc_rename_order_status_type( $order_statuses ) {
  51. foreach ( $order_statuses as $key => $status ) {
  52. $new_order_statuses[ $key ] = $status;
  53. if ( 'wc-processing' === $key ) {
  54. $order_statuses['wc-processing']['label_count'] = _n_noop( 'Payment accepted <span class="count">(%s)</span>', 'Payment accepted <span class="count">(%s)</span>', 'woocommerce' );
  55. }
  56. }
  57. return $order_statuses;
  58. }
  59. add_filter( 'woocommerce_register_shop_order_post_statuses', 'wc_rename_order_status_type' );
  60.  
  61.  
  62. // Rename order status in the bulk actions dropdown on main order list
  63. function rename_bulk_status( $translated_text, $untranslated_text, $domain ) {
  64. if( is_admin()) {
  65. if( $untranslated_text == 'Mark processing' )
  66. $translated_text = __( 'Change Status To Payment accepted','woocommerce' );
  67. }
  68. return $translated_text;
  69. }
  70.  
  71. add_filter('gettext', 'rename_bulk_status', 20, 3);
  72.  
  73.  
  74. /**
  75. * Snippet To convert special Characters
  76. */
  77. add_filter( 'wf_fedex_request', 'xa_fedex_escape_charecters', 10, 2 );
  78. if( ! function_exists('xa_fedex_escape_charecters') ) {
  79. function xa_fedex_escape_charecters($request) {
  80. $polish = array('ę', 'Ę', 'ó', 'Ó', 'ą', 'Ą', 'ś', 'Ś', 'ł', 'Ł', 'ż', 'Ż', 'ź', 'Ź', 'ć', 'Ć', 'ń', 'Ń','ś', 'Ś');
  81. $polish_replace = array('e', 'E', 'o', 'O', 'a', 'A', 's', 'S', 'l', 'L', 'z', 'Z', 'z', 'Z', 'c', 'C', 'n', 'N','s', 'S');
  82. $german = array('ä', 'Ä', 'ö', 'Ö', 'ü', 'Ü', 'ß');
  83. $german_replace = array('a', 'A', 'o', 'O', 'u', 'U', 'ss');
  84. $spanish = array('á', 'Á', 'ó', 'Ó', 'é', 'É', 'í', 'Í', 'ú', 'Ú', 'ü', 'Ü', 'ñ', 'Ñ');
  85. $spanish_array = array('a', 'A', 'o', 'O', 'e', 'E', 'i', 'I', 'u', 'U', 'u', 'U', 'n', 'N');
  86.  
  87. $name = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Contact']['PersonName']);
  88. $name = str_replace( $german, $german_replace, $name);
  89. $name = str_replace( $spanish, $spanish_array, $name);
  90.  
  91. $company = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Contact']['CompanyName']);
  92. $company = str_replace( $german, $german_replace, $company);
  93. $company = str_replace( $spanish, $spanish_array, $company);
  94.  
  95. $street1 = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['StreetLines'][0]);
  96. $street1 = str_replace( $german, $german_replace, $street1);
  97. $street1 = str_replace( $spanish, $spanish_array, $street1);
  98. $street2 = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['StreetLines'][1]);
  99. $street2 = str_replace( $german, $german_replace, $street2);
  100. $street2 = str_replace( $spanish, $spanish_array, $street2);
  101.  
  102. $city = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['City']);
  103. $city = str_replace( $german, $german_replace, $city);
  104. $city = str_replace( $spanish, $spanish_array, $city);
  105.  
  106. $request['RequestedShipment']['Recipient']['Contact']['PersonName'] = $name;
  107. $request['RequestedShipment']['Recipient']['Contact']['CompanyName'] = $company;
  108. $request['RequestedShipment']['Recipient']['Address']['StreetLines'][0] = $street1;
  109. $request['RequestedShipment']['Recipient']['Address']['StreetLines'][1] = $street2;
  110. $request['RequestedShipment']['Recipient']['Address']['City'] = $city;
  111. return $request;
  112. }
  113. }
  114.  
  115. //Export Fedex
  116.  
  117. add_filter('hf_alter_csv_order_data','hf_alter_csv_order_data',10,4);
  118. function hf_alter_csv_order_data($order_data, $export_columns, $user_columns_name, $max_line_items){
  119. $order = wc_get_order($order_data['order_id']);
  120. $fedex_data =$order->get_meta('wf_fedex_shipment_source');
  121. if($fedex_data)
  122. { $order_data['fedex_shipping_service'] = $fedex_data['shipping_service']; $order_data['fedex_shipment_id_cs'] = $fedex_data['shipment_id_cs']; $order_data['fedex_order_date'] = $fedex_data['order_date']; }
  123. return $order_data;
  124. }
  125. /**
  126. * @snippet Get Total Sales by COUPON
  127. * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
  128. * @sourcecode https://businessbloomer.com/?p=72576
  129. * @author Rodolfo Melogli
  130. * @testedwith WooCommerce 3.0.7
  131. */
  132.  
  133. // -------------------------
  134. // 1. Create function that calculates sales based on coupon code
  135.  
  136. function bbloomer_get_sales_by_coupon($coupon_id) {
  137.  
  138. $args = [
  139. 'post_type' => 'shop_order',
  140. 'posts_per_page' => '-1',
  141. 'post_status' => ['wc-processing', 'wc-completed', 'wc-on-hold']
  142. ];
  143. $my_query = new WP_Query($args);
  144. $orders = $my_query->posts;
  145.  
  146. $total = 0;
  147.  
  148. foreach ($orders as $key => $value) {
  149.  
  150. $order_id = $value->ID;
  151. $order = wc_get_order($order_id);
  152. $items = $order->get_items('coupon');
  153.  
  154. foreach ( $items as $item ) {
  155.  
  156. if( $item['code'] == $coupon_id ) {
  157. $total += $order->get_total();
  158. }
  159.  
  160. }
  161.  
  162. }
  163. return 'Total sales for coupon "' . $coupon_id . '": ' . wc_price($total);
  164. }
  165.  
  166. // -------------------------
  167. // 2. Add new tab to WooCommerce "Reports", and print the coupon total sales
  168.  
  169. add_filter( 'woocommerce_admin_reports', 'bbloomer_add_report_tab' );
  170.  
  171. function bbloomer_add_report_tab( $reports ) {
  172.  
  173. $reports['coupons'] = array(
  174. 'title' => __( 'Coupons', 'woocommerce' ),
  175. 'reports' => array(
  176. "sales_by_code" => array(
  177. 'title' => __( 'Sales by code', 'woocommerce' ),
  178. 'description' => bbloomer_get_sales_by_coupon('barmada'), //change coupon code here
  179. 'hide_title' => false,
  180. 'callback' => '',
  181. ),
  182. ),
  183. );
  184.  
  185. return $reports;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement