Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Robimy pole Telefon wymaganym
- */
- add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
- function wc_npr_filter_phone( $address_fields ) {
- $address_fields['billing_phone']['required'] = true;
- return $address_fields;
- }
- /**
- * Wyłączamy długość hasła
- */
- function wc_ninja_remove_password_strength() {
- if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
- wp_dequeue_script( 'wc-password-strength-meter' );
- }
- }
- add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 );
- /**
- * WPML support. Converts the raw price in the default currency into the selected currency.
- * https://wpml.org/wcml-hook/wcml_raw_price_amount/
- */
- function vpc_selected_currency_price( $price ) {
- return apply_filters( 'wcml_raw_price_amount', $price );
- }
- add_filter( 'vpc_options_price', 'vpc_selected_currency_price' );
- /*zmiana nazwy statusu Processing na Payment accepted*/
- function wc_renaming_order_status( $order_statuses ) {
- foreach ( $order_statuses as $key => $status ) {
- $new_order_statuses[ $key ] = $status;
- if ( 'wc-processing' === $key ) {
- $order_statuses['wc-processing'] = _x( 'Payment accepted', 'Order status', 'woocommerce' );
- }
- }
- return $order_statuses;
- }
- add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
- // Rename order status 'Completed' to 'Order Received' in admin main view - different hook, different value than the other places
- function wc_rename_order_status_type( $order_statuses ) {
- foreach ( $order_statuses as $key => $status ) {
- $new_order_statuses[ $key ] = $status;
- if ( 'wc-processing' === $key ) {
- $order_statuses['wc-processing']['label_count'] = _n_noop( 'Payment accepted <span class="count">(%s)</span>', 'Payment accepted <span class="count">(%s)</span>', 'woocommerce' );
- }
- }
- return $order_statuses;
- }
- add_filter( 'woocommerce_register_shop_order_post_statuses', 'wc_rename_order_status_type' );
- // Rename order status in the bulk actions dropdown on main order list
- function rename_bulk_status( $translated_text, $untranslated_text, $domain ) {
- if( is_admin()) {
- if( $untranslated_text == 'Mark processing' )
- $translated_text = __( 'Change Status To Payment accepted','woocommerce' );
- }
- return $translated_text;
- }
- add_filter('gettext', 'rename_bulk_status', 20, 3);
- /**
- * Snippet To convert special Characters
- */
- add_filter( 'wf_fedex_request', 'xa_fedex_escape_charecters', 10, 2 );
- if( ! function_exists('xa_fedex_escape_charecters') ) {
- function xa_fedex_escape_charecters($request) {
- $polish = array('ę', 'Ę', 'ó', 'Ó', 'ą', 'Ą', 'ś', 'Ś', 'ł', 'Ł', 'ż', 'Ż', 'ź', 'Ź', 'ć', 'Ć', 'ń', 'Ń','ś', 'Ś');
- $polish_replace = array('e', 'E', 'o', 'O', 'a', 'A', 's', 'S', 'l', 'L', 'z', 'Z', 'z', 'Z', 'c', 'C', 'n', 'N','s', 'S');
- $german = array('ä', 'Ä', 'ö', 'Ö', 'ü', 'Ü', 'ß');
- $german_replace = array('a', 'A', 'o', 'O', 'u', 'U', 'ss');
- $spanish = array('á', 'Á', 'ó', 'Ó', 'é', 'É', 'í', 'Í', 'ú', 'Ú', 'ü', 'Ü', 'ñ', 'Ñ');
- $spanish_array = array('a', 'A', 'o', 'O', 'e', 'E', 'i', 'I', 'u', 'U', 'u', 'U', 'n', 'N');
- $name = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Contact']['PersonName']);
- $name = str_replace( $german, $german_replace, $name);
- $name = str_replace( $spanish, $spanish_array, $name);
- $company = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Contact']['CompanyName']);
- $company = str_replace( $german, $german_replace, $company);
- $company = str_replace( $spanish, $spanish_array, $company);
- $street1 = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['StreetLines'][0]);
- $street1 = str_replace( $german, $german_replace, $street1);
- $street1 = str_replace( $spanish, $spanish_array, $street1);
- $street2 = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['StreetLines'][1]);
- $street2 = str_replace( $german, $german_replace, $street2);
- $street2 = str_replace( $spanish, $spanish_array, $street2);
- $city = str_replace( $polish, $polish_replace, $request['RequestedShipment']['Recipient']['Address']['City']);
- $city = str_replace( $german, $german_replace, $city);
- $city = str_replace( $spanish, $spanish_array, $city);
- $request['RequestedShipment']['Recipient']['Contact']['PersonName'] = $name;
- $request['RequestedShipment']['Recipient']['Contact']['CompanyName'] = $company;
- $request['RequestedShipment']['Recipient']['Address']['StreetLines'][0] = $street1;
- $request['RequestedShipment']['Recipient']['Address']['StreetLines'][1] = $street2;
- $request['RequestedShipment']['Recipient']['Address']['City'] = $city;
- return $request;
- }
- }
- //Export Fedex
- add_filter('hf_alter_csv_order_data','hf_alter_csv_order_data',10,4);
- function hf_alter_csv_order_data($order_data, $export_columns, $user_columns_name, $max_line_items){
- $order = wc_get_order($order_data['order_id']);
- $fedex_data =$order->get_meta('wf_fedex_shipment_source');
- if($fedex_data)
- { $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']; }
- return $order_data;
- }
- /**
- * @snippet Get Total Sales by COUPON
- * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
- * @sourcecode https://businessbloomer.com/?p=72576
- * @author Rodolfo Melogli
- * @testedwith WooCommerce 3.0.7
- */
- // -------------------------
- // 1. Create function that calculates sales based on coupon code
- function bbloomer_get_sales_by_coupon($coupon_id) {
- $args = [
- 'post_type' => 'shop_order',
- 'posts_per_page' => '-1',
- 'post_status' => ['wc-processing', 'wc-completed', 'wc-on-hold']
- ];
- $my_query = new WP_Query($args);
- $orders = $my_query->posts;
- $total = 0;
- foreach ($orders as $key => $value) {
- $order_id = $value->ID;
- $order = wc_get_order($order_id);
- $items = $order->get_items('coupon');
- foreach ( $items as $item ) {
- if( $item['code'] == $coupon_id ) {
- $total += $order->get_total();
- }
- }
- }
- return 'Total sales for coupon "' . $coupon_id . '": ' . wc_price($total);
- }
- // -------------------------
- // 2. Add new tab to WooCommerce "Reports", and print the coupon total sales
- add_filter( 'woocommerce_admin_reports', 'bbloomer_add_report_tab' );
- function bbloomer_add_report_tab( $reports ) {
- $reports['coupons'] = array(
- 'title' => __( 'Coupons', 'woocommerce' ),
- 'reports' => array(
- "sales_by_code" => array(
- 'title' => __( 'Sales by code', 'woocommerce' ),
- 'description' => bbloomer_get_sales_by_coupon('barmada'), //change coupon code here
- 'hide_title' => false,
- 'callback' => '',
- ),
- ),
- );
- return $reports;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement