Booster for WooCommerce - Version 2.1.1

Version Description

  • 18/02/2015 =
  • Orders Shortcodes - Shortcodes compatibility with PDF Invoices v1 module.
  • Orders Shortcodes - Added hide_if_zero checking for _order_item_total_ shortcodes.
Download this release

Release Info

Developer algoritmika
Plugin Icon 128x128 Booster for WooCommerce
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.0.13 to 2.1.1

Files changed (106) hide show
  1. includes/admin/settings/class-wc-settings-jetpack.php +38 -4
  2. includes/class-wcj-admin-tools.php +241 -0
  3. includes/class-wcj-call-for-price.php +4 -4
  4. includes/class-wcj-checkout-custom-fields.php +3 -2
  5. includes/class-wcj-currencies.php +65 -69
  6. includes/class-wcj-general.php +8 -6
  7. includes/class-wcj-order-numbers.php +17 -8
  8. includes/class-wcj-orders.php +3 -3
  9. includes/class-wcj-pdf-invoices.php +14 -13
  10. includes/class-wcj-pdf-invoicing.php +190 -0
  11. includes/class-wcj-price-by-country.php +105 -527
  12. includes/class-wcj-product-info.php +49 -73
  13. includes/class-wcj-product-input-fields.php +232 -0
  14. includes/class-wcj-related-products.php +164 -0
  15. includes/class-wcj-sku.php +48 -26
  16. includes/classes/class-wcj-invoice.php +109 -0
  17. includes/classes/class-wcj-pdf-invoice.php +237 -0
  18. includes/currencies/wcj-currencies.php +1 -0
  19. includes/functions/wcj-country-functions.php +322 -0
  20. includes/functions/wcj-debug-functions.php +30 -0
  21. includes/functions/wcj-functions.php +288 -0
  22. includes/functions/wcj-html-functions.php +82 -0
  23. includes/functions/wcj-invoicing-functions.php +136 -0
  24. includes/gateways/class-wc-gateway-wcj-custom.php +2 -3
  25. includes/{abstracts/class-wcj-product-input-fields.php → input-fields/class-wcj-product-input-fields-abstract.php} +4 -4
  26. includes/{class-wcj-product-input-fields-global.php → input-fields/class-wcj-product-input-fields-global.php} +8 -79
  27. includes/{class-wcj-product-input-fields-per-product.php → input-fields/class-wcj-product-input-fields-per-product.php} +7 -66
  28. includes/js/exchange_rates.js +40 -0
  29. includes/js/product-input-fields.js +9 -0
  30. includes/{tcpdf_min → lib/tcpdf_min}/CHANGELOG.TXT +0 -0
  31. includes/{tcpdf_min → lib/tcpdf_min}/LICENSE.TXT +0 -0
  32. includes/{tcpdf_min → lib/tcpdf_min}/README.TXT +0 -0
  33. includes/{tcpdf_min → lib/tcpdf_min}/composer.json +0 -0
  34. includes/{tcpdf_min → lib/tcpdf_min}/config/tcpdf_config.php +0 -0
  35. includes/{tcpdf_min → lib/tcpdf_min}/fonts/courier.php +0 -0
  36. includes/{tcpdf_min → lib/tcpdf_min}/fonts/courierb.php +0 -0
  37. includes/{tcpdf_min → lib/tcpdf_min}/fonts/courierbi.php +0 -0
  38. includes/{tcpdf_min → lib/tcpdf_min}/fonts/courieri.php +0 -0
  39. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.ctg.z +0 -0
  40. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.php +0 -0
  41. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.z +0 -0
  42. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.ctg.z +0 -0
  43. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.php +0 -0
  44. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.z +0 -0
  45. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.ctg.z +0 -0
  46. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.php +0 -0
  47. includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.z +0 -0
  48. includes/{tcpdf_min → lib/tcpdf_min}/fonts/helvetica.php +0 -0
  49. includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticab.php +0 -0
  50. includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticabi.php +0 -0
  51. includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticai.php +0 -0
  52. includes/{tcpdf_min → lib/tcpdf_min}/fonts/symbol.php +0 -0
  53. includes/{tcpdf_min → lib/tcpdf_min}/fonts/times.php +0 -0
  54. includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesb.php +0 -0
  55. includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesbi.php +0 -0
  56. includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesi.php +0 -0
  57. includes/{tcpdf_min → lib/tcpdf_min}/fonts/zapfdingbats.php +0 -0
  58. includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/datamatrix.php +0 -0
  59. includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/pdf417.php +0 -0
  60. includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/qrcode.php +0 -0
  61. includes/{tcpdf_min → lib/tcpdf_min}/include/sRGB.icc +0 -0
  62. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_colors.php +0 -0
  63. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_filters.php +0 -0
  64. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_font_data.php +0 -0
  65. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_fonts.php +0 -0
  66. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_images.php +0 -0
  67. includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_static.php +0 -0
  68. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf.php +0 -0
  69. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_autoconfig.php +0 -0
  70. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_barcodes_1d.php +0 -0
  71. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_barcodes_2d.php +0 -0
  72. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_import.php +0 -0
  73. includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_parser.php +0 -0
  74. includes/{tcpdf_min → lib/tcpdf_min}/tools/.htaccess +0 -0
  75. includes/{tcpdf_min → lib/tcpdf_min}/tools/convert_fonts_examples.txt +0 -0
  76. includes/{tcpdf_min → lib/tcpdf_min}/tools/tcpdf_addfont.php +0 -0
  77. includes/pdf-invoices/class-wcj-pdf-invoicing-renumerate-tool.php +223 -0
  78. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-display.php +209 -0
  79. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-emails.php +113 -0
  80. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-footer.php +90 -0
  81. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-header.php +123 -0
  82. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-numbering.php +85 -0
  83. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-page.php +98 -0
  84. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-styling.php +103 -0
  85. includes/pdf-invoices/settings/class-wcj-pdf-invoicing-templates.php +72 -0
  86. includes/pdf-invoices/settings/defaults/wcj-content-template-invoice.php +32 -0
  87. includes/pdf-invoices/settings/defaults/wcj-content-template-packing_slip.php +27 -0
  88. includes/pdf-invoices/settings/defaults/wcj-content-template-proforma_invoice.php +32 -0
  89. includes/pdf-invoices/settings/defaults/wcj-invoice.css +31 -0
  90. includes/pdf-invoices/settings/defaults/wcj-packing_slip.css +13 -0
  91. includes/pdf-invoices/settings/defaults/wcj-proforma_invoice.css +31 -0
  92. includes/price-by-country/class-wcj-country-by-ip.php +292 -0
  93. includes/price-by-country/class-wcj-exchange-rates-crons.php +138 -0
  94. includes/price-by-country/class-wcj-exchange-rates.php +86 -0
  95. includes/price-by-country/class-wcj-price-by-country-core.php +283 -0
  96. includes/price-by-country/class-wcj-price-by-country-local.php +294 -0
  97. includes/price-by-country/class-wcj-price-by-country-reports.php +106 -0
  98. includes/reports/wcj-class-reports-customers.php +1 -1
  99. includes/shortcodes/class-wcj-general-shortcodes.php +58 -0
  100. includes/shortcodes/class-wcj-invoices-shortcodes.php +95 -0
  101. includes/shortcodes/class-wcj-order-items-shortcodes.php +240 -0
  102. includes/shortcodes/class-wcj-orders-shortcodes.php +287 -0
  103. includes/shortcodes/class-wcj-products-shortcodes.php +73 -0
  104. includes/shortcodes/class-wcj-shortcodes.php +87 -0
  105. readme.txt +37 -6
  106. woocommerce-jetpack.php +155 -64
includes/admin/settings/class-wc-settings-jetpack.php CHANGED
@@ -38,7 +38,17 @@ class WC_Settings_Jetpack extends WC_Settings_Page {
38
  'products' => array(
39
  'label' => __( 'Products', 'woocommerce-jetpack' ),
40
  'default_cat_id' => 'product_listings',
41
- 'all_cat_ids' => array( 'product_listings', 'product_tabs', 'product_info', 'sorting', 'sku', 'product_input_fields_global', 'product_input_fields_local', 'bulk_price_converter', ),
 
 
 
 
 
 
 
 
 
 
42
  ),
43
  'cart' => array(
44
  'label' => __( 'Cart', 'woocommerce-jetpack' ),
@@ -60,10 +70,34 @@ class WC_Settings_Jetpack extends WC_Settings_Page {
60
  'default_cat_id' => 'orders',
61
  'all_cat_ids' => array( 'orders', 'order_numbers', ),
62
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  'pdf_invoices' => array(
64
- 'label' => __( 'PDF Invoices', 'woocommerce-jetpack' ),
65
  'default_cat_id' => 'pdf_invoices',
66
- 'all_cat_ids' => array( 'pdf_invoices', ),
 
 
67
  ),
68
  'emails' => array(
69
  'label' => __( 'Emails', 'woocommerce-jetpack' ),
@@ -78,7 +112,7 @@ class WC_Settings_Jetpack extends WC_Settings_Page {
78
  'misc' => array(
79
  'label' => __( 'Misc.', 'woocommerce-jetpack' ),
80
  'default_cat_id' => 'general',
81
- 'all_cat_ids' => array( 'general', 'old_slugs', 'reports', ),
82
  ),
83
  );
84
 
38
  'products' => array(
39
  'label' => __( 'Products', 'woocommerce-jetpack' ),
40
  'default_cat_id' => 'product_listings',
41
+ 'all_cat_ids' => array(
42
+ 'product_listings',
43
+ 'product_tabs',
44
+ 'product_info',
45
+ 'related_products',
46
+ 'sorting',
47
+ 'sku',
48
+ 'product_input_fields',
49
+ //'product_input_fields_global',
50
+ //'product_input_fields_local',
51
+ 'bulk_price_converter', ),
52
  ),
53
  'cart' => array(
54
  'label' => __( 'Cart', 'woocommerce-jetpack' ),
70
  'default_cat_id' => 'orders',
71
  'all_cat_ids' => array( 'orders', 'order_numbers', ),
72
  ),
73
+ 'pdf_invoicing' => array(
74
+ //'label' => __( 'PDF Invoicing & Packing Slips', 'woocommerce-jetpack' ) . ' (v2)',
75
+ 'label' => __( 'PDF Invoices', 'woocommerce-jetpack' ) . ' (v2)',
76
+ 'default_cat_id' => 'pdf_invoicing',
77
+ 'all_cat_ids' => array(
78
+ //'pdf_invoices',
79
+ 'pdf_invoicing',
80
+ //'pdf_invoices_by_settings',
81
+ //'pdf_invoices_by_shortcodes',
82
+ //'pdf_invoices_proforma',
83
+ //'pdf_invoices_packing',
84
+ 'pdf_invoicing_numbering',
85
+ 'pdf_invoicing_templates',
86
+ 'pdf_invoicing_header',
87
+ 'pdf_invoicing_footer',
88
+ 'pdf_invoicing_styling',
89
+ 'pdf_invoicing_page',
90
+ 'pdf_invoicing_emails',
91
+ 'pdf_invoicing_display',
92
+ //'pdf_invoicing_general',
93
+ ),
94
+ ),
95
  'pdf_invoices' => array(
96
+ 'label' => __( 'PDF Invoices', 'woocommerce-jetpack' ) . ' (v1)',
97
  'default_cat_id' => 'pdf_invoices',
98
+ 'all_cat_ids' => array(
99
+ 'pdf_invoices',
100
+ ),
101
  ),
102
  'emails' => array(
103
  'label' => __( 'Emails', 'woocommerce-jetpack' ),
112
  'misc' => array(
113
  'label' => __( 'Misc.', 'woocommerce-jetpack' ),
114
  'default_cat_id' => 'general',
115
+ 'all_cat_ids' => array( 'general', 'old_slugs', 'reports', 'admin_tools', ),
116
  ),
117
  );
118
 
includes/class-wcj-admin-tools.php ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Admin Tools
4
+ *
5
+ * The WooCommerce Jetpack Admin Tools class.
6
+ *
7
+ * @class WCJ_Admin_Tools
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Admin_Tools' ) ) :
16
+
17
+ class WCJ_Admin_Tools {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ // Main hooks
25
+ if ( 'yes' === get_option( 'wcj_admin_tools_enabled' ) ) {
26
+ add_filter( 'wcj_tools_tabs', array( $this, 'add_tool_tab' ), 100 );
27
+ add_action( 'wcj_tools_' . 'admin_tools', array( $this, 'create_tool' ), 100 );
28
+ }
29
+
30
+ // Settings hooks
31
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
32
+ add_filter( 'wcj_settings_admin_tools', array( $this, 'get_settings' ), 100 );
33
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
34
+ add_action( 'wcj_tools_dashboard', array( $this, 'add_tool_info_to_tools_dashboard' ), 100 );
35
+
36
+
37
+
38
+
39
+ }
40
+
41
+
42
+
43
+
44
+
45
+ /**
46
+ * add_tool_info_to_tools_dashboard.
47
+ */
48
+ public function add_tool_info_to_tools_dashboard() {
49
+ echo '<tr>';
50
+ if ( 'yes' === get_option( 'wcj_admin_tools_enabled') )
51
+ $is_enabled = '<span style="color:green;font-style:italic;">' . __( 'enabled', 'woocommerce-jetpack' ) . '</span>';
52
+ else
53
+ $is_enabled = '<span style="color:gray;font-style:italic;">' . __( 'disabled', 'woocommerce-jetpack' ) . '</span>';
54
+ echo '<td>' . __( 'Admin Tools', 'woocommerce-jetpack' ) . '</td>';
55
+ echo '<td>' . $is_enabled . '</td>';
56
+ echo '<td>' . __( 'Log.', 'woocommerce-jetpack' ) . '</td>';
57
+ echo '</tr>';
58
+ }
59
+
60
+ /**
61
+ * add_tool_tab.
62
+ */
63
+ public function add_tool_tab( $tabs ) {
64
+ $tabs[] = array(
65
+ 'id' => 'admin_tools',
66
+ 'title' => __( 'Admin Tools', 'woocommerce-jetpack' ),
67
+ );
68
+ return $tabs;
69
+ }
70
+
71
+ /**
72
+ * create_tool.
73
+ */
74
+ public function create_tool() {
75
+
76
+ $the_notice = '';
77
+ if ( isset( $_GET['wcj_delete_log'] ) && is_super_admin() ) {
78
+ update_option( 'wcj_log', '' );
79
+ $the_notice .= __( 'Log deleted successfully.', 'woocommerce-jetpack' );
80
+ }
81
+
82
+ $the_tools = '';
83
+ $the_tools .= '<a href="' . add_query_arg( 'wcj_delete_log', '1' ) . '">' . __( 'Delete Log', 'woocommerce-jetpack' ) . '</a>';
84
+
85
+ $the_log = '';
86
+ //if ( isset( $_GET['wcj_view_log'] ) ) {
87
+ $the_log .= '<pre>' . get_option( 'wcj_log', '' ) . '</pre>';
88
+ //}
89
+
90
+ echo '<p>' . $the_tools . '</p>';
91
+
92
+ echo '<p>' . $the_notice . '</p>';
93
+
94
+ echo '<p>' . $the_log . '</p>';
95
+
96
+ /**
97
+ // Show invoices
98
+ $data = array();
99
+ $data[] = array(
100
+ 'Invoice Nr.',
101
+ 'Invoice Date',
102
+ 'Order ID',
103
+ 'Customer Country',
104
+ 'Tax %',
105
+ 'Order Total Tax Excl.',
106
+ 'Order Taxes',
107
+ 'Order Total',
108
+ );
109
+
110
+ $total_sum = 0;
111
+ $total_sum_excl_tax = 0;
112
+ $total_tax = 0;
113
+
114
+ $args = array(
115
+ 'post_type' => 'shop_order',
116
+ 'post_status' => 'any',
117
+ 'posts_per_page' => -1,
118
+ 'orderby' => 'date',
119
+ 'order' => 'ASC',
120
+
121
+ 'year' => 2015,
122
+ 'monthnum' => 1,
123
+ );
124
+ $loop = new WP_Query( $args );
125
+ while ( $loop->have_posts() ) : $loop->the_post();
126
+ $order_id = $loop->post->ID;
127
+ $invoice_type_id = 'invoice';
128
+
129
+
130
+ if ( wcj_is_invoice_created( $order_id, $invoice_type_id ) ) {
131
+
132
+ $the_order = wc_get_order( $order_id );
133
+
134
+ $user_meta = get_user_meta( $the_order->get_user_id() );
135
+ $billing_country = isset( $user_meta['billing_country'][0] ) ? $user_meta['billing_country'][0] : '';
136
+ $shipping_country = isset( $user_meta['shipping_country'][0] ) ? $user_meta['shipping_country'][0] : '';
137
+ $customer_country = ( '' == $billing_country ) ? $shipping_country : $billing_country;
138
+
139
+ $order_total = $the_order->get_total();
140
+
141
+ $order_tax = apply_filters( 'wcj_order_total_tax', $the_order->get_total_tax(), $the_order );
142
+ //$order_tax_percent = ( isset( $taxes_by_countries_eu[ $customer_country ] ) ) ? $taxes_by_countries_eu[ $customer_country ] : 0;
143
+ //$order_tax_percent /= 100;
144
+ //$order_tax = $order_total * $order_tax_percent;
145
+ $order_total_exlc_tax = $order_total - $order_tax;
146
+ $order_tax_percent = ( 0 == $order_total ) ? 0 : $order_tax / $order_total_exlc_tax;
147
+
148
+ $total_sum += $order_total;
149
+ $total_sum_excl_tax += $order_total_exlc_tax;
150
+ $total_tax += $order_tax;
151
+
152
+ //$order_tax_html = ( 0 == $order_tax ) ? '' : sprintf( '$ %.2f', $order_tax );
153
+ $order_tax_html = sprintf( '$ %.2f', $order_tax );
154
+
155
+ $data[] = array(
156
+ wcj_get_invoice_number( $order_id, $invoice_type_id ),
157
+ wcj_get_invoice_date( $order_id, $invoice_type_id, 0, get_option( 'date_format' ) ),
158
+ $order_id,
159
+ $customer_country,
160
+ sprintf( '%.0f %%', $order_tax_percent * 100 ),
161
+ sprintf( '$ %.2f', $order_total_exlc_tax ),
162
+ $order_tax_html,
163
+ sprintf( '$ %.2f', $order_total ),
164
+ );
165
+ }
166
+ endwhile;
167
+ echo '<h3>' . 'Total Sum Excl. Tax: ' . sprintf( '$ %.2f', $total_sum_excl_tax ) . '</h3>';
168
+ echo '<h3>' . 'Total Sum: ' . sprintf( '$ %.2f', $total_sum ) . '</h3>';
169
+ echo '<h3>' . 'Total Tax: ' . sprintf( '$ %.2f', $total_tax ) . '</h3>';
170
+ echo wcj_get_table_html( $data, array( 'table_class' => 'widefat', ) );
171
+ /**/
172
+ }
173
+
174
+ /**
175
+ * add_enabled_option.
176
+ */
177
+ public function add_enabled_option( $settings ) {
178
+ $all_settings = $this->get_settings();
179
+ $settings[] = $all_settings[1];
180
+ return $settings;
181
+ }
182
+
183
+ /**
184
+ * get_settings.
185
+ */
186
+ function get_settings() {
187
+
188
+ $settings = array(
189
+
190
+ array( 'title' => __( 'Admin Tools Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_admin_tools_options' ),
191
+
192
+ array(
193
+ 'title' => __( 'Admin Tools', 'woocommerce-jetpack' ),
194
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
195
+ 'desc_tip' => __( 'Debug and log tools.', 'woocommerce-jetpack' ),
196
+ 'id' => 'wcj_admin_tools_enabled',
197
+ 'default' => 'no',
198
+ 'type' => 'checkbox',
199
+ ),
200
+
201
+ array(
202
+ 'title' => __( 'Logging', 'woocommerce-jetpack' ),
203
+ 'desc' => __( 'Enable', 'woocommerce-jetpack' ),
204
+ 'id' => 'wcj_logging_enabled',
205
+ 'default' => 'no',
206
+ 'type' => 'checkbox',
207
+ ),
208
+
209
+ array(
210
+ 'title' => __( 'Debug', 'woocommerce-jetpack' ),
211
+ 'desc' => __( 'Enable', 'woocommerce-jetpack' ),
212
+ 'id' => 'wcj_debuging_enabled',
213
+ 'default' => 'no',
214
+ 'type' => 'checkbox',
215
+ ),
216
+
217
+ /*array(
218
+ 'title' => __( 'Custom Shortcode', 'woocommerce-jetpack' ),
219
+ 'id' => 'wcj_custom_shortcode_1',
220
+ 'default' => '',
221
+ 'type' => 'textarea',
222
+ ),*/
223
+
224
+ array( 'type' => 'sectionend', 'id' => 'wcj_admin_tools_options' ),
225
+ );
226
+
227
+ return $settings;
228
+ }
229
+
230
+ /**
231
+ * settings_section.
232
+ */
233
+ function settings_section( $sections ) {
234
+ $sections['admin_tools'] = __( 'Admin Tools', 'woocommerce-jetpack' );
235
+ return $sections;
236
+ }
237
+ }
238
+
239
+ endif;
240
+
241
+ return new WCJ_Admin_Tools();
includes/class-wcj-call-for-price.php CHANGED
@@ -58,13 +58,13 @@ class WCJ_Call_For_Price {
58
  */
59
  public function on_empty_price( $price ) {
60
  if ( ( get_option('wcj_call_for_price_text') !== '' ) && is_single( get_the_ID() ) )
61
- return apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text') );
62
  if ( ( get_option('wcj_call_for_price_text_on_related') !== '' ) && ( is_single() ) && ( ! is_single( get_the_ID() ) ) )
63
- return apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_related') );
64
  if ( ( get_option('wcj_call_for_price_text_on_archive') !== '' ) && is_archive() )
65
- return apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_archive') );
66
  if ( ( get_option('wcj_call_for_price_text_on_home') !== '' ) && is_front_page() )
67
- return apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_home') );
68
 
69
  // No changes
70
  return $price;
58
  */
59
  public function on_empty_price( $price ) {
60
  if ( ( get_option('wcj_call_for_price_text') !== '' ) && is_single( get_the_ID() ) )
61
+ return do_shortcode( apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text') ) );
62
  if ( ( get_option('wcj_call_for_price_text_on_related') !== '' ) && ( is_single() ) && ( ! is_single( get_the_ID() ) ) )
63
+ return do_shortcode( apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_related') ) );
64
  if ( ( get_option('wcj_call_for_price_text_on_archive') !== '' ) && is_archive() )
65
+ return do_shortcode( apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_archive') ) );
66
  if ( ( get_option('wcj_call_for_price_text_on_home') !== '' ) && is_front_page() )
67
+ return do_shortcode( apply_filters( 'wcj_get_option_filter', $this->default_empty_price_text, get_option('wcj_call_for_price_text_on_home') ) );
68
 
69
  // No changes
70
  return $price;
includes/class-wcj-checkout-custom-fields.php CHANGED
@@ -185,9 +185,10 @@ class WCJ_Checkout_Custom_Fields {
185
  $post_meta = get_post_meta( $order->id );//, $post_meta_name, false );
186
  //print_r( $post_meta );
187
  foreach( $post_meta as $key => $values ) {
188
- $value = unserialize( $values[0] );
 
189
  //foreach( $values as $value ) {
190
- if ( $section === $value['section'] ) {
191
  //print_r( $value );
192
  if ( '' != $value['value'] ) {
193
  $the_label = $value['label'];
185
  $post_meta = get_post_meta( $order->id );//, $post_meta_name, false );
186
  //print_r( $post_meta );
187
  foreach( $post_meta as $key => $values ) {
188
+ // $value = unserialize( $values[0] );
189
+ $value = maybe_unserialize( $values[0] );
190
  //foreach( $values as $value ) {
191
+ if ( isset( $value['section'] ) && $section === $value['section'] ) {
192
  //print_r( $value );
193
  if ( '' != $value['value'] ) {
194
  $the_label = $value['label'];
includes/class-wcj-currencies.php CHANGED
@@ -9,57 +9,66 @@
9
  * @category Class
10
  * @author Algoritmika Ltd.
11
  */
12
-
13
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
  if ( ! class_exists( 'WCJ_Currencies' ) ) :
16
 
17
  class WCJ_Currencies {
18
-
19
  public function __construct() {
20
-
21
  $currencies = include( 'currencies/wcj-currencies.php' );
22
  foreach( $currencies as $data ) {
23
- $this->currency_symbols[ $data['code'] ] = $data['symbol'];
24
- $this->currency_names[ $data['code'] ] = $data['name'];
25
- //$this->currency_names_and_symbols[ $data['code'] ] = $data['name'] . ' (' . $data['symbol'] . ')';
26
- }
27
-
28
  // Hooks
29
  if ( get_option( 'wcj_currency_enabled' ) == 'yes') {
30
-
31
  // Main hooks
32
- add_filter( 'woocommerce_currencies', array($this, 'add_all_currencies'), 100 );
33
- add_filter( 'woocommerce_currency_symbol', array($this, 'add_currency_symbol'), 100, 2 );
34
-
35
  // Settings
36
  add_filter( 'woocommerce_general_settings', array( $this, 'add_edit_currency_symbol_field' ), 100 );
37
  }
38
-
39
  // Settings
40
  add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
41
- add_filter( 'wcj_settings_currency', array( $this, 'get_settings' ), 100 );
42
-
43
- add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
44
  }
45
 
46
  /**
47
- * add_enabled_option.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  */
49
- public function add_enabled_option( $settings ) {
50
-
51
- $all_settings = $this->get_settings();
52
- $settings[] = $all_settings[1];
53
-
54
- return $settings;
55
- }
56
-
57
  function add_edit_currency_symbol_field( $settings ) {
58
 
59
  $updated_settings = array();
60
 
61
  foreach ( $settings as $section ) {
62
-
63
  if ( isset( $section['id'] ) && 'woocommerce_currency_pos' == $section['id'] ) {
64
 
65
  $updated_settings[] = array(
@@ -70,19 +79,31 @@ class WCJ_Currencies {
70
  'default' => get_woocommerce_currency_symbol(),
71
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
72
  'css' => 'width: 50px;',
73
- 'custom_attributes'
74
  => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
75
  );
76
  }
77
-
78
  $updated_settings[] = $section;
79
  }
80
-
81
  return $updated_settings;
82
- }
83
-
 
 
 
 
 
 
 
 
 
 
 
 
84
  function get_settings() {
85
-
86
  $settings = array(
87
 
88
  array( 'title' => __( 'Currencies Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_currency_options' ),
@@ -95,11 +116,11 @@ class WCJ_Currencies {
95
  'default' => 'yes',
96
  'type' => 'checkbox'
97
  ),
98
-
99
  array( 'type' => 'sectionend', 'id' => 'wcj_currency_options' ),
100
-
101
  array( 'title' => __( 'Currency Symbol Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_all_currencies_list_options' ),
102
-
103
  array(
104
  'title' => __( 'Hide Currency Symbol', 'woocommerce-jetpack' ),
105
  'desc' => __( 'Hide', 'woocommerce-jetpack' ),
@@ -107,9 +128,9 @@ class WCJ_Currencies {
107
  'id' => 'wcj_currency_hide_symbol',
108
  'default' => 'no',
109
  'type' => 'checkbox'
110
- ),
111
  );
112
-
113
  foreach ( $this->currency_names as $currency_code => $currency_name )
114
  $settings[] = array(
115
  'title' => $currency_name,
@@ -117,47 +138,22 @@ class WCJ_Currencies {
117
  'id' => 'wcj_currency_' . $currency_code,
118
  'default' => $this->currency_symbols[ $currency_code ],
119
  'type' => 'text',
120
- 'custom_attributes'
121
  => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
122
  );
123
-
124
  $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_all_currencies_list_options' );
125
-
126
  return $settings;
127
  }
128
-
 
 
 
129
  function settings_section( $sections ) {
130
-
131
  $sections['currency'] = __( 'Currencies', 'woocommerce-jetpack' );
132
-
133
  return $sections;
134
  }
135
-
136
- function add_all_currencies( $currencies ) {
137
-
138
- foreach ( $this->currency_names as $currency_code => $currency_name )
139
- $currencies[ $currency_code ] = $currency_name;
140
-
141
- asort( $currencies );
142
-
143
- return $currencies;
144
- }
145
-
146
- function add_currency_symbol( $currency_symbol, $currency ) {
147
-
148
- if ( 'yes' === get_option( 'wcj_currency_hide_symbol' ) )
149
- return '';
150
-
151
- return apply_filters( 'wcj_get_option_filter', $this->currency_symbols[ $currency ], get_option( 'wcj_currency_' . $currency, $currency_symbol ) );
152
- }
153
-
154
- /*public function check_wooallcurpro_fields($input) {
155
-
156
- foreach ($this->currencies_list as $currency_id => $currency_name)
157
- $res[$currency_id] = str_replace('"', '\'', $input[$currency_id]);
158
-
159
- return $res;
160
- }*/
161
  }
162
 
163
  endif;
9
  * @category Class
10
  * @author Algoritmika Ltd.
11
  */
12
+
13
  if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
  if ( ! class_exists( 'WCJ_Currencies' ) ) :
16
 
17
  class WCJ_Currencies {
18
+
19
  public function __construct() {
20
+
21
  $currencies = include( 'currencies/wcj-currencies.php' );
22
  foreach( $currencies as $data ) {
23
+ $this->currency_symbols[ $data['code'] ] = $data['symbol'];
24
+ $this->currency_names[ $data['code'] ] = $data['name'];
25
+ //$this->currency_names_and_symbols[ $data['code'] ] = $data['name'] . ' (' . $data['symbol'] . ')';
26
+ }
27
+
28
  // Hooks
29
  if ( get_option( 'wcj_currency_enabled' ) == 'yes') {
 
30
  // Main hooks
31
+ add_filter( 'woocommerce_currencies', array( $this, 'add_all_currencies'), 100 );
32
+ add_filter( 'woocommerce_currency_symbol', array( $this, 'add_currency_symbol'), 100, 2 );
 
33
  // Settings
34
  add_filter( 'woocommerce_general_settings', array( $this, 'add_edit_currency_symbol_field' ), 100 );
35
  }
36
+
37
  // Settings
38
  add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
39
+ add_filter( 'wcj_settings_currency', array( $this, 'get_settings' ), 100 );
40
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
 
41
  }
42
 
43
  /**
44
+ * add_all_currencies.
45
+ */
46
+ function add_all_currencies( $currencies ) {
47
+ foreach ( $this->currency_names as $currency_code => $currency_name )
48
+ $currencies[ $currency_code ] = $currency_name;
49
+ asort( $currencies );
50
+ return $currencies;
51
+ }
52
+
53
+ /**
54
+ * add_currency_symbol.
55
+ */
56
+ function add_currency_symbol( $currency_symbol, $currency ) {
57
+ if ( 'yes' === get_option( 'wcj_currency_hide_symbol' ) )
58
+ return '';
59
+ $default = ( isset( $this->currency_symbols[ $currency ] ) ) ? $this->currency_symbols[ $currency ] : $currency_symbol;
60
+ return apply_filters( 'wcj_get_option_filter', $default, get_option( 'wcj_currency_' . $currency, $currency_symbol ) );
61
+ }
62
+
63
+ /**
64
+ * add_edit_currency_symbol_field.
65
  */
 
 
 
 
 
 
 
 
66
  function add_edit_currency_symbol_field( $settings ) {
67
 
68
  $updated_settings = array();
69
 
70
  foreach ( $settings as $section ) {
71
+
72
  if ( isset( $section['id'] ) && 'woocommerce_currency_pos' == $section['id'] ) {
73
 
74
  $updated_settings[] = array(
79
  'default' => get_woocommerce_currency_symbol(),
80
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
81
  'css' => 'width: 50px;',
82
+ 'custom_attributes'
83
  => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
84
  );
85
  }
86
+
87
  $updated_settings[] = $section;
88
  }
89
+
90
  return $updated_settings;
91
+ }
92
+
93
+ /**
94
+ * add_enabled_option.
95
+ */
96
+ public function add_enabled_option( $settings ) {
97
+ $all_settings = $this->get_settings();
98
+ $settings[] = $all_settings[1];
99
+ return $settings;
100
+ }
101
+
102
+ /**
103
+ * get_settings.
104
+ */
105
  function get_settings() {
106
+
107
  $settings = array(
108
 
109
  array( 'title' => __( 'Currencies Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_currency_options' ),
116
  'default' => 'yes',
117
  'type' => 'checkbox'
118
  ),
119
+
120
  array( 'type' => 'sectionend', 'id' => 'wcj_currency_options' ),
121
+
122
  array( 'title' => __( 'Currency Symbol Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_all_currencies_list_options' ),
123
+
124
  array(
125
  'title' => __( 'Hide Currency Symbol', 'woocommerce-jetpack' ),
126
  'desc' => __( 'Hide', 'woocommerce-jetpack' ),
128
  'id' => 'wcj_currency_hide_symbol',
129
  'default' => 'no',
130
  'type' => 'checkbox'
131
+ ),
132
  );
133
+
134
  foreach ( $this->currency_names as $currency_code => $currency_name )
135
  $settings[] = array(
136
  'title' => $currency_name,
138
  'id' => 'wcj_currency_' . $currency_code,
139
  'default' => $this->currency_symbols[ $currency_code ],
140
  'type' => 'text',
141
+ 'custom_attributes'
142
  => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
143
  );
144
+
145
  $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_all_currencies_list_options' );
146
+
147
  return $settings;
148
  }
149
+
150
+ /**
151
+ * settings_section.
152
+ */
153
  function settings_section( $sections ) {
 
154
  $sections['currency'] = __( 'Currencies', 'woocommerce-jetpack' );
 
155
  return $sections;
156
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
 
159
  endif;
includes/class-wcj-general.php CHANGED
@@ -22,11 +22,13 @@ class WCJ_General {
22
  public function __construct() {
23
  // Main hooks
24
  if ( 'yes' === get_option( 'wcj_general_enabled' ) ) {
 
25
  if ( '' != get_option( 'wcj_general_custom_css' ) )
26
- add_action( 'wp_head', array( $this, 'hook_custom_css' ) );
27
  if ( '' != get_option( 'wcj_general_custom_admin_css' ) )
28
- add_action( 'admin_head', array( $this, 'hook_custom_admin_css' ) );
29
- }
 
30
  // Settings hooks
31
  add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
32
  add_filter( 'wcj_settings_general', array( $this, 'get_settings' ), 100 );
@@ -71,10 +73,10 @@ class WCJ_General {
71
 
72
  array(
73
  'title' => __( 'General', 'woocommerce-jetpack' ),
74
- 'desc' => __( 'Enable the General feature', 'woocommerce-jetpack' ),
75
  'desc_tip' => __( 'Separate custom CSS for front and back end.', 'woocommerce-jetpack' ),
76
  'id' => 'wcj_general_enabled',
77
- 'default' => 'yes',
78
  'type' => 'checkbox',
79
  ),
80
 
@@ -110,7 +112,7 @@ class WCJ_General {
110
  function settings_section( $sections ) {
111
  $sections['general'] = __( 'General', 'woocommerce-jetpack' );
112
  return $sections;
113
- }
114
  }
115
 
116
  endif;
22
  public function __construct() {
23
  // Main hooks
24
  if ( 'yes' === get_option( 'wcj_general_enabled' ) ) {
25
+
26
  if ( '' != get_option( 'wcj_general_custom_css' ) )
27
+ add_action( 'wp_head', array( $this, 'hook_custom_css' ) );
28
  if ( '' != get_option( 'wcj_general_custom_admin_css' ) )
29
+ add_action( 'admin_head', array( $this, 'hook_custom_admin_css' ) );
30
+ }
31
+
32
  // Settings hooks
33
  add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
34
  add_filter( 'wcj_settings_general', array( $this, 'get_settings' ), 100 );
73
 
74
  array(
75
  'title' => __( 'General', 'woocommerce-jetpack' ),
76
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
77
  'desc_tip' => __( 'Separate custom CSS for front and back end.', 'woocommerce-jetpack' ),
78
  'id' => 'wcj_general_enabled',
79
+ 'default' => 'no',
80
  'type' => 'checkbox',
81
  ),
82
 
112
  function settings_section( $sections ) {
113
  $sections['general'] = __( 'General', 'woocommerce-jetpack' );
114
  return $sections;
115
+ }
116
  }
117
 
118
  endif;
includes/class-wcj-order-numbers.php CHANGED
@@ -23,7 +23,8 @@ class WCJ_Order_Numbers {
23
 
24
  // Main hooks
25
  if ( 'yes' === get_option( 'wcj_order_numbers_enabled' ) ) {
26
- add_action( 'woocommerce_new_order', array( $this, 'add_order_number_meta' ), 100 );
 
27
  add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), 100, 2 );
28
  add_filter( 'wcj_tools_tabs', array( $this, 'add_renumerate_orders_tool_tab' ), 100 );
29
  add_action( 'wcj_tools_renumerate_orders', array( $this, 'create_renumerate_orders_tool' ), 100 );
@@ -99,16 +100,24 @@ class WCJ_Order_Numbers {
99
  </form>
100
  </div><?php
101
  }
 
 
 
 
102
 
103
  /**
104
  * Add/update order_number meta to order.
105
  */
106
- public function add_order_number_meta( $order_id ) {
 
 
 
107
 
108
- $current_order_number = get_option( 'wcj_order_number_counter' );
109
- //echo $current_order_number;
110
- update_option( 'wcj_order_number_counter', ( $current_order_number + 1 ) );
111
- update_post_meta( $order_id, '_wcj_order_number', $current_order_number );
 
112
  }
113
 
114
  /**
@@ -129,7 +138,7 @@ class WCJ_Order_Numbers {
129
  while ( $loop->have_posts() ) : $loop->the_post();
130
 
131
  $order_id = $loop->post->ID;
132
- $this->add_order_number_meta( $order_id );
133
 
134
  endwhile;
135
  }
@@ -154,7 +163,7 @@ class WCJ_Order_Numbers {
154
 
155
  array(
156
  'title' => __( 'Order Numbers', 'woocommerce-jetpack' ),
157
- 'desc' => '<strong>' . __( 'Enable Order Numbers WooJetpack Module', 'woocommerce-jetpack' ) . '</strong>',
158
  'desc_tip' => __( 'Sequential order numbering, custom order number prefix, suffix and number width.', 'woocommerce-jetpack' ),
159
  'id' => 'wcj_order_numbers_enabled',
160
  'default' => 'no',
23
 
24
  // Main hooks
25
  if ( 'yes' === get_option( 'wcj_order_numbers_enabled' ) ) {
26
+ //add_action( 'woocommerce_new_order', array( $this, 'add_new_order_number' ), 100 );
27
+ add_action( 'wp_insert_post', array( $this, 'add_new_order_number' ), 100 );
28
  add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), 100, 2 );
29
  add_filter( 'wcj_tools_tabs', array( $this, 'add_renumerate_orders_tool_tab' ), 100 );
30
  add_action( 'wcj_tools_renumerate_orders', array( $this, 'create_renumerate_orders_tool' ), 100 );
100
  </form>
101
  </div><?php
102
  }
103
+
104
+ public function add_new_order_number( $order_id ) {
105
+ $this->add_order_number_meta( $order_id, false );
106
+ }
107
 
108
  /**
109
  * Add/update order_number meta to order.
110
  */
111
+ public function add_order_number_meta( $order_id, $do_overwrite ) {
112
+
113
+ if ( 'shop_order' !== get_post_type( $order_id ) )
114
+ return;
115
 
116
+ if ( true === $do_overwrite || 0 == get_post_meta( $order_id, '_wcj_order_number', true ) ) {
117
+ $current_order_number = get_option( 'wcj_order_number_counter' );
118
+ update_option( 'wcj_order_number_counter', ( $current_order_number + 1 ) );
119
+ update_post_meta( $order_id, '_wcj_order_number', $current_order_number );
120
+ }
121
  }
122
 
123
  /**
138
  while ( $loop->have_posts() ) : $loop->the_post();
139
 
140
  $order_id = $loop->post->ID;
141
+ $this->add_order_number_meta( $order_id, true );
142
 
143
  endwhile;
144
  }
163
 
164
  array(
165
  'title' => __( 'Order Numbers', 'woocommerce-jetpack' ),
166
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
167
  'desc_tip' => __( 'Sequential order numbering, custom order number prefix, suffix and number width.', 'woocommerce-jetpack' ),
168
  'id' => 'wcj_order_numbers_enabled',
169
  'default' => 'no',
includes/class-wcj-orders.php CHANGED
@@ -77,9 +77,9 @@ class WCJ_Orders {
77
  */
78
  public function add_custom_order_statuses_to_reports( $args ) {
79
 
80
- /*if ( in_array( 'shop_order_refund', $args['order_types'] ) )
81
- return $args;*/
82
- if ( is_array( $args['order_status'] ) && 1 === count( $args['order_status'] ) && in_array( 'refunded', $args['order_status'] ) )
83
  return $args;
84
 
85
  $custom_order_statuses = get_option( 'wcj_orders_custom_statuses_array' );
77
  */
78
  public function add_custom_order_statuses_to_reports( $args ) {
79
 
80
+ if ( ! empty( $args['order_types'] ) && is_array( $args['order_types'] ) && in_array( 'shop_order_refund', $args['order_types'] ) )
81
+ return $args;
82
+ if ( ! empty( $args['order_status'] ) && is_array( $args['order_status'] ) && 1 === count( $args['order_status'] ) && in_array( 'refunded', $args['order_status'] ) )
83
  return $args;
84
 
85
  $custom_order_statuses = get_option( 'wcj_orders_custom_statuses_array' );
includes/class-wcj-pdf-invoices.php CHANGED
@@ -31,11 +31,11 @@ class WCJ_PDF_Invoices {
31
  */
32
  public function __construct() {
33
 
34
- add_shortcode( 'wcj_order_date', array( $this, 'shortcode_pdf_invoices_order_date' ) );
35
- add_shortcode( 'wcj_order_billing_address', array( $this, 'shortcode_pdf_invoices_billing_address' ) );
36
- add_shortcode( 'wcj_items_total_weight', array( $this, 'shortcode_pdf_invoices_items_total_weight' ) );
37
- add_shortcode( 'wcj_items_total_quantity', array( $this, 'shortcode_pdf_invoices_items_total_quantity' ) );
38
- add_shortcode( 'wcj_items_total_number', array( $this, 'shortcode_pdf_invoices_items_total_number' ) );
39
 
40
  // Main hooks
41
  if ( get_option( 'wcj_pdf_invoices_enabled' ) == 'yes' ) {
@@ -202,19 +202,18 @@ class WCJ_PDF_Invoices {
202
  public function generate_pdf( $get_by_order_id = 0 ) {
203
 
204
  if ( ! isset( $_GET['pdf_invoice'] ) && 0 == $get_by_order_id ) return;
 
 
205
 
206
  if ( ! is_user_logged_in() && 0 == $get_by_order_id ) return;
207
 
208
  if ( ( ! current_user_can( 'administrator' ) ) && ( get_current_user_id() != intval( get_post_meta( $order_id, '_customer_user', true ) ) ) && ( 0 == $get_by_order_id ) ) return;
209
 
210
- if ( 0 == $get_by_order_id )
211
- $order_id = $_GET['pdf_invoice'];
212
- else
213
- $order_id = $get_by_order_id;
214
 
215
  // Include the main TCPDF library (search for installation path).
216
  //require_once('tcpdf_include.php');
217
- require_once( 'tcpdf_min/tcpdf.php' );
218
 
219
  // create new PDF document
220
  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
@@ -384,8 +383,8 @@ class WCJ_PDF_Invoices {
384
 
385
  $post_meta = get_post_meta( $order_id );
386
  foreach( $post_meta as $key => $values ) {
387
- $value = unserialize( $values[0] );
388
- if ( $section === $value['section'] ) {
389
  if ( '' != $value['value'] ) {
390
  $the_label = $value['label'];
391
  if ( '' != $the_label )
@@ -417,6 +416,7 @@ class WCJ_PDF_Invoices {
417
  $order_total_discount = $the_order->get_total_discount();
418
 
419
  $order_tax_percent = 0;
 
420
  $order_total_before_discount = $order_total + $order_total_discount;
421
  if ( 0 != $order_total_before_discount )
422
  $order_tax_percent = $order_total_tax / $order_total_before_discount;
@@ -506,6 +506,7 @@ class WCJ_PDF_Invoices {
506
  'css' => 'width:36%;',
507
  'required' => true,
508
  'value_var' => 'item_name',
 
509
  ),
510
  array(
511
  'title' => get_option( 'wcj_pdf_invoices_column_qty_text' ),
@@ -798,7 +799,7 @@ class WCJ_PDF_Invoices {
798
 
799
  array(
800
  'title' => __( 'PDF Invoices', 'woocommerce-jetpack' ),
801
- 'desc' => __( 'Enable the PDF Invoices feature', 'woocommerce-jetpack' ),
802
  'desc_tip' => __( 'Add PDF invoices for the store owners and for the customers.', 'woocommerce-jetpack' ),
803
  'id' => 'wcj_pdf_invoices_enabled',
804
  'default' => 'yes',
31
  */
32
  public function __construct() {
33
 
34
+ //add_shortcode( 'wcj_order_date', array( $this, 'shortcode_pdf_invoices_order_date' ) );
35
+ //add_shortcode( 'wcj_order_billing_address', array( $this, 'shortcode_pdf_invoices_billing_address' ) );
36
+ //add_shortcode( 'wcj_items_total_weight', array( $this, 'shortcode_pdf_invoices_items_total_weight' ) );
37
+ //add_shortcode( 'wcj_items_total_quantity', array( $this, 'shortcode_pdf_invoices_items_total_quantity' ) );
38
+ //add_shortcode( 'wcj_items_total_number', array( $this, 'shortcode_pdf_invoices_items_total_number' ) );
39
 
40
  // Main hooks
41
  if ( get_option( 'wcj_pdf_invoices_enabled' ) == 'yes' ) {
202
  public function generate_pdf( $get_by_order_id = 0 ) {
203
 
204
  if ( ! isset( $_GET['pdf_invoice'] ) && 0 == $get_by_order_id ) return;
205
+
206
+ $order_id = ( 0 == $get_by_order_id ) ? $_GET['pdf_invoice'] : $get_by_order_id;
207
 
208
  if ( ! is_user_logged_in() && 0 == $get_by_order_id ) return;
209
 
210
  if ( ( ! current_user_can( 'administrator' ) ) && ( get_current_user_id() != intval( get_post_meta( $order_id, '_customer_user', true ) ) ) && ( 0 == $get_by_order_id ) ) return;
211
 
212
+
 
 
 
213
 
214
  // Include the main TCPDF library (search for installation path).
215
  //require_once('tcpdf_include.php');
216
+ require_once( 'lib/tcpdf_min/tcpdf.php' );
217
 
218
  // create new PDF document
219
  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
383
 
384
  $post_meta = get_post_meta( $order_id );
385
  foreach( $post_meta as $key => $values ) {
386
+ $value = maybe_unserialize( $values[0] );
387
+ if ( isset( $value['section'] ) && $section === $value['section'] ) {
388
  if ( '' != $value['value'] ) {
389
  $the_label = $value['label'];
390
  if ( '' != $the_label )
416
  $order_total_discount = $the_order->get_total_discount();
417
 
418
  $order_tax_percent = 0;
419
+ $order_total_discount_tax = 0;
420
  $order_total_before_discount = $order_total + $order_total_discount;
421
  if ( 0 != $order_total_before_discount )
422
  $order_tax_percent = $order_total_tax / $order_total_before_discount;
506
  'css' => 'width:36%;',
507
  'required' => true,
508
  'value_var' => 'item_name',
509
+ 'td_css' => '',
510
  ),
511
  array(
512
  'title' => get_option( 'wcj_pdf_invoices_column_qty_text' ),
799
 
800
  array(
801
  'title' => __( 'PDF Invoices', 'woocommerce-jetpack' ),
802
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
803
  'desc_tip' => __( 'Add PDF invoices for the store owners and for the customers.', 'woocommerce-jetpack' ),
804
  'id' => 'wcj_pdf_invoices_enabled',
805
  'default' => 'yes',
includes/class-wcj-pdf-invoicing.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ if ( get_option( 'wcj_pdf_invoicing_enabled' ) == 'yes' ) {
25
+
26
+ include_once( 'pdf-invoices/class-wcj-pdf-invoicing-renumerate-tool.php' );
27
+
28
+ add_action( 'init', array( $this, 'catch_args' ) );
29
+ add_action( 'init', array( $this, 'generate_pdf_on_init' ) );
30
+
31
+ define ( 'K_PATH_IMAGES', $_SERVER['DOCUMENT_ROOT'] );
32
+
33
+ $invoice_types = wcj_get_enabled_invoice_types();
34
+ foreach ( $invoice_types as $invoice_type ) {
35
+ $the_hook = get_option( 'wcj_invoices_' . $invoice_type['id'] . '_create_on', 'woocommerce_new_order' );
36
+ if ( 'disabled' != $the_hook ) {
37
+ add_action( $the_hook, array( $this, 'create_' . $invoice_type['id'] ) );
38
+ }
39
+ }
40
+ }
41
+
42
+ // Settings hooks
43
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
44
+ add_filter( 'wcj_settings_pdf_invoicing', array( $this, 'get_settings' ), 100 );
45
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
46
+ }
47
+
48
+ /**
49
+ * create_invoice.
50
+ */
51
+ function create_invoice( $order_id ) {
52
+ return $this->create_document( $order_id, 'invoice' );
53
+ }
54
+
55
+ /**
56
+ * create_proforma_invoice.
57
+ */
58
+ function create_proforma_invoice( $order_id ) {
59
+ return $this->create_document( $order_id, 'proforma_invoice' );
60
+ }
61
+
62
+ /**
63
+ * create_packing_slip.
64
+ */
65
+ function create_packing_slip( $order_id ) {
66
+ return $this->create_document( $order_id, 'packing_slip' );
67
+ }
68
+
69
+ /**
70
+ * create_document.
71
+ */
72
+ function create_document( $order_id, $invoice_type ) {
73
+ if ( false == wcj_is_invoice_created( $order_id, $invoice_type ) ) {
74
+ wcj_create_invoice( $order_id, $invoice_type );
75
+ }
76
+ /*
77
+ if ( '' == get_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', true ) ) {
78
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_sequential_enabled' ) ) {
79
+ $the_invoice_number = get_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', 1 );
80
+ update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', ( $the_invoice_number + 1 ) );
81
+ } else {
82
+ $the_invoice_number = $order_id;
83
+ }
84
+ update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', $the_invoice_number );
85
+ update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_date', time() );
86
+ }
87
+ */
88
+ }
89
+
90
+ /**
91
+ * catch_args.
92
+ */
93
+ function catch_args() {
94
+ $this->order_id = ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : 0;
95
+ $this->invoice_type_id = ( isset( $_GET['invoice_type_id'] ) ) ? $_GET['invoice_type_id'] : '';
96
+ $this->save_as_pdf = ( isset( $_GET['save_pdf_invoice'] ) && '1' == $_GET['save_pdf_invoice'] ) ? true : false;
97
+ $this->get_invoice = ( isset( $_GET['get_invoice'] ) && '1' == $_GET['get_invoice'] ) ? true : false;
98
+ }
99
+
100
+ /**
101
+ * generate_pdf_on_init.
102
+ */
103
+ function generate_pdf_on_init() {
104
+
105
+ // Check if all is OK
106
+ if ( ( true !== $this->get_invoice ) ||
107
+ ( 0 == $this->order_id ) ||
108
+ ( ! is_user_logged_in() ) ||
109
+ ( ! current_user_can( 'administrator' ) && get_current_user_id() != intval( get_post_meta( $this->order_id, '_customer_user', true ) ) ) )
110
+ return;
111
+
112
+ $the_invoice = wcj_get_pdf_invoice( $this->order_id, $this->invoice_type_id );
113
+ //$invoice = new WCJ_PDF_Invoice();
114
+ $dest = ( true === $this->save_as_pdf ) ? 'D' : 'I';
115
+ //$invoice->get_pdf( $this->order_id, $this->invoice_type_id, '', $dest );//, $this->invoice_type_id );
116
+ $the_invoice->get_pdf( $dest );
117
+ //echo $invoice_html;
118
+ }
119
+
120
+ /**
121
+ * add_enabled_option.
122
+ */
123
+ public function add_enabled_option( $settings ) {
124
+ $all_settings = $this->get_settings();
125
+ $settings[] = $all_settings[1];
126
+ return $settings;
127
+ }
128
+
129
+ /**
130
+ * get_settings.
131
+ */
132
+ function get_settings() {
133
+
134
+ $settings = array(
135
+
136
+ array( 'title' => __( 'PDF Invoicing General Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => __( '', 'woocommerce-jetpack' ), 'id' => 'wcj_pdf_invoicing_options' ),
137
+
138
+ array(
139
+ 'title' => __( 'PDF Invoicing', 'woocommerce-jetpack' ),
140
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
141
+ //'desc_tip' => __( 'Add PDF invoices for the store owners and for the customers.', 'woocommerce-jetpack' ),
142
+ 'desc_tip' => __( 'Invoices, Proforma Invoices, Packing Slips.', 'woocommerce-jetpack' ),
143
+ 'id' => 'wcj_pdf_invoicing_enabled',
144
+ 'default' => 'no',
145
+ 'type' => 'checkbox',
146
+ ),
147
+ );
148
+
149
+ // Hooks Array
150
+ $create_on_array = array();
151
+ $create_on_array['disabled'] = __( 'Disabled', 'woocommerce-jetpack' );
152
+ $create_on_array['woocommerce_new_order'] = __( 'Create on New Order', 'woocommerce-jetpack' );
153
+ $order_statuses = wcj_get_order_statuses( true );
154
+ foreach ( $order_statuses as $status => $desc ) {
155
+ $create_on_array[ 'woocommerce_order_status_' . $status ] = __( 'Create on Order Status', 'woocommerce-jetpack' ) . ' ' . $desc;
156
+ }
157
+
158
+ // Settings
159
+ $invoice_types = wcj_get_invoice_types();
160
+ foreach ( $invoice_types as $k => $invoice_type ) {
161
+ $settings[] = array(
162
+ 'title' => $invoice_type['title'],
163
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_create_on',
164
+ 'default' => 'disabled',
165
+ 'type' => 'select',
166
+ 'class' => 'chosen_select',
167
+ 'options' => $create_on_array,
168
+ 'desc' => ( 0 === $k ) ? '' : apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
169
+ 'custom_attributes'
170
+ => ( 0 === $k ) ? '' : apply_filters( 'get_wc_jetpack_plus_message', '', 'disabled' ),
171
+ );
172
+ }
173
+
174
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_pdf_invoicing_options' );
175
+
176
+ return $settings;
177
+ }
178
+
179
+ /**
180
+ * settings_section.
181
+ */
182
+ function settings_section( $sections ) {
183
+ $sections['pdf_invoicing'] = __( 'General', 'woocommerce-jetpack' );
184
+ return $sections;
185
+ }
186
+ }
187
+
188
+ endif;
189
+
190
+ return new WCJ_PDF_Invoicing();
includes/class-wcj-price-by-country.php CHANGED
@@ -21,519 +21,28 @@ class WCJ_Price_By_Country {
21
  */
22
  public function __construct() {
23
 
24
- $this->customer_country = null;
25
- $this->customer_country_group_id = null;
26
-
27
- $this->current_db_file_version = 5;
28
-
29
- //$this->currency_symbols = include( 'currencies/wcj-currency-symbols.php' );
30
- /*$currencies = include( 'currencies/wcj-currencies.php' );
31
- $this->currency_symbols = array_column( $currencies, 'symbol', 'code' );
32
- $this->currency_names = array_column( $currencies, 'name', 'code' );
33
- foreach( $this->currency_names as $code => $name )
34
- $this->currency_names_and_symbols[ $code ] = $this->currency_names[ $code ] . ' (' . $this->currency_symbols[ $code ] . ')';*/
35
- $currencies = include( 'currencies/wcj-currencies.php' );
36
- foreach( $currencies as $data ) {
37
- $this->currency_symbols[ $data['code'] ] = $data['symbol'];
38
- //$this->currency_names[ $code ] = $data['name'];
39
- $this->currency_names_and_symbols[ $data['code'] ] = $data['name'] . ' (' . $data['symbol'] . ')';
40
- }
41
-
42
  // Main hooks
43
  if ( 'yes' === get_option( 'wcj_price_by_country_enabled' ) ) {
44
  if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
45
- // The price
46
- add_filter( 'woocommerce_get_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX );
47
- add_filter( 'woocommerce_get_sale_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX );
48
- add_filter( 'woocommerce_get_regular_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX );
49
- add_filter( 'booking_form_calculated_booking_cost', array( $this, 'change_price_by_country' ), PHP_INT_MAX );
50
- add_filter( 'woocommerce_get_price_html', array( $this, 'fix_variable_product_price_on_sale' ), 10 , 2 );
51
- // Currency
52
- add_filter( 'woocommerce_currency_symbol', array( $this, 'change_currency_symbol'), PHP_INT_MAX, 2 );
53
- add_filter( 'woocommerce_currency', array( $this, 'change_currency_code'), PHP_INT_MAX, 1 );
54
  }
55
- // Reports
56
- add_filter( 'woocommerce_reports_get_order_report_data_args', array( $this, 'filter_reports'), PHP_INT_MAX, 1 );
57
- add_filter( 'woocommerce_currency_symbol', array( $this, 'change_currency_symbol_reports'), PHP_INT_MAX, 2 );
58
- //add_filter( 'woocommerce_currency', array( $this, 'change_currency_code_reports'), PHP_INT_MAX, 2 );
59
- add_action( 'admin_bar_menu', array( $this, 'add_reports_currency_to_admin_bar' ), PHP_INT_MAX );
60
-
61
- // Debug
62
- add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'add_debug_info'), PHP_INT_MAX, 0 );
63
- add_action( 'admin_init', array( $this, 'reinstall_ip_db'), PHP_INT_MAX, 0 );
64
  }
 
65
 
66
  // Settings hooks
67
- add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
68
- add_filter( 'wcj_settings_price_by_country', array( $this, 'get_settings' ), 100 );
69
- add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
70
  }
71
 
72
- public function reinstall_ip_db() {
73
- if ( isset( $_GET['wcj-install-ip-db'] ) && '1' == $_GET['wcj-install-ip-db'] ) {
74
- $this->update_database();
75
- }
76
- }
77
-
78
- public function add_debug_info() {
79
- if ( isset( $_GET['wcj-debug'] ) ) {
80
- echo '<input type="hidden" name="wcj-get-ip" value="' . $this->get_the_ip() . '" />';
81
- echo '<input type="hidden" name="wcj-get-country" value="' . $this->get_user_country_by_ip() . '" />';
82
- echo '<input type="hidden" name="wcj-get-country-external" value="' . $this->get_user_country_by_ip_external() . '" />';
83
- echo '<input type="hidden" name="wcj-get-country-group" value="' . $this->get_user_country_group_id() . '" />';
84
- echo '<input type="hidden" name="wcj-get-country-db-cur-ver" value="' . $this->current_db_file_version . '" />';
85
- echo '<input type="hidden" name="wcj-get-country-db-ver" value="' . get_option( 'wcj_geoipcountry_db_version', 0 ) . '" />';
86
- echo '<input type="hidden" name="wcj-get-country-db-from-size" value="' . count( get_option( 'wcj_geoipcountry_db_from', array() ) ) . '" />';
87
- echo '<input type="hidden" name="wcj-get-country-db-to-size" value="' . count( get_option( 'wcj_geoipcountry_db_to', array() ) ) . '" />';
88
- echo '<input type="hidden" name="wcj-get-country-db-country-size" value="' . count( get_option( 'wcj_geoipcountry_db_country', array() ) ) . '" />';
89
- }
90
- }
91
-
92
- public function add_reports_currency_to_admin_bar( $wp_admin_bar ) {
93
-
94
- //http://codex.wordpress.org/Function_Reference/add_node
95
-
96
- if ( isset( $_GET['page'] ) && 'wc-reports' === $_GET['page'] ) {
97
- $the_current_code = isset( $_GET['currency'] ) ? $_GET['currency'] : get_woocommerce_currency();
98
- $parent = 'reports_currency_select';
99
- $args = array(
100
- 'parent' => false,
101
- 'id' => $parent,
102
- 'title' => __( 'Reports currency:', 'woocommerce-jetpack' ) . ' ' . $the_current_code,
103
- 'href' => false,
104
- 'meta' => array( 'title' => __( 'Show reports only in', 'woocommerce-jetpack' ) . ' ' . $the_current_code, ),
105
- );
106
-
107
- $wp_admin_bar->add_node( $args );
108
-
109
- $currency_symbols = array();
110
- $currency_symbols[ $the_current_code ] = '';
111
- $currency_symbols[ get_woocommerce_currency() ] = '';
112
- for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
113
- $currency_symbols[ get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i ) ] = '';
114
- }
115
- $this->reports_currency_symbols = $currency_symbols;
116
-
117
-
118
- foreach ( $this->reports_currency_symbols as $code => $symbol ) {
119
- //if ( $code === $the_current_code )
120
- // continue;
121
- $args = array(
122
- 'parent' => $parent,
123
- 'id' => $parent . '_' . $code,
124
- 'title' => $code,// . ' ' . $symbol,
125
- 'href' => add_query_arg( 'currency', $code),
126
- 'meta' => array( 'title' => __( 'Show reports only in', 'woocommerce-jetpack' ) . ' ' . $code, ),
127
- );
128
-
129
- $wp_admin_bar->add_node( $args );
130
- }
131
- }
132
- }
133
-
134
- /**
135
- * change_currency_symbol_reports.
136
- */
137
- public function change_currency_symbol_reports( $currency_symbol, $currency ) {
138
- if ( isset( $_GET['page'] ) && 'wc-reports' === $_GET['page'] ) {
139
- if ( isset( $_GET['currency'] ) ) {
140
- if ( isset( $this->currency_symbols[ strtoupper( $_GET['currency'] ) ] ) ) {
141
- return $this->currency_symbols[ strtoupper( $_GET['currency'] ) ];
142
- }
143
- }
144
- }
145
- return $currency_symbol;
146
- }
147
-
148
- /**
149
- * change_currency_code_reports.
150
- *
151
- public function change_currency_code_reports( $currency ) {
152
- if ( isset( $_GET['page'] ) && 'wc-reports' === $_GET['page'] ) {
153
- if ( isset( $_GET['currency'] ) ) {
154
- return $_GET['currency'];
155
- }
156
- }
157
- return $currency;
158
- }
159
-
160
- /**
161
- * filter_reports.
162
- */
163
- public function filter_reports( $args ) {
164
- $args['where_meta'] = array(
165
- array(
166
- 'meta_key' => '_order_currency',
167
- 'meta_value' => isset( $_GET['currency'] ) ? $_GET['currency'] : get_woocommerce_currency(),
168
- 'operator' => '=',
169
- ),
170
- );
171
- return $args;
172
- }
173
-
174
- /**
175
- * fix_variable_product_price_on_sale.
176
- */
177
- public function fix_variable_product_price_on_sale( $price, $product ) {
178
- if ( $product->is_type( 'variable' ) ) {
179
- if ( ! $product->is_on_sale() ) {
180
- $start_position = strpos( $price, '<del>' );
181
- $length = strpos( $price, '</del>' ) - $start_position;
182
- // Fixing the price, i.e. removing the sale tags
183
- return substr_replace( $price, '', $start_position, $length );
184
- }
185
- }
186
- // No changes
187
- return $price;
188
- }
189
-
190
- /**
191
- * convert_ip_to_int.
192
- */
193
- public function convert_ip_to_int( $ip ) {
194
- // Convert IP to int
195
- $calc = array( 16777216, 65536, 256, 1 );
196
- $i = 0;
197
- $result = 0;
198
- $token = strtok( $ip , '.' );
199
- while ( $token !== false ) {
200
- $result += $calc[ $i++ ] * $token;
201
- $token = strtok( '.' );
202
- }
203
- return $result;
204
- }
205
-
206
- /**
207
- * str_getcsv.
208
- */
209
- public function parse_csv_line( $line ) {
210
- return explode( ',', trim( $line ) );
211
- }
212
-
213
- /**
214
- * get_country_by_ip_mysql.
215
- */
216
- public function get_country_by_ip_mysql( $ip ) {
217
- global $wpdb;
218
- $results = $wpdb->get_results( "SELECT `country_code` FROM `{$wpdb->prefix}woojetpack_country_ip` WHERE `ip_from` <= $ip AND `ip_to` >= $ip", OBJECT );
219
- if ( 1 !== count( $results ) )
220
- return null;
221
- return $results[0]->country_code;
222
- }
223
-
224
- /**
225
- * check_and_update_database.
226
- */
227
- public function update_database() {
228
- // Get IPs from file
229
- // This product includes GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
230
-
231
- // Started
232
- update_option( 'wcj_geoipcountry_db_version', -1 );
233
-
234
- global $wpdb;
235
-
236
- $charset_collate = $wpdb->get_charset_collate();
237
- $table_name = $wpdb->prefix . 'woojetpack_country_ip';
238
-
239
- $wpdb->query( "DROP TABLE $table_name;" );
240
-
241
- $sql = "CREATE TABLE $table_name (
242
- ip_from BIGINT NOT NULL,
243
- ip_to BIGINT NOT NULL,
244
- country_code VARCHAR(2) NOT NULL,
245
- UNIQUE KEY ip_from (ip_from)
246
- ) $charset_collate;";
247
- $wpdb->query( $sql );
248
-
249
- $the_values = '';
250
- $max_insert_size = 10000;
251
- $the_offset = 0;
252
- $the_predifined_size = 104402;
253
-
254
- $the_array = file( plugin_dir_path( __FILE__ ) . 'lib/ipdb.csv' );
255
-
256
- // Adding data to table
257
- while ( $the_offset < $the_predifined_size ) {
258
- $the_array_slice = array_slice( $the_array, $the_offset, $max_insert_size, true );
259
- $csv = array_map( array( $this, 'parse_csv_line' ), $the_array_slice );
260
- if ( ! empty ( $csv ) ) {
261
- foreach ( $csv as $key => $data ) {
262
- $the_values .= "('$data[0]', '$data[1]', '$data[2]'), ";
263
- //$the_values .= "('" . implode( "', '", $data ) . "'), ";
264
- }
265
- $the_values = rtrim( $the_values, ', ' );
266
- $wpdb->query( "INSERT INTO $table_name (`ip_from`, `ip_to`, `country_code`) VALUES $the_values;" );
267
- $the_values = '';
268
- }
269
- $the_offset += $max_insert_size;
270
- }
271
-
272
- // Checking if OK
273
- $count_db_table = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name;" );
274
- if ( $the_predifined_size != $count_db_table ) {
275
- // Something went wrong
276
- update_option( 'wcj_geoipcountry_db_version', -2 );
277
- }
278
- else {
279
- // Finished
280
- update_option( 'wcj_geoipcountry_db_version', $this->current_db_file_version );
281
- }
282
-
283
- // Depreciated - cleaning
284
- update_option( 'wcj_geoipcountry_db_from', array() );
285
- update_option( 'wcj_geoipcountry_db_to', array() );
286
- update_option( 'wcj_geoipcountry_db_country', array() );
287
- }
288
-
289
- /**
290
- * check_and_update_database.
291
- */
292
- public function check_and_update_database() {
293
- $current_version = get_option( 'wcj_geoipcountry_db_version', 0 );
294
- if ( $current_version < 0 )
295
- return;
296
- if ( $current_version != $this->current_db_file_version ) {
297
- $this->update_database();
298
- }
299
- }
300
-
301
- /**
302
- * search_for_nearest_below_value.
303
- * returns index on success, otherwise null
304
- */
305
- public function search_for_nearest_below_value( $db, $value_to_search ) {
306
-
307
- $count = count( $db );
308
- if( 0 == $count )
309
- return null;
310
-
311
- $div_step = 2;
312
- $index = ceil( $count / $div_step );
313
- $best_index = null;
314
- $best_score = PHP_INT_MAX;
315
- $direction = null;
316
- $indexes_checked = Array();
317
-
318
- while( true ) {
319
-
320
- // Stop if already checked
321
- if( isset( $indexes_checked[ $index ] ) ) {
322
- break ;
323
- }
324
-
325
- // Get current value
326
- $curr_value = $db[ $index ];
327
- // Stop if current value no set
328
- if( $curr_value === null ) {
329
- break ;
330
- }
331
-
332
- // Mark as already checked
333
- $indexes_checked[ $index ] = true;
334
-
335
- // Perfect match, nothing else to do
336
- if($curr_value == $value_to_search) {
337
- $best_index = $index;
338
- break;
339
- }
340
-
341
- // Calculate current score and direction
342
- $curr_score = $curr_value - $value_to_search;
343
- if( $curr_score > 0 ) {
344
- $curr_score = null;
345
- $direction = -1;
346
- }
347
- else {
348
- $curr_score = abs( $curr_score );
349
- $direction = 1;
350
- }
351
-
352
- // Save best index if: lower than value and better score than previous best, or first best
353
- if ( ( $curr_score !== null ) && ( $curr_score < $best_score ) ) {
354
- $best_index = $index;
355
- $best_score = $curr_score;
356
- }
357
-
358
- // Get next index
359
- $div_step *= 2;
360
- $index += $direction * ceil( $count / $div_step );
361
- }
362
-
363
- return $best_index;
364
- }
365
-
366
- /**
367
- * get_the_ip.
368
- */
369
- public function get_the_ip( ) {
370
- $ip = null;
371
- // Code from http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
372
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
373
- $ip = $_SERVER['HTTP_CLIENT_IP'];
374
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
375
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
376
- } else {
377
- $ip = $_SERVER['REMOTE_ADDR'];
378
- }
379
- return $ip;
380
- }
381
-
382
- /**
383
- * get_user_country_by_ip.
384
- */
385
- public function get_user_country_by_ip( ) {
386
-
387
- // We already know the country - nothing to calculate - return country
388
- if ( null != $this->customer_country )
389
- return $this->customer_country;
390
-
391
- // Default value
392
- //$this->customer_country = WC()->countries->get_base_country();
393
-
394
- // Get user IP
395
- $customer_ip = $this->get_the_ip();
396
-
397
- // Convert IP to int
398
- $ip_as_int = $this->convert_ip_to_int( $customer_ip );
399
-
400
- // Update DB if needed
401
- $this->check_and_update_database();
402
-
403
- // Search for IP in DB
404
- return $this->get_country_by_ip_mysql( $ip_as_int );
405
- /*
406
- // Search for IP in DB
407
- $db = get_option( 'wcj_geoipcountry_db_from', array() );
408
- $index = $this->search_for_nearest_below_value( $db, $ip_as_int );
409
-
410
- if ( null !== $index ) {
411
- // Check for upper limit
412
- $db = get_option( 'wcj_geoipcountry_db_to', array() );
413
- if ( $ip_as_int <= $db[ $index ] ) {
414
- // Get the country
415
- $db = get_option( 'wcj_geoipcountry_db_country', array() );
416
- $this->customer_country = $db[ $index ];
417
- return $db[ $index ];
418
- }
419
- }
420
-
421
-
422
- return null;*/
423
- }
424
-
425
- public function get_user_country_by_ip_external() {
426
- ob_start();
427
- $country = file_get_contents( 'http://api.hostip.info/country.php?ip=' . $this->get_the_ip() );
428
- //$json = file_get_contents( 'http://api.hostip.info/country.php?ip=' . $this->get_the_ip() );//file_get_contents( 'http://ipinfo.io/' . $this->get_the_ip() . '/country' );
429
- //$country = json_decode( $json );
430
- ob_end_clean();
431
- return $country;
432
- }
433
-
434
- /**
435
- * get_user_country_group_id.
436
- */
437
- public function get_user_country_group_id() {
438
-
439
- // We already know the group - nothing to calculate - return group
440
- if ( null != $this->customer_country_group_id )
441
- return $this->customer_country_group_id;
442
-
443
- // Get the country by IP
444
- switch( get_option( 'wcj_price_by_country_by_ip_detection_type', 'internal' ) ) {
445
- case 'internal':
446
- $country = $this->get_user_country_by_ip();
447
- break;
448
- case 'hostip_info':
449
- $country = $this->get_user_country_by_ip_external();
450
- break;
451
- }
452
-
453
- if ( null === $country )
454
- return null;
455
-
456
- // Go through all the groups, first found group is returned
457
- for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
458
- $country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
459
- $country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
460
- $country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
461
- if ( in_array( $country, $country_exchange_rate_group ) ) {
462
- $this->customer_country_group_id = $i;
463
- return $i;
464
- }
465
- }
466
-
467
- // Nothing found
468
- return null;
469
- }
470
-
471
- /**
472
- * change_currency_symbol.
473
- */
474
- public function change_currency_symbol( $currency_symbol, $currency ) {
475
- if ( null != ( $group_id = $this->get_user_country_group_id() ) ) {
476
- $country_currency_symbol = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
477
- if ( '' != $country_currency_symbol )
478
- return $this->currency_symbols[ $country_currency_symbol ];
479
- }
480
- return $currency_symbol;
481
- }
482
-
483
- /**
484
- * change_currency_code.
485
- */
486
- public function change_currency_code( $currency ) {
487
- if ( null != ( $group_id = $this->get_user_country_group_id() ) ) {
488
- $country_currency_symbol = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
489
- if ( '' != $country_currency_symbol )
490
- return $country_currency_symbol;
491
- }
492
- return $currency;
493
- }
494
-
495
- /**
496
- * change_price_by_country.
497
- */
498
- public function change_price_by_country( $price ) {
499
- if ( null != ( $group_id = $this->get_user_country_group_id() ) ) {
500
- $country_exchange_rate = get_option( 'wcj_price_by_country_exchange_rate_group_' . $group_id, 1 );
501
- if ( 1 != $country_exchange_rate ) {
502
- $modified_price = $price * $country_exchange_rate;
503
- $rounding = get_option( 'wcj_price_by_country_rounding', 'none' );
504
- $precision = get_option( 'woocommerce_price_num_decimals', 2 );
505
- switch ( $rounding ) {
506
- case 'none':
507
- //return ( $modified_price );
508
- return round( $modified_price, $precision );
509
- case 'round':
510
- return round( $modified_price );
511
- case 'floor':
512
- return floor( $modified_price );
513
- case 'ceil':
514
- return ceil( $modified_price );
515
- }
516
- }
517
- }
518
- // No changes
519
- return $price;
520
- }
521
-
522
- /**
523
- * get_ip_db_status_html.
524
- */
525
- public function get_ip_db_status_html() {
526
- $installed_db_version = get_option( 'wcj_geoipcountry_db_version', 0 );
527
- if ( $this->current_db_file_version != $installed_db_version ) {
528
- if ( $installed_db_version < 0 )
529
- $installed_db_version = abs( $installed_db_version ) + 10000;
530
- return __( 'IP DB not installed', 'woocommerce-jetpack' ) . ' (' . $installed_db_version . ').'
531
- . ' ' . '<a href="' . add_query_arg( 'wcj-install-ip-db', '1' ) . '">' . __( 'Fix', 'woocommerce-jetpack' ) . '</a>';
532
- }
533
- else
534
- return __( 'IP DB version: ', 'woocommerce-jetpack' ) . $this->current_db_file_version;
535
- }
536
-
537
  /**
538
  * add_enabled_option.
539
  */
@@ -550,13 +59,16 @@ class WCJ_Price_By_Country {
550
 
551
  $settings = array(
552
 
553
- array(
554
- 'title' => __( 'Price by Country Options', 'woocommerce-jetpack' ),
555
- 'type' => 'title',
556
  'desc' => __( 'Change product\'s price and currency by customer\'s country. Customer\'s country is detected automatically by IP.', 'woocommerce-jetpack' )
557
  . '<br>'
558
  . '<span style="color:gray;font-size:smaller;">'
559
- . $this->get_ip_db_status_html()
 
 
 
560
  . '</span>',
561
  'id' => 'wcj_price_by_country_options' ),
562
 
@@ -568,19 +80,20 @@ class WCJ_Price_By_Country {
568
  'default' => 'no',
569
  'type' => 'checkbox',
570
  ),
571
-
572
  array(
573
  'title' => __( 'Country by IP Method', 'woocommerce-jetpack' ),
574
  'desc' => __( 'Select which method to use for detecting customers country by IP.', 'woocommerce-jetpack' ),
575
  'id' => 'wcj_price_by_country_by_ip_detection_type',
576
- 'default' => 'internal',
577
  'type' => 'select',
578
  'options' => array(
579
- 'internal' => __( 'Internal DB (recommended)', 'woocommerce-jetpack' ),
 
580
  'hostip_info' => __( 'External server:', 'woocommerce-jetpack' ) . ' ' . 'api.hostip.info',
581
  ),
582
- ),
583
-
584
  array(
585
  'title' => __( 'Price Rounding', 'woocommerce-jetpack' ),
586
  'desc' => __( 'If you choose to multiply price, set rounding options here.', 'woocommerce-jetpack' ),
@@ -593,17 +106,26 @@ class WCJ_Price_By_Country {
593
  'floor' => __( 'Round down', 'woocommerce-jetpack' ),
594
  'ceil' => __( 'Round up', 'woocommerce-jetpack' ),
595
  ),
596
- ),
 
 
 
 
 
 
 
 
 
597
 
598
- array( 'type' => 'sectionend', 'id' => 'wcj_price_by_country_options' ),
599
 
600
- array( 'title' => __( 'Country Groups', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_price_by_country_exchange_rate_options' ),
601
 
602
  array(
603
  'title' => __( 'Groups Number', 'woocommerce-jetpack' ),
604
  'id' => 'wcj_price_by_country_total_groups_number',
605
  'default' => 1,
606
- 'type' => 'number',
607
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
608
  'custom_attributes'
609
  => array_merge(
@@ -615,19 +137,58 @@ class WCJ_Price_By_Country {
615
  ),
616
  );
617
 
618
- for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
619
 
620
- $settings[] = array(
621
  'title' => __( 'Group', 'woocommerce-jetpack' ) . ' #' . $i,
622
  'desc' => __( 'Countries. List of comma separated country codes.<br>For country codes and predifined sets visit <a href="http://woojetpack.com/features/prices-and-currencies-by-customers-country">WooJetpack.com</a>', 'woocommerce-jetpack' ),
623
  'id' => 'wcj_price_by_country_exchange_rate_countries_group_' . $i,
624
  'default' => '',
625
  'type' => 'textarea',
626
  'css' => 'width:50%;min-width:300px;height:100px;',
627
- );
628
 
629
  $settings[] = array(
630
  'title' => '',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
631
  'desc' => __( 'Multiply Price by', 'woocommerce-jetpack' ),
632
  'id' => 'wcj_price_by_country_exchange_rate_group_' . $i,
633
  'default' => 1,
@@ -638,16 +199,33 @@ class WCJ_Price_By_Country {
638
  'min' => '0',
639
  ),
640
  );
641
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
  $settings[] = array(
643
  'title' => '',
644
- 'desc' => __( 'Currency', 'woocommerce-jetpack' ),
645
- 'id' => 'wcj_price_by_country_exchange_rate_currency_group_' . $i,
646
- 'default' => 'EUR',
647
- 'type' => 'select',
648
- 'options' => $this->currency_names_and_symbols,
649
- );
650
  }
 
651
  $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_price_by_country_exchange_rate_options' );
652
 
653
  return $settings;
21
  */
22
  public function __construct() {
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  // Main hooks
25
  if ( 'yes' === get_option( 'wcj_price_by_country_enabled' ) ) {
26
  if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
27
+ //wcj_log( 'WCJ_Price_By_Country: frontend' );
28
+ include_once( 'price-by-country/class-wcj-price-by-country-core.php' );
29
+ } else {
30
+ //wcj_log( 'WCJ_Price_By_Country: backend' );
31
+ include_once( 'price-by-country/class-wcj-exchange-rates.php' );
32
+ include_once( 'price-by-country/class-wcj-price-by-country-reports.php' );
33
+ if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled' ) ) {
34
+ include_once( 'price-by-country/class-wcj-price-by-country-local.php' );
35
+ }
36
  }
 
 
 
 
 
 
 
 
 
37
  }
38
+ include_once( 'price-by-country/class-wcj-exchange-rates-crons.php' );
39
 
40
  // Settings hooks
41
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
42
+ add_filter( 'wcj_settings_price_by_country', array( $this, 'get_settings' ), 100 );
43
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /**
47
  * add_enabled_option.
48
  */
59
 
60
  $settings = array(
61
 
62
+ array(
63
+ 'title' => __( 'Price by Country Options', 'woocommerce-jetpack' ),
64
+ 'type' => 'title',
65
  'desc' => __( 'Change product\'s price and currency by customer\'s country. Customer\'s country is detected automatically by IP.', 'woocommerce-jetpack' )
66
  . '<br>'
67
  . '<span style="color:gray;font-size:smaller;">'
68
+ //. wcj_get_ip_db_status_html()
69
+ . apply_filters( 'wcj_get_ip_db_status_html', '' )
70
+ . '<br>'
71
+ . ( ( ini_get( 'allow_url_fopen' ) ) ? 'allow_url_fopen: enabled' : 'allow_url_fopen: disabled' )
72
  . '</span>',
73
  'id' => 'wcj_price_by_country_options' ),
74
 
80
  'default' => 'no',
81
  'type' => 'checkbox',
82
  ),
83
+
84
  array(
85
  'title' => __( 'Country by IP Method', 'woocommerce-jetpack' ),
86
  'desc' => __( 'Select which method to use for detecting customers country by IP.', 'woocommerce-jetpack' ),
87
  'id' => 'wcj_price_by_country_by_ip_detection_type',
88
+ 'default' => 'internal_wc',
89
  'type' => 'select',
90
  'options' => array(
91
+ 'internal_wc' => __( 'Internal DB - since WooCommerce 2.3 (recommended)', 'woocommerce-jetpack' ),
92
+ 'internal' => __( 'Internal DB (depreciated)', 'woocommerce-jetpack' ),
93
  'hostip_info' => __( 'External server:', 'woocommerce-jetpack' ) . ' ' . 'api.hostip.info',
94
  ),
95
+ ),
96
+
97
  array(
98
  'title' => __( 'Price Rounding', 'woocommerce-jetpack' ),
99
  'desc' => __( 'If you choose to multiply price, set rounding options here.', 'woocommerce-jetpack' ),
106
  'floor' => __( 'Round down', 'woocommerce-jetpack' ),
107
  'ceil' => __( 'Round up', 'woocommerce-jetpack' ),
108
  ),
109
+ ),
110
+
111
+ array(
112
+ 'title' => __( 'Price by Country on per Product Basis', 'woocommerce-jetpack' ),
113
+ 'desc' => __( 'Enable', 'woocommerce-jetpack' ),
114
+ 'desc_tip' => __( 'This will add meta boxes in product edit.', 'woocommerce-jetpack' ),
115
+ 'id' => 'wcj_price_by_country_local_enabled',
116
+ 'default' => 'yes',
117
+ 'type' => 'checkbox',
118
+ ),
119
 
120
+ array( 'type' => 'sectionend', 'id' => 'wcj_price_by_country_options' ),
121
 
122
+ array( 'title' => __( 'Country Groups', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_price_by_country_country_groups_options' ),
123
 
124
  array(
125
  'title' => __( 'Groups Number', 'woocommerce-jetpack' ),
126
  'id' => 'wcj_price_by_country_total_groups_number',
127
  'default' => 1,
128
+ 'type' => 'number',
129
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
130
  'custom_attributes'
131
  => array_merge(
137
  ),
138
  );
139
 
140
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
141
 
142
+ $settings[] = array(
143
  'title' => __( 'Group', 'woocommerce-jetpack' ) . ' #' . $i,
144
  'desc' => __( 'Countries. List of comma separated country codes.<br>For country codes and predifined sets visit <a href="http://woojetpack.com/features/prices-and-currencies-by-customers-country">WooJetpack.com</a>', 'woocommerce-jetpack' ),
145
  'id' => 'wcj_price_by_country_exchange_rate_countries_group_' . $i,
146
  'default' => '',
147
  'type' => 'textarea',
148
  'css' => 'width:50%;min-width:300px;height:100px;',
149
+ );
150
 
151
  $settings[] = array(
152
  'title' => '',
153
+ 'desc' => __( 'Currency', 'woocommerce-jetpack' ),
154
+ 'id' => 'wcj_price_by_country_exchange_rate_currency_group_' . $i,
155
+ 'default' => 'EUR',
156
+ 'type' => 'select',
157
+ 'options' => wcj_get_currencies_names_and_symbols(),
158
+ );
159
+ }
160
+
161
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_price_by_country_country_groups_options' );
162
+
163
+ $settings[] = array( 'title' => __( 'Exchange Rates', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_price_by_country_exchange_rate_options' );
164
+
165
+ $settings[] = array(
166
+ 'title' => __( 'Exchange Rates Updates', 'woocommerce-jetpack' ),
167
+ //'desc' => __( '', 'woocommerce-jetpack' ),
168
+ //'desc_tip' => __( '', 'woocommerce-jetpack' ),
169
+ 'id' => 'wcj_price_by_country_auto_exchange_rates',
170
+ 'default' => 'manual',
171
+ 'type' => 'select',
172
+ 'options' => array(
173
+ 'manual' => __( 'Enter Rates Manually', 'woocommerce-jetpack' ),
174
+ 'hourly' => __( 'Automatically: Update Hourly', 'woocommerce-jetpack' ),
175
+ 'twicedaily' => __( 'Automatically: Update Twice Daily', 'woocommerce-jetpack' ),
176
+ 'daily' => __( 'Automatically: Update Daily', 'woocommerce-jetpack' ),
177
+ 'weekly' => __( 'Automatically: Update Weekly', 'woocommerce-jetpack' ),
178
+ 'minutely' => __( 'Automatically: Update Every Minute', 'woocommerce-jetpack' ),
179
+ ),
180
+ 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
181
+ 'custom_attributes'
182
+ => apply_filters( 'get_wc_jetpack_plus_message', '', 'disabled' ),
183
+ );
184
+
185
+ $currency_from = apply_filters( 'woocommerce_currency', get_option('woocommerce_currency') );
186
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
187
+
188
+ $currency_to = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i );
189
+
190
+ $settings[] = array(
191
+ 'title' => __( 'Group', 'woocommerce-jetpack' ) . ' #' . $i,
192
  'desc' => __( 'Multiply Price by', 'woocommerce-jetpack' ),
193
  'id' => 'wcj_price_by_country_exchange_rate_group_' . $i,
194
  'default' => 1,
199
  'min' => '0',
200
  ),
201
  );
202
+
203
+ $custom_attributes = array(
204
+ 'currency_from' => $currency_from,
205
+ 'currency_to' => $currency_to,
206
+ 'multiply_by_field_id' => 'wcj_price_by_country_exchange_rate_group_' . $i,
207
+ );
208
+ if ( $currency_from == $currency_to )
209
+ $custom_attributes['disabled'] = 'disabled';
210
+ $settings[] = array(
211
+ 'title' => '',
212
+ //'id' => 'wcj_price_by_country_exchange_rate_refresh_group_' . $i,
213
+ 'class' => 'exchage_rate_button',
214
+ 'type' => 'button',
215
+ 'css' => 'width:300px;',
216
+ 'value' => sprintf( __( '%s rate from Yahoo.com', 'woocommerce-jetpack' ), $currency_from . '/' . $currency_to ),
217
+ 'custom_attributes' => $custom_attributes,
218
+ );
219
+
220
  $settings[] = array(
221
  'title' => '',
222
+ 'desc' => __( 'Make empty price', 'woocommerce-jetpack' ),
223
+ 'id' => 'wcj_price_by_country_make_empty_price_group_' . $i,
224
+ 'default' => 'no',
225
+ 'type' => 'checkbox',
226
+ );
 
227
  }
228
+
229
  $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_price_by_country_exchange_rate_options' );
230
 
231
  return $settings;
includes/class-wcj-product-info.php CHANGED
@@ -78,11 +78,7 @@ class WCJ_Product_Info {
78
  $this->add_product_info_filters( 'archive' );
79
  $this->add_product_info_filters( 'single' );
80
 
81
- // Related products
82
- if ( 'yes' === get_option( 'wcj_product_info_related_products_enable' ) ) {
83
- add_filter( 'woocommerce_related_products_args', array( $this, 'related_products_limit' ), 100 );
84
- add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_limit_args' ), 100 );
85
- }
86
 
87
  // Shortcodes
88
  add_shortcode( 'wcj_sku', array( $this, 'shortcode_product_info_sku' ) );
@@ -118,7 +114,10 @@ class WCJ_Product_Info {
118
  add_shortcode( 'wcj_list_attribute', array( $this, 'shortcode_product_info_list_attribute' ) );
119
 
120
  // Depreciated
121
- add_shortcode( 'wcjp_list_attribute', array( $this, 'shortcode_wcjp_list_attribute' ) );
 
 
 
122
  }
123
 
124
  // Settings hooks
@@ -127,6 +126,13 @@ class WCJ_Product_Info {
127
  add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
128
  }
129
 
 
 
 
 
 
 
 
130
  /**
131
  * shortcode_wcjp_list_attribute.
132
  */
@@ -289,7 +295,7 @@ class WCJ_Product_Info {
289
  }
290
 
291
  /**
292
- * add_product_info_filters.
293
  */
294
  public function list_short_codes() {
295
  //return __( 'Available shortcodes are:', 'woocommerce-jetpack' ) . ' ' . implode( ", ", $this->product_info_shortcodes_array );
@@ -307,8 +313,9 @@ class WCJ_Product_Info {
307
  ( '' != get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter_priority' ) ) )
308
  add_action( get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter' ), array( $this, 'product_info' ), get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter_priority' ) );
309
  // More product Info
310
- if ( 'yes' === get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_enabled' ) )
311
  add_action( get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_filter' ), array( $this, 'more_product_info' ), get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_filter_priority' ) );
 
312
  }
313
 
314
  /**
@@ -353,8 +360,19 @@ class WCJ_Product_Info {
353
  * apply_product_info_short_codes.
354
  */
355
  public function apply_product_info_short_codes( $the_product_info, $remove_on_empty ) {
 
 
 
 
 
 
 
 
 
 
356
  if ( '' == $the_product_info )
357
  return;
 
358
  foreach ( $this->product_info_shortcodes_array as $product_info_short_code ) {
359
  if ( false !== strpos( $the_product_info, $product_info_short_code ) ) {
360
  // We found short code in the text
@@ -371,6 +389,7 @@ class WCJ_Product_Info {
371
  }
372
  }
373
  }
 
374
  echo apply_filters( 'the_content', $the_product_info );
375
  }
376
 
@@ -591,27 +610,7 @@ class WCJ_Product_Info {
591
  return false;
592
  }
593
 
594
- // RELATED PRODUCTS //
595
-
596
- /**
597
- * Change number of related products on product page.
598
- */
599
- function related_products_limit_args( $args ) {
600
- $args['posts_per_page'] = get_option( 'wcj_product_info_related_products_num' );
601
- $args['orderby'] = get_option( 'wcj_product_info_related_products_orderby' );
602
- $args['columns'] = get_option( 'wcj_product_info_related_products_columns' );
603
- return $args;
604
- }
605
-
606
- /**
607
- * Change number of related products on product page.
608
- */
609
- function related_products_limit( $args ) {
610
- $args['posts_per_page'] = get_option( 'wcj_product_info_related_products_num' );
611
- $args['orderby'] = get_option( 'wcj_product_info_related_products_orderby' );
612
- if ( get_option( 'wcj_product_info_related_products_orderby' ) != 'rand' ) $args['order'] = get_option( 'wcj_product_info_related_products_order' );
613
- return $args;
614
- }
615
 
616
  // ADMIN //
617
 
@@ -814,59 +813,36 @@ class WCJ_Product_Info {
814
  'id' => 'wcj_product_info_on_single_filter_priority',
815
  'default' => 10,
816
  'type' => 'number',
 
 
 
 
 
 
 
 
 
817
  ),
818
 
819
- array( 'type' => 'sectionend', 'id' => 'wcj_product_info_additional_options' ),
820
-
821
- // Related Products Options
822
- array( 'title' => __( 'Related Products Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => 'This section lets you change related products number.', 'id' => 'wcj_product_info_related_products_options' ),
823
-
824
- array(
825
- 'title' => __( 'Enable', 'woocommerce-jetpack' ),
826
- 'id' => 'wcj_product_info_related_products_enable',
827
- 'default' => 'no',
828
- 'type' => 'checkbox',
829
- ),
830
 
831
  array(
832
- 'title' => __( 'Related Products Number', 'woocommerce-jetpack' ),
833
- 'id' => 'wcj_product_info_related_products_num',
834
- 'default' => 3,
835
- 'type' => 'number',
836
- ),
837
 
838
  array(
839
- 'title' => __( 'Related Products Columns', 'woocommerce-jetpack' ),
840
- 'id' => 'wcj_product_info_related_products_columns',
841
  'default' => 3,
842
  'type' => 'number',
843
- ),
844
-
845
- array(
846
- 'title' => __( 'Order by', 'woocommerce-jetpack' ),
847
- 'id' => 'wcj_product_info_related_products_orderby',
848
- 'default' => 'rand',
849
- 'type' => 'select',
850
- 'options' => array(
851
- 'rand' => __( 'Random', 'woocommerce-jetpack' ),
852
- 'date' => __( 'Date', 'woocommerce-jetpack' ),
853
- 'title' => __( 'Title', 'woocommerce-jetpack' ),
854
- ),
855
- ),
856
 
857
- array(
858
- 'title' => __( 'Order', 'woocommerce-jetpack' ),
859
- 'desc_tip' => __( 'Ignored if order by "Random" is selected above.', 'woocommerce-jetpack' ),
860
- 'id' => 'wcj_product_info_related_products_order',
861
- 'default' => 'desc',
862
- 'type' => 'select',
863
- 'options' => array(
864
- 'asc' => __( 'Ascending', 'woocommerce-jetpack' ),
865
- 'desc' => __( 'Descending', 'woocommerce-jetpack' ),
866
- ),
867
- ),
868
-
869
- array( 'type' => 'sectionend', 'id' => 'wcj_product_info_related_products_options' ),
870
 
871
  ) );
872
 
78
  $this->add_product_info_filters( 'archive' );
79
  $this->add_product_info_filters( 'single' );
80
 
81
+
 
 
 
 
82
 
83
  // Shortcodes
84
  add_shortcode( 'wcj_sku', array( $this, 'shortcode_product_info_sku' ) );
114
  add_shortcode( 'wcj_list_attribute', array( $this, 'shortcode_product_info_list_attribute' ) );
115
 
116
  // Depreciated
117
+ add_shortcode( 'wcjp_list_attribute', array( $this, 'shortcode_wcjp_list_attribute' ) );
118
+
119
+ // Single Product Images
120
+ add_filter( 'woocommerce_product_thumbnails_columns', array( $this, 'change_product_thumbnails_columns_number' ) );
121
  }
122
 
123
  // Settings hooks
126
  add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
127
  }
128
 
129
+ /**
130
+ * change_product_thumbnails_columns.
131
+ */
132
+ public function change_product_thumbnails_columns_number( $columns_number ) {
133
+ return ( 'yes' === get_option( 'wcj_product_images_enabled', 'no' ) ) ? get_option( 'wcj_product_images_thumbnails_columns', 3 ) : $columns_number;
134
+ }
135
+
136
  /**
137
  * shortcode_wcjp_list_attribute.
138
  */
295
  }
296
 
297
  /**
298
+ * list_short_codes.
299
  */
300
  public function list_short_codes() {
301
  //return __( 'Available shortcodes are:', 'woocommerce-jetpack' ) . ' ' . implode( ", ", $this->product_info_shortcodes_array );
313
  ( '' != get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter_priority' ) ) )
314
  add_action( get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter' ), array( $this, 'product_info' ), get_option( 'wcj_product_info_on_' . $single_or_archive . '_filter_priority' ) );
315
  // More product Info
316
+ if ( 'yes' === get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_enabled' ) ) {
317
  add_action( get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_filter' ), array( $this, 'more_product_info' ), get_option( 'wcj_more_product_info_on_' . $single_or_archive . '_filter_priority' ) );
318
+ }
319
  }
320
 
321
  /**
360
  * apply_product_info_short_codes.
361
  */
362
  public function apply_product_info_short_codes( $the_product_info, $remove_on_empty ) {
363
+
364
+ $product_ids_to_exclude = get_option( 'wcj_product_info_products_to_exclude', '' );
365
+ if ( '' != $product_ids_to_exclude ) {
366
+ $product_ids_to_exclude = str_replace( ' ', '', $product_ids_to_exclude );
367
+ $product_ids_to_exclude = explode( ',', $product_ids_to_exclude );
368
+ $product_id = get_the_ID();
369
+ if ( ! empty( $product_ids_to_exclude ) && is_array( $product_ids_to_exclude ) && in_array( $product_id, $product_ids_to_exclude ) )
370
+ return;
371
+ }
372
+
373
  if ( '' == $the_product_info )
374
  return;
375
+
376
  foreach ( $this->product_info_shortcodes_array as $product_info_short_code ) {
377
  if ( false !== strpos( $the_product_info, $product_info_short_code ) ) {
378
  // We found short code in the text
389
  }
390
  }
391
  }
392
+
393
  echo apply_filters( 'the_content', $the_product_info );
394
  }
395
 
610
  return false;
611
  }
612
 
613
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
 
615
  // ADMIN //
616
 
813
  'id' => 'wcj_product_info_on_single_filter_priority',
814
  'default' => 10,
815
  'type' => 'number',
816
+ ),
817
+
818
+ array(
819
+ 'title' => __( 'Product IDs to exclude', 'woocommerce-jetpack' ),
820
+ 'desc_tip' => __( 'Comma separated list of product IDs to exclude from product info.', 'woocommerce-jetpack' ),
821
+ 'id' => 'wcj_product_info_products_to_exclude',
822
+ 'default' => '',
823
+ 'type' => 'text',
824
+ 'css' => 'min-width:300px;',
825
  ),
826
 
827
+ array( 'type' => 'sectionend', 'id' => 'wcj_product_info_additional_options' ),
828
+
829
+ array( 'title' => __( 'Product Images', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_product_images_options' ),
 
 
 
 
 
 
 
 
830
 
831
  array(
832
+ 'title' => __( 'Enable', 'woocommerce-jetpack' ),
833
+ 'id' => 'wcj_product_images_enabled',
834
+ 'default' => 'no',
835
+ 'type' => 'checkbox',
836
+ ),
837
 
838
  array(
839
+ 'title' => __( 'Single Product Thumbnails Columns', 'woocommerce-jetpack' ),
840
+ 'id' => 'wcj_product_images_thumbnails_columns',
841
  'default' => 3,
842
  'type' => 'number',
843
+ ),
 
 
 
 
 
 
 
 
 
 
 
 
844
 
845
+ array( 'type' => 'sectionend', 'id' => 'wcj_product_images_options' ),
 
 
 
 
 
 
 
 
 
 
 
 
846
 
847
  ) );
848
 
includes/class-wcj-product-input-fields.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Product Input Fields
4
+ *
5
+ * The WooCommerce Jetpack Product Input Fields class.
6
+ *
7
+ * @class WCJ_Product_Input_Fields
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Product_Input_Fields' ) ) :
16
+
17
+ class WCJ_Product_Input_Fields {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ include_once( 'input-fields/class-wcj-product-input-fields-abstract.php' );
25
+
26
+ // Main hooks
27
+ if ( 'yes' === get_option( 'wcj_product_input_fields_enabled' ) ) {
28
+
29
+ include_once( 'input-fields/class-wcj-product-input-fields-global.php' );
30
+ include_once( 'input-fields/class-wcj-product-input-fields-per-product.php' );
31
+
32
+ if ( 'yes' === get_option( 'wcj_product_input_fields_global_enabled' ) || 'yes' === get_option( 'wcj_product_input_fields_local_enabled' ) ) {
33
+ add_action( 'wp_enqueue_scripts' , array( $this, 'enqueue_scripts' ) );
34
+ add_action( 'init', array( $this, 'register_scripts' ) );
35
+ }
36
+ }
37
+
38
+ // Settings hooks
39
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
40
+ add_filter( 'wcj_settings_product_input_fields', array( $this, 'get_settings' ), 100 );
41
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
42
+ }
43
+
44
+ /**
45
+ * register_script.
46
+ */
47
+ public function register_scripts() {
48
+ //wp_register_script( 'wcj-product-input-fields', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/product-input-fields.js', array( 'jquery' ), false, true );
49
+ wp_register_script( 'wcj-product-input-fields', WCJ()->plugin_url() . '/includes/js/product-input-fields.js', array( 'jquery' ), false, true );
50
+ }
51
+
52
+ /**
53
+ * enqueue_checkout_script.
54
+ */
55
+ public function enqueue_scripts() {
56
+ if( ! is_product() ) return;
57
+ wp_enqueue_script( 'wcj-product-input-fields' );
58
+ }
59
+
60
+ /**
61
+ * get_options.
62
+ */
63
+ public function get_options() {
64
+
65
+ $product_input_fields_abstract = new WCJ_Product_Input_Fields_Abstract();
66
+
67
+ $product_input_fields_abstract->scope = 'global';
68
+
69
+ return $product_input_fields_abstract->get_options();
70
+
71
+ /*$options = array(
72
+ array(
73
+ 'id' => 'wcj_product_input_fields_enabled_' . $this->scope . '_',
74
+ 'title' => __( 'Enabled', 'woocommerce-jetpack' ),
75
+ 'type' => 'checkbox',
76
+ 'default' => 'no',
77
+ ),
78
+ array(
79
+ 'id' => 'wcj_product_input_fields_required_' . $this->scope . '_',
80
+ 'title' => __( 'Required', 'woocommerce-jetpack' ),
81
+ 'type' => 'checkbox',
82
+ 'default' => 'no',
83
+ ),
84
+ array(
85
+ 'id' => 'wcj_product_input_fields_title_' . $this->scope . '_',
86
+ 'title' => __( 'Title', 'woocommerce-jetpack' ),
87
+ 'type' => 'textarea',
88
+ 'default' => '',
89
+ ),
90
+ array(
91
+ 'id' => 'wcj_product_input_fields_placeholder_' . $this->scope . '_',
92
+ 'title' => __( 'Placeholder', 'woocommerce-jetpack' ),
93
+ 'type' => 'textarea',
94
+ 'default' => '',
95
+ ),
96
+ array(
97
+ 'id' => 'wcj_product_input_fields_required_message_' . $this->scope . '_',
98
+ 'title' => __( 'Message on required', 'woocommerce-jetpack' ),
99
+ 'type' => 'textarea',
100
+ 'default' => '',
101
+ ),
102
+ );
103
+ return $options;*/
104
+ }
105
+
106
+ /**
107
+ * add_enabled_option.
108
+ */
109
+ public function add_enabled_option( $settings ) {
110
+ $all_settings = $this->get_settings();
111
+ $settings[] = $all_settings[1];
112
+ return $settings;
113
+ }
114
+
115
+ /**
116
+ * get_settings.
117
+ */
118
+ function get_settings() {
119
+
120
+ $settings = array(
121
+
122
+ array( 'title' => __( 'Product Input Fields Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => __( 'Product Input Fields.', 'woocommerce-jetpack' ), 'id' => 'wcj_product_input_fields_options' ),
123
+
124
+ array(
125
+ 'title' => __( 'Product Input Fields', 'woocommerce-jetpack' ),
126
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
127
+ 'desc_tip' => __( 'Product Input Fields.', 'woocommerce-jetpack' ),
128
+ 'id' => 'wcj_product_input_fields_enabled',
129
+ 'default' => 'no',
130
+ 'type' => 'checkbox',
131
+ ),
132
+
133
+ array( 'type' => 'sectionend', 'id' => 'wcj_product_input_fields_options' ),
134
+
135
+ array(
136
+ 'title' => __( 'Product Input Fields per Product Options', 'woocommerce-jetpack' ),
137
+ 'type' => 'title',
138
+ 'desc' => __( 'Add custom input fields to product\'s single page for customer to fill before adding product to cart.', 'woocommerce-jetpack' )
139
+ . ' '
140
+ . __( 'When enabled this module will add "Product Input Fields" tab to product\'s "Edit" page.', 'woocommerce-jetpack' ),
141
+ 'id' => 'wcj_product_input_fields_local_options',
142
+ ),
143
+
144
+ array(
145
+ 'title' => __( 'Product Input Fields - per Product', 'woocommerce-jetpack' ),
146
+ 'desc' => '<strong>' . __( 'Enable', 'woocommerce-jetpack' ) . '</strong>',
147
+ 'desc_tip' => __( 'Add custom input field on per product basis.', 'woocommerce-jetpack' ),
148
+ 'id' => 'wcj_product_input_fields_local_enabled',
149
+ 'default' => 'no',
150
+ 'type' => 'checkbox',
151
+ ),
152
+
153
+ array(
154
+ 'title' => __( 'Default Number of Product Input Fields per Product', 'woocommerce-jetpack' ),
155
+ 'id' => 'wcj_product_input_fields_local_total_number_default',
156
+ 'desc_tip' => __( 'You will be able to change this number later as well as define the fields, for each product individually, in product\'s "Edit".', 'woocommerce-jetpack' ),
157
+ 'default' => 1,
158
+ 'type' => 'number',
159
+ 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
160
+ 'custom_attributes'
161
+ => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
162
+ ),
163
+
164
+ array(
165
+ 'type' => 'sectionend',
166
+ 'id' => 'wcj_product_input_fields_local_options',
167
+ ),
168
+
169
+ array(
170
+ 'title' => __( 'Product Input Fields Global Options', 'woocommerce-jetpack' ),
171
+ 'type' => 'title',
172
+ 'desc' => __( 'Add custom input fields to product\'s single page for customer to fill before adding product to cart.', 'woocommerce-jetpack' ),
173
+ 'id' => 'wcj_product_input_fields_global_options',
174
+ ),
175
+
176
+ array(
177
+ 'title' => __( 'Product Input Fields - All Products', 'woocommerce-jetpack' ),
178
+ 'desc' => '<strong>' . __( 'Enable', 'woocommerce-jetpack' ) . '</strong>',
179
+ 'desc_tip' => __( 'Add custom input fields to all products.', 'woocommerce-jetpack' ),
180
+ 'id' => 'wcj_product_input_fields_global_enabled',
181
+ 'default' => 'no',
182
+ 'type' => 'checkbox',
183
+ ),
184
+
185
+ array(
186
+ 'title' => __( 'Product Input Fields Number', 'woocommerce-jetpack' ),
187
+ 'desc_tip' => __( 'Click "Save changes" after you change this number.', 'woocommerce-jetpack' ),
188
+ 'id' => 'wcj_product_input_fields_global_total_number',
189
+ 'default' => 1,
190
+ 'type' => 'number',
191
+ 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
192
+ 'custom_attributes'
193
+ => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
194
+ ),
195
+ );
196
+
197
+ $options = $this->get_options();
198
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_product_input_fields_global_total_number', 1 ) ); $i++ ) {
199
+ foreach( $options as $option ) {
200
+ $settings[] =
201
+ array(
202
+ 'title' => ( 'wcj_product_input_fields_enabled_global_' === $option['id'] ) ? __( 'Product Input Field', 'woocommerce-jetpack' ) . ' #' . $i : '',
203
+ 'desc' => $option['title'],
204
+ 'id' => $option['id'] . $i,
205
+ 'default' => $option['default'],
206
+ 'type' => $option['type'],
207
+ 'css' => 'width:30%;min-width:300px;',
208
+ );
209
+ }
210
+ }
211
+
212
+ $settings[] =
213
+ array(
214
+ 'type' => 'sectionend',
215
+ 'id' => 'wcj_product_input_fields_global_options',
216
+ );
217
+
218
+ return $settings;
219
+ }
220
+
221
+ /**
222
+ * settings_section.
223
+ */
224
+ function settings_section( $sections ) {
225
+ $sections['product_input_fields'] = __( 'Product Input Fields', 'woocommerce-jetpack' );
226
+ return $sections;
227
+ }
228
+ }
229
+
230
+ endif;
231
+
232
+ return new WCJ_Product_Input_Fields();
includes/class-wcj-related-products.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Related Products
4
+ *
5
+ * The WooCommerce Jetpack Related Products class.
6
+ *
7
+ * @class WCJ_Related_Products
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Related_Products' ) ) :
16
+
17
+ class WCJ_Related_Products {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ // Main hooks
25
+ if ( 'yes' === get_option( 'wcj_related_products_enabled' ) ) {
26
+
27
+ add_filter( 'woocommerce_related_products_args', array( $this, 'related_products_limit' ), 100 );
28
+
29
+ add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_limit_args' ), 100 );
30
+
31
+ if ( 'no' === get_option( 'wcj_product_info_related_products_relate_by_category' ) ) {
32
+ apply_filters( 'woocommerce_product_related_posts_relate_by_category', false );
33
+ }
34
+
35
+ if ( 'no' === get_option( 'wcj_product_info_related_products_relate_by_tag' ) ) {
36
+ apply_filters( 'woocommerce_product_related_posts_relate_by_tag', false );
37
+ }
38
+ }
39
+
40
+ // Settings hooks
41
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
42
+ add_filter( 'wcj_settings_related_products', array( $this, 'get_settings' ), 100 );
43
+ add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
44
+ }
45
+
46
+ /**
47
+ * add_enabled_option.
48
+ */
49
+ public function add_enabled_option( $settings ) {
50
+ $all_settings = $this->get_settings();
51
+ $settings[] = $all_settings[1];
52
+ return $settings;
53
+ }
54
+
55
+ // RELATED PRODUCTS //
56
+
57
+ /**
58
+ * Change number of related products on product page.
59
+ */
60
+ function related_products_limit_args( $args ) {
61
+ $args['posts_per_page'] = get_option( 'wcj_product_info_related_products_num' );
62
+ $args['orderby'] = get_option( 'wcj_product_info_related_products_orderby' );
63
+ $args['columns'] = get_option( 'wcj_product_info_related_products_columns' );
64
+ return $args;
65
+ }
66
+
67
+ /**
68
+ * Change number of related products on product page.
69
+ */
70
+ function related_products_limit( $args ) {
71
+ $args['posts_per_page'] = get_option( 'wcj_product_info_related_products_num' );
72
+ $args['orderby'] = get_option( 'wcj_product_info_related_products_orderby' );
73
+ if ( get_option( 'wcj_product_info_related_products_orderby' ) != 'rand' ) $args['order'] = get_option( 'wcj_product_info_related_products_order' );
74
+ return $args;
75
+ }
76
+
77
+ /**
78
+ * get_settings.
79
+ */
80
+ function get_settings() {
81
+
82
+ $settings = array(
83
+
84
+ array( 'title' => __( 'Related Products Options', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_product_info_related_products_options' ),
85
+
86
+ array(
87
+ 'title' => __( 'Related Products', 'woocommerce-jetpack' ),
88
+ 'desc' => '<strong>' . __( 'Enable Module', 'woocommerce-jetpack' ) . '</strong>',
89
+ 'desc_tip' => __( 'Change displayed related products number, columns, order, relate by tag and/or category.', 'woocommerce-jetpack' ) . '</strong>',
90
+ 'id' => 'wcj_related_products_enabled',//'wcj_product_info_related_products_enable'
91
+ 'default' => 'no',
92
+ 'type' => 'checkbox',
93
+ ),
94
+
95
+ array(
96
+ 'title' => __( 'Related Products Number', 'woocommerce-jetpack' ),
97
+ 'id' => 'wcj_product_info_related_products_num',
98
+ 'default' => 3,
99
+ 'type' => 'number',
100
+ ),
101
+
102
+ array(
103
+ 'title' => __( 'Related Products Columns', 'woocommerce-jetpack' ),
104
+ 'id' => 'wcj_product_info_related_products_columns',
105
+ 'default' => 3,
106
+ 'type' => 'number',
107
+ ),
108
+
109
+ array(
110
+ 'title' => __( 'Order by', 'woocommerce-jetpack' ),
111
+ 'id' => 'wcj_product_info_related_products_orderby',
112
+ 'default' => 'rand',
113
+ 'type' => 'select',
114
+ 'options' => array(
115
+ 'rand' => __( 'Random', 'woocommerce-jetpack' ),
116
+ 'date' => __( 'Date', 'woocommerce-jetpack' ),
117
+ 'title' => __( 'Title', 'woocommerce-jetpack' ),
118
+ ),
119
+ ),
120
+
121
+ array(
122
+ 'title' => __( 'Order', 'woocommerce-jetpack' ),
123
+ 'desc_tip' => __( 'Ignored if order by "Random" is selected above.', 'woocommerce-jetpack' ),
124
+ 'id' => 'wcj_product_info_related_products_order',
125
+ 'default' => 'desc',
126
+ 'type' => 'select',
127
+ 'options' => array(
128
+ 'asc' => __( 'Ascending', 'woocommerce-jetpack' ),
129
+ 'desc' => __( 'Descending', 'woocommerce-jetpack' ),
130
+ ),
131
+ ),
132
+
133
+ array(
134
+ 'title' => __( 'Relate by Category', 'woocommerce-jetpack' ),
135
+ 'id' => 'wcj_product_info_related_products_relate_by_category',
136
+ 'default' => 'yes',
137
+ 'type' => 'checkbox',
138
+ ),
139
+
140
+ array(
141
+ 'title' => __( 'Relate by Tag', 'woocommerce-jetpack' ),
142
+ 'id' => 'wcj_product_info_related_products_relate_by_tag',
143
+ 'default' => 'yes',
144
+ 'type' => 'checkbox',
145
+ ),
146
+
147
+ array( 'type' => 'sectionend', 'id' => 'wcj_product_info_related_products_options' ),
148
+ );
149
+
150
+ return $settings;
151
+ }
152
+
153
+ /**
154
+ * settings_section.
155
+ */
156
+ function settings_section( $sections ) {
157
+ $sections['related_products'] = __( 'Related Products', 'woocommerce-jetpack' );
158
+ return $sections;
159
+ }
160
+ }
161
+
162
+ endif;
163
+
164
+ return new WCJ_Related_Products();
includes/class-wcj-sku.php CHANGED
@@ -19,13 +19,14 @@ class WCJ_SKU {
19
  /**
20
  * Constructor.
21
  */
22
- public function __construct() {
23
-
24
  $the_priority = 100;
25
  // Main hooks
26
  if ( 'yes' === get_option( 'wcj_sku_enabled' ) ) {
27
  add_filter( 'wcj_tools_tabs', array( $this, 'add_sku_tool_tab' ), $the_priority );
28
  add_action( 'wcj_tools_sku', array( $this, 'create_sku_tool' ), $the_priority );
 
29
  add_action( 'wp_insert_post', array( $this, 'set_product_sku' ), $the_priority, 3 );
30
  }
31
  add_action( 'wcj_tools_dashboard', array( $this, 'add_sku_tool_info_to_tools_dashboard' ), $the_priority );
@@ -39,8 +40,10 @@ class WCJ_SKU {
39
  /**
40
  * set_sku_with_variable.
41
  */
42
- public function set_sku_with_variable( $product_id, $is_preview ) {
43
- $this->set_sku( $product_id, $product_id, '', $is_preview );
 
 
44
  // Handling variable products
45
  $variation_handling = apply_filters( 'wcj_get_option_filter', 'as_variable', get_option( 'wcj_sku_variations_handling', 'as_variable' ) );
46
  $product = wc_get_product( $product_id );
@@ -71,7 +74,8 @@ class WCJ_SKU {
71
  /**
72
  * set_sku.
73
  */
74
- public function set_sku( $product_id, $sku_number, $variation_suffix, $is_preview ) {
 
75
  $the_sku = sprintf( '%s%0' . get_option( 'wcj_sku_minimum_number_length', 0 ) . 'd%s%s',
76
  get_option( 'wcj_sku_prefix', '' ),
77
  $sku_number,
@@ -80,37 +84,52 @@ class WCJ_SKU {
80
 
81
  if ( $is_preview ) {
82
  echo '<tr>' .
 
83
  '<td>' . get_the_title( $product_id ) . '</td>' .
84
  '<td>' . $the_sku . '</td>' .
85
  '</tr>';
86
  }
87
  else
88
- update_post_meta( $product_id, '_' . 'sku', $the_sku );
89
  }
90
 
91
  /**
92
  * set_all_sku.
93
  */
94
- public function set_all_sku( $is_preview ) {
95
- $args = array(
96
- 'post_type' => 'product',
97
- 'post_status' => 'any',
98
- 'posts_per_page' => -1,
99
- );
100
- $loop = new WP_Query( $args );
101
- while ( $loop->have_posts() ) : $loop->the_post();
102
- $this->set_sku_with_variable( $loop->post->ID, $is_preview );
103
-
104
- endwhile;
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
108
  * set_product_sku.
109
  */
110
- public function set_product_sku( $post_ID, $post, $update ) {
 
111
  if ( 'product' != $post->post_type ) {
112
  return;
113
  }
 
114
  if ( false === $update ) {
115
  $this->set_sku_with_variable( $post_ID, false );
116
  }
@@ -119,7 +138,7 @@ class WCJ_SKU {
119
  /**
120
  * add_sku_tool_tab.
121
  */
122
- public function add_sku_tool_tab( $tabs ) {
123
  $tabs[] = array(
124
  'id' => 'sku',
125
  'title' => __( 'Autogenerate SKUs', 'woocommerce-jetpack' ),
@@ -130,20 +149,23 @@ class WCJ_SKU {
130
  /**
131
  * create_sku_tool
132
  */
133
- public function create_sku_tool() {
134
  $result_message = '';
135
- if ( isset( $_POST['set_sku'] ) || isset( $_POST['preview_sku'] ) ) {
136
- $is_preview = ( isset( $_POST['preview_sku'] ) ) ? true : false;
 
137
 
 
138
  $preview_html = '<table class="widefat" style="width:50%; min-width: 300px;">';
139
  $preview_html .= '<tr>' .
 
140
  '<th>' . __( 'Product', 'woocommerce-jetpack' ) . '</th>' .
141
  '<th>' . __( 'SKU', 'woocommerce-jetpack' ) . '</th>' .
142
  '</tr>';
143
  ob_start();
144
  $this->set_all_sku( $is_preview );
145
  $preview_html .= ob_get_clean();
146
- $preview_html .= '<table>';
147
  $result_message = '<p><div class="updated"><p><strong>' . __( 'SKUs generated and set successfully!', 'woocommerce-jetpack' ) . '</strong></p></div></p>';
148
  }
149
  ?><div>
@@ -161,7 +183,7 @@ class WCJ_SKU {
161
  /**
162
  * add_sku_tool_info_to_tools_dashboard.
163
  */
164
- public function add_sku_tool_info_to_tools_dashboard() {
165
  echo '<tr>';
166
  if ( 'yes' === get_option( 'wcj_sku_enabled') )
167
  $is_enabled = '<span style="color:green;font-style:italic;">' . __( 'enabled', 'woocommerce-jetpack' ) . '</span>';
@@ -176,7 +198,7 @@ class WCJ_SKU {
176
  /**
177
  * add_enabled_option.
178
  */
179
- public function add_enabled_option( $settings ) {
180
  $all_settings = $this->get_settings();
181
  $settings[] = $all_settings[1];
182
  return $settings;
@@ -237,7 +259,7 @@ class WCJ_SKU {
237
  'options' => array(
238
  'as_variable' => __( 'SKU same as parent\'s product', 'woocommerce-jetpack' ),
239
  'as_variation' => __( 'Generate different SKU for each variation', 'woocommerce-jetpack' ),
240
- 'as_variable_with_suffix' => __( 'SKU same as parent\'s product + variation suffix', 'woocommerce-jetpack' ),
241
  ),
242
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
243
  'custom_attributes'
19
  /**
20
  * Constructor.
21
  */
22
+ function __construct() {
23
+
24
  $the_priority = 100;
25
  // Main hooks
26
  if ( 'yes' === get_option( 'wcj_sku_enabled' ) ) {
27
  add_filter( 'wcj_tools_tabs', array( $this, 'add_sku_tool_tab' ), $the_priority );
28
  add_action( 'wcj_tools_sku', array( $this, 'create_sku_tool' ), $the_priority );
29
+
30
  add_action( 'wp_insert_post', array( $this, 'set_product_sku' ), $the_priority, 3 );
31
  }
32
  add_action( 'wcj_tools_dashboard', array( $this, 'add_sku_tool_info_to_tools_dashboard' ), $the_priority );
40
  /**
41
  * set_sku_with_variable.
42
  */
43
+ function set_sku_with_variable( $product_id, $is_preview ) {
44
+
45
+ $this->set_sku( $product_id, $product_id, '', $is_preview );
46
+
47
  // Handling variable products
48
  $variation_handling = apply_filters( 'wcj_get_option_filter', 'as_variable', get_option( 'wcj_sku_variations_handling', 'as_variable' ) );
49
  $product = wc_get_product( $product_id );
74
  /**
75
  * set_sku.
76
  */
77
+ function set_sku( $product_id, $sku_number, $variation_suffix, $is_preview ) {
78
+
79
  $the_sku = sprintf( '%s%0' . get_option( 'wcj_sku_minimum_number_length', 0 ) . 'd%s%s',
80
  get_option( 'wcj_sku_prefix', '' ),
81
  $sku_number,
84
 
85
  if ( $is_preview ) {
86
  echo '<tr>' .
87
+ '<td>' . $this->product_counter++ . '</td>' .
88
  '<td>' . get_the_title( $product_id ) . '</td>' .
89
  '<td>' . $the_sku . '</td>' .
90
  '</tr>';
91
  }
92
  else
93
+ update_post_meta( $product_id, '_' . 'sku', $the_sku );
94
  }
95
 
96
  /**
97
  * set_all_sku.
98
  */
99
+ function set_all_sku( $is_preview ) {
100
+
101
+ $limit = 1000;
102
+ $offset = 0;
103
+
104
+ while ( TRUE ) {
105
+ $posts = new WP_Query( array(
106
+ 'posts_per_page' => $limit,
107
+ 'offset' => $offset,
108
+ 'post_type' => 'product',
109
+ 'post_status' => 'any',
110
+ ));
111
+
112
+ if ( ! $posts->have_posts() ) break;
113
+
114
+ while ( $posts->have_posts() ) {
115
+ $posts->the_post();
116
+
117
+ $this->set_sku_with_variable( $posts->post->ID, $is_preview );
118
+ }
119
+
120
+ $offset += $limit;
121
+ }
122
  }
123
 
124
  /**
125
  * set_product_sku.
126
  */
127
+ function set_product_sku( $post_ID, $post, $update ) {
128
+
129
  if ( 'product' != $post->post_type ) {
130
  return;
131
  }
132
+
133
  if ( false === $update ) {
134
  $this->set_sku_with_variable( $post_ID, false );
135
  }
138
  /**
139
  * add_sku_tool_tab.
140
  */
141
+ function add_sku_tool_tab( $tabs ) {
142
  $tabs[] = array(
143
  'id' => 'sku',
144
  'title' => __( 'Autogenerate SKUs', 'woocommerce-jetpack' ),
149
  /**
150
  * create_sku_tool
151
  */
152
+ function create_sku_tool() {
153
  $result_message = '';
154
+ $is_preview = ( isset( $_POST['preview_sku'] ) ) ? true : false;
155
+
156
+ if ( isset( $_POST['set_sku'] ) || isset( $_POST['preview_sku'] ) ) {
157
 
158
+ $this->product_counter = 1;
159
  $preview_html = '<table class="widefat" style="width:50%; min-width: 300px;">';
160
  $preview_html .= '<tr>' .
161
+ '<th></th>' .
162
  '<th>' . __( 'Product', 'woocommerce-jetpack' ) . '</th>' .
163
  '<th>' . __( 'SKU', 'woocommerce-jetpack' ) . '</th>' .
164
  '</tr>';
165
  ob_start();
166
  $this->set_all_sku( $is_preview );
167
  $preview_html .= ob_get_clean();
168
+ $preview_html .= '</table>';
169
  $result_message = '<p><div class="updated"><p><strong>' . __( 'SKUs generated and set successfully!', 'woocommerce-jetpack' ) . '</strong></p></div></p>';
170
  }
171
  ?><div>
183
  /**
184
  * add_sku_tool_info_to_tools_dashboard.
185
  */
186
+ function add_sku_tool_info_to_tools_dashboard() {
187
  echo '<tr>';
188
  if ( 'yes' === get_option( 'wcj_sku_enabled') )
189
  $is_enabled = '<span style="color:green;font-style:italic;">' . __( 'enabled', 'woocommerce-jetpack' ) . '</span>';
198
  /**
199
  * add_enabled_option.
200
  */
201
+ function add_enabled_option( $settings ) {
202
  $all_settings = $this->get_settings();
203
  $settings[] = $all_settings[1];
204
  return $settings;
259
  'options' => array(
260
  'as_variable' => __( 'SKU same as parent\'s product', 'woocommerce-jetpack' ),
261
  'as_variation' => __( 'Generate different SKU for each variation', 'woocommerce-jetpack' ),
262
+ 'as_variable_with_suffix' => __( 'SKU same as parent\'s product + variation letter suffix', 'woocommerce-jetpack' ),
263
  ),
264
  'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
265
  'custom_attributes'
includes/classes/class-wcj-invoice.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Invoice
4
+ *
5
+ * The WooCommerce Jetpack Invoice class.
6
+ *
7
+ * @class WCJ_Invoice
8
+ * @version 2.1.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Invoice' ) ) :
16
+
17
+ class WCJ_Invoice {
18
+
19
+ public $order_id;
20
+ public $invoice_type;
21
+
22
+ /**
23
+ * Constructor.
24
+ */
25
+ public function __construct( $order_id, $invoice_type ) {
26
+ $this->order_id = $order_id;
27
+ $this->invoice_type = $invoice_type;
28
+ }
29
+
30
+ /**
31
+ * is_created.
32
+ */
33
+ function is_created() {
34
+ return ( '' != get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', true ) ) ? true : false;
35
+ }
36
+
37
+ /**
38
+ * delete.
39
+ */
40
+ function delete() {
41
+ update_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_number_id', 0 );
42
+ update_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_number', 0 );
43
+ update_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', '' );
44
+ }
45
+
46
+ /**
47
+ * create.
48
+ */
49
+ function create( $date = '' ) {
50
+ $order_id = $this->order_id;
51
+ $invoice_type = $this->invoice_type;
52
+ //if ( '' == get_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', true ) ) {
53
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_sequential_enabled' ) ) {
54
+ $the_invoice_number = get_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', 1 );
55
+ update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', ( $the_invoice_number + 1 ) );
56
+ } else {
57
+ $the_invoice_number = $order_id;
58
+ }
59
+ $the_date = ( '' == $date ) ? time() : $date;
60
+ update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number_id', $the_invoice_number );
61
+ update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', $this->get_invoice_full_number( $the_invoice_number ) );
62
+ update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_date', $the_date );
63
+ //}
64
+ }
65
+
66
+ /**
67
+ * get_file_name.
68
+ */
69
+ function get_file_name() {
70
+ $the_file_name = do_shortcode( get_option( 'wcj_invoicing_' . $this->invoice_type . '_file_name', 'invoice-' . $this->order_id ) . '.pdf' );
71
+ if ( '' == $the_file_name ) $the_file_name = 'invoice';
72
+ return apply_filters( 'wcj_get_' . $this->invoice_type . '_file_name', $the_file_name, $this->order_id );
73
+ }
74
+
75
+ /**
76
+ * get_invoice_date.
77
+ */
78
+ function get_invoice_date() {
79
+ $the_date = get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_date', true );
80
+ return apply_filters( 'wcj_get_' . $this->invoice_type . '_date', $the_date, $this->order_id );
81
+ }
82
+
83
+ /**
84
+ * get_invoice_number.
85
+ */
86
+ function get_invoice_number() {
87
+ $the_number = get_post_meta( $this->order_id, '_wcj_invoicing_' . $this->invoice_type . '_number', true );
88
+ //$the_number = $this->order_id;
89
+ return apply_filters( 'wcj_get_' . $this->invoice_type . '_number', $the_number, $this->order_id );
90
+ }
91
+
92
+ /**
93
+ * get_invoice_full_number.
94
+ */
95
+ private function get_invoice_full_number( $the_number ) {
96
+ /*$the_number = $this->get_invoice_number();
97
+ if ( 0 == $the_number ) {
98
+ return '';//'N/A';
99
+ }*/
100
+ $the_prefix = get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_prefix' );
101
+ $the_suffix = get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_suffix' );
102
+ return do_shortcode( sprintf( '%s%0' . get_option( 'wcj_invoicing_' . $this->invoice_type . '_numbering_counter_width', 0 ). 'd%s',
103
+ $the_prefix,
104
+ $the_number,
105
+ $the_suffix ) );
106
+ }
107
+ }
108
+
109
+ endif;
includes/classes/class-wcj-pdf-invoice.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoice
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoice class.
6
+ *
7
+ * @class WCJ_PDF_Invoice
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoice' ) ) :
16
+
17
+ class WCJ_PDF_Invoice extends WCJ_Invoice {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct( $order_id, $invoice_type ) {
23
+ parent::__construct( $order_id, $invoice_type );
24
+ }
25
+
26
+ function prepare_pdf() {
27
+
28
+ $invoice_type = $this->invoice_type;
29
+
30
+ // Include the main TCPDF library
31
+ require_once( WCJ()->plugin_path() . '/includes/lib/tcpdf_min/tcpdf.php' );
32
+
33
+ // Create new PDF document
34
+ $pdf = new TCPDF( get_option( 'wcj_invoicing_' . $invoice_type . '_page_orientation', 'P' ), PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false );
35
+
36
+ // Set document information
37
+ $pdf->SetCreator( PDF_CREATOR );
38
+ //$pdf->SetAuthor( 'Algoritmika Ltd.' );
39
+ $pdf->SetTitle( 'Invoice' );
40
+ $pdf->SetSubject( 'Invoice PDF' );
41
+ $pdf->SetKeywords( 'invoice, PDF' );
42
+
43
+ // Header - set default header data
44
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_header_enabled' ) ) {
45
+ $the_logo = '';
46
+ $the_logo_width_mm = 0;
47
+ if ( '' != get_option( 'wcj_invoicing_' . $invoice_type . '_header_image' ) ) {
48
+ $the_logo = parse_url( get_option( 'wcj_invoicing_' . $invoice_type . '_header_image' ) );
49
+ $the_logo = $the_logo['path'];
50
+ $the_logo_width_mm = get_option( 'wcj_invoicing_' . $invoice_type . '_header_image_width_mm' );
51
+ }
52
+ $pdf->SetHeaderData(
53
+ $the_logo,
54
+ $the_logo_width_mm,
55
+ do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_header_title_text' ) ),
56
+ do_shortcode( get_option( 'wcj_invoicing_' . $invoice_type . '_header_text' ) . apply_filters( 'wcj_get_option_filter', ' - ' . 'powered by ' . 'woojetpack' . '.com', '' ) ),
57
+ wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_header_text_color' ) ),
58
+ wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_header_line_color' ) ) );
59
+ } else {
60
+ $pdf->SetPrintHeader( false );
61
+ }
62
+
63
+ // Footer
64
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_footer_enabled' ) ) {
65
+ $pdf->setFooterData(
66
+ wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_text_color' ) ),
67
+ wcj_hex2rgb( get_option( 'wcj_invoicing_' . $invoice_type . '_footer_line_color' ) ) );
68
+ } else {
69
+ $pdf->SetPrintFooter( false );
70
+ }
71
+
72
+ // Set Header and Footer fonts
73
+ $pdf->setHeaderFont( Array( PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN ) );
74
+ $pdf->setFooterFont( Array( PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA ) );
75
+
76
+ // Set default monospaced font
77
+ $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
78
+
79
+ // Set margins
80
+ $pdf->SetMargins(
81
+ get_option( 'wcj_invoicing_' . $invoice_type . '_margin_left' ),
82
+ get_option( 'wcj_invoicing_' . $invoice_type . '_margin_top' ),
83
+ get_option( 'wcj_invoicing_' . $invoice_type . '_margin_right' ) );
84
+ $pdf->SetHeaderMargin( get_option( 'wcj_invoicing_' . $invoice_type . '_margin_header' ) );
85
+ $pdf->SetFooterMargin( get_option( 'wcj_invoicing_' . $invoice_type . '_margin_footer' ) );
86
+
87
+ // Set auto page breaks
88
+ $pdf->SetAutoPageBreak( TRUE, get_option( 'wcj_invoicing_' . $invoice_type . '_margin_bottom' ) );
89
+
90
+ // Set image scale factor
91
+ $pdf->setImageScale( PDF_IMAGE_SCALE_RATIO );
92
+
93
+ /*// Set some language-dependent strings (optional)
94
+ if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
95
+ require_once(dirname(__FILE__).'/lang/eng.php');
96
+ $pdf->setLanguageArray($l);
97
+ }*/
98
+
99
+ // Set default font subsetting mode
100
+ $pdf->setFontSubsetting( true );
101
+
102
+ // Set font
103
+ // dejavusans is a UTF-8 Unicode font, if you only need to print standard ASCII chars, you can use core fonts like helvetica or times to reduce file size.
104
+ $pdf->SetFont(
105
+ apply_filters( 'wcj_get_option_filter', 'dejavusans', get_option( 'wcj_pdf_invoices_general_font_family', 'dejavusans' ) ),
106
+ '',
107
+ apply_filters( 'wcj_get_option_filter', 8, get_option( 'wcj_pdf_invoices_general_font_size' ) ),
108
+ '',
109
+ true );
110
+
111
+ // Add a page
112
+ $pdf->AddPage();
113
+
114
+ // Set text shadow effect
115
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_general_font_shadowed', 'yes' ) ) {
116
+ $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
117
+ }
118
+
119
+ return $pdf;
120
+ }
121
+
122
+ /**
123
+ * get_pdf.
124
+ */
125
+ //function get_pdf( $get_by_order_id = 0 ) {
126
+ //function get_pdf( $order_id, $invoice_type, $name, $dest ) {
127
+ function get_pdf( $dest ) {
128
+
129
+ $pdf = $this->prepare_pdf();
130
+
131
+ // Get invoice content HTML
132
+ $_GET['order_id'] = $this->order_id;
133
+ $html = do_shortcode( get_option( 'wcj_invoicing_' . $this->invoice_type . '_template' ) );
134
+ //$html = apply_filters( 'the_content', get_option( 'wcj_invoicing_' . $this->invoice_type . '_template' ) );
135
+
136
+ $styling = '<style>' . get_option( 'wcj_invoicing_' . $this->invoice_type . '_css' ) . '</style>';
137
+
138
+ // Print text using writeHTMLCell()
139
+ $pdf->writeHTMLCell( 0, 0, '', '', $styling . $html, 0, 1, 0, true, '', true );
140
+
141
+
142
+ /*
143
+ // set style for barcode
144
+ $style = array(
145
+ 'border' => true,
146
+ 'vpadding' => 'auto',
147
+ 'hpadding' => 'auto',
148
+ 'fgcolor' => array(0,0,0),
149
+ 'bgcolor' => false, //array(255,255,255)
150
+ 'module_width' => 1, // width of a single module in points
151
+ 'module_height' => 1 // height of a single module in points
152
+ );
153
+
154
+ // -------------------------------------------------------------------
155
+ // PDF417 (ISO/IEC 15438:2006)
156
+
157
+ /*
158
+
159
+ The $type parameter can be simple 'PDF417' or 'PDF417' followed by a
160
+ number of comma-separated options:
161
+
162
+ 'PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6'
163
+
164
+ Possible options are:
165
+
166
+ a = aspect ratio (width/height);
167
+ e = error correction level (0-8);
168
+
169
+ Macro Control Block options:
170
+
171
+ t = total number of macro segments;
172
+ s = macro segment index (0-99998);
173
+ f = file ID;
174
+ o0 = File Name (text);
175
+ o1 = Segment Count (numeric);
176
+ o2 = Time Stamp (numeric);
177
+ o3 = Sender (text);
178
+ o4 = Addressee (text);
179
+ o5 = File Size (numeric);
180
+ o6 = Checksum (numeric).
181
+
182
+ Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional.
183
+ To use a comma character ',' on text options, replace it with the character 255: "\xff".
184
+
185
+ *//*
186
+
187
+ $pdf->write2DBarcode( 'www.woojetpack.com', 'PDF417', 0, 200, 0, 30, $style, 'T');
188
+ //$pdf->Text(80, 85, 'PDF417 (ISO/IEC 15438:2006)');
189
+
190
+ // -------------------------------------------------------------------
191
+ /**
192
+ require_once( wcj_plugin_path() .'/includes/lib/tcpdf_min/tcpdf_barcodes_2d.php');
193
+ $barcodeobj = new TCPDF2DBarcode('http://www.tcpdf.org', 'PDF417');
194
+ // output the barcode as PNG image
195
+ //$barcodeobj->getBarcodePNG(4, 4, array(0,0,0));
196
+ $html = $barcodeobj->getBarcodeHTML(4, 4, 'black');
197
+ //$pdf->writeHTMLCell( 0, 0, '', '', $html, 0, 1, 0, true, '', true );
198
+ /**/
199
+
200
+ // Close and output PDF document
201
+ $result_pdf = $pdf->Output( '', 'S' );
202
+ $file_name = $this->get_file_name();
203
+ $file_path = sys_get_temp_dir() . '/' . $file_name;
204
+ if ( ! file_put_contents( $file_path, $result_pdf ) )
205
+ return null;
206
+
207
+ if ( 'F' === $dest ) {
208
+ return $file_path;
209
+ }
210
+ elseif ( 'D' === $dest || 'I' === $dest ) {
211
+ if ( 'D' === $dest ) {
212
+ header( "Content-Type: application/octet-stream" );
213
+ header( "Content-Disposition: attachment; filename=" . urlencode( $file_name ) );
214
+ header( "Content-Type: application/octet-stream" );
215
+ header( "Content-Type: application/download" );
216
+ header( "Content-Description: File Transfer" );
217
+ }
218
+ elseif ( 'I' === $dest ) {
219
+ header( "Content-type: application/pdf" );
220
+ header( "Content-Disposition: inline; filename=" . urlencode( $file_name ) );
221
+ }
222
+ header( "Content-Length: " . filesize( $file_path ) );
223
+ flush(); // this doesn't really matter.
224
+
225
+ $fp = fopen($file_path, "r");
226
+ while (!feof($fp))
227
+ {
228
+ echo fread($fp, 65536);
229
+ flush(); // this is essential for large downloads
230
+ }
231
+ fclose($fp);
232
+ }
233
+ return null;
234
+ }
235
+ }
236
+
237
+ endif;
includes/currencies/wcj-currencies.php CHANGED
@@ -78,6 +78,7 @@
78
  array( 'code' => 'KGS', 'name' => __( 'Kyrgyzstani som' ), 'symbol' => 'KGS', ),
79
  array( 'code' => 'KWD', 'name' => __( 'Kuwaiti dinar' ), 'symbol' => 'KWD', ),
80
  array( 'code' => 'LAK', 'name' => __( 'Lao kip' ), 'symbol' => 'LAK', ),
 
81
  array( 'code' => 'LVL', 'name' => __( 'Latvian lats' ), 'symbol' => 'LVL', ),
82
  array( 'code' => 'LBP', 'name' => __( 'Lebanese lira' ), 'symbol' => 'LBP', ),
83
  array( 'code' => 'LSL', 'name' => __( 'Lesotho loti' ), 'symbol' => 'LSL', ),
78
  array( 'code' => 'KGS', 'name' => __( 'Kyrgyzstani som' ), 'symbol' => 'KGS', ),
79
  array( 'code' => 'KWD', 'name' => __( 'Kuwaiti dinar' ), 'symbol' => 'KWD', ),
80
  array( 'code' => 'LAK', 'name' => __( 'Lao kip' ), 'symbol' => 'LAK', ),
81
+ //array( 'code' => 'KIP', 'name' => __( 'Lao kip' ), 'symbol' => 'KIP', ),
82
  array( 'code' => 'LVL', 'name' => __( 'Latvian lats' ), 'symbol' => 'LVL', ),
83
  array( 'code' => 'LBP', 'name' => __( 'Lebanese lira' ), 'symbol' => 'LBP', ),
84
  array( 'code' => 'LSL', 'name' => __( 'Lesotho loti' ), 'symbol' => 'LSL', ),
includes/functions/wcj-country-functions.php ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * wcj_get_customer_country.
4
+ *
5
+ * @return string
6
+ */
7
+ if ( ! function_exists( 'wcj_get_customer_country' ) ) {
8
+ function wcj_get_customer_country( $user_id ) {
9
+
10
+ $user_meta = get_user_meta( $user_id );
11
+
12
+ $billing_country = isset( $user_meta['billing_country'][0] ) ? $user_meta['billing_country'][0] : '';
13
+ $shipping_country = isset( $user_meta['shipping_country'][0] ) ? $user_meta['shipping_country'][0] : '';
14
+
15
+ $customer_country = ( '' == $billing_country ) ? $shipping_country : $billing_country;
16
+
17
+ return $customer_country;
18
+ }
19
+ }
20
+
21
+ /**
22
+ * wcj_get_european_union_countries_with_vat.
23
+ *
24
+ * @return array
25
+ */
26
+ if ( ! function_exists( 'wcj_get_european_union_countries_with_vat' ) ) {
27
+ function wcj_get_european_union_countries_with_vat() {
28
+ return array(
29
+ 'AT' => 20,
30
+ 'BE' => 21,
31
+ 'BG' => 20,
32
+ 'CY' => 19,
33
+ 'CZ' => 21,
34
+ 'DE' => 19,
35
+ 'DK' => 25,
36
+ 'EE' => 20,
37
+ 'ES' => 21,
38
+ 'FI' => 24,
39
+ 'FR' => 20,
40
+ 'GB' => 20,
41
+ 'GR' => 23,
42
+ 'HU' => 27,
43
+ 'HR' => 25,
44
+ 'IE' => 23,
45
+ 'IT' => 22,
46
+ 'LT' => 21,
47
+ 'LU' => 17,
48
+ 'LV' => 21,
49
+ 'MT' => 18,
50
+ 'NL' => 21,
51
+ 'PL' => 23,
52
+ 'PT' => 23,
53
+ 'RO' => 24,
54
+ 'SE' => 25,
55
+ 'SI' => 22,
56
+ 'SK' => 20,
57
+
58
+ //'MC' => ,
59
+ //'IM' => ,
60
+ );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Get country name by country code.
66
+ *
67
+ * @return string on success, boolean false otherwise
68
+ */
69
+ if ( ! function_exists( 'wcj_get_country_name_by_code' ) ) {
70
+ function wcj_get_country_name_by_code( $country_code ) {
71
+ $countries = array(
72
+ 'AX' => __( '�land Islands', 'woocommerce' ),
73
+ 'AF' => __( 'Afghanistan', 'woocommerce' ),
74
+ 'AL' => __( 'Albania', 'woocommerce' ),
75
+ 'DZ' => __( 'Algeria', 'woocommerce' ),
76
+ 'AD' => __( 'Andorra', 'woocommerce' ),
77
+ 'AO' => __( 'Angola', 'woocommerce' ),
78
+ 'AI' => __( 'Anguilla', 'woocommerce' ),
79
+ 'AQ' => __( 'Antarctica', 'woocommerce' ),
80
+ 'AG' => __( 'Antigua and Barbuda', 'woocommerce' ),
81
+ 'AR' => __( 'Argentina', 'woocommerce' ),
82
+ 'AM' => __( 'Armenia', 'woocommerce' ),
83
+ 'AW' => __( 'Aruba', 'woocommerce' ),
84
+ 'AU' => __( 'Australia', 'woocommerce' ),
85
+ 'AT' => __( 'Austria', 'woocommerce' ),
86
+ 'AZ' => __( 'Azerbaijan', 'woocommerce' ),
87
+ 'BS' => __( 'Bahamas', 'woocommerce' ),
88
+ 'BH' => __( 'Bahrain', 'woocommerce' ),
89
+ 'BD' => __( 'Bangladesh', 'woocommerce' ),
90
+ 'BB' => __( 'Barbados', 'woocommerce' ),
91
+ 'BY' => __( 'Belarus', 'woocommerce' ),
92
+ 'PW' => __( 'Belau', 'woocommerce' ),
93
+ 'BE' => __( 'Belgium', 'woocommerce' ),
94
+ 'BZ' => __( 'Belize', 'woocommerce' ),
95
+ 'BJ' => __( 'Benin', 'woocommerce' ),
96
+ 'BM' => __( 'Bermuda', 'woocommerce' ),
97
+ 'BT' => __( 'Bhutan', 'woocommerce' ),
98
+ 'BO' => __( 'Bolivia', 'woocommerce' ),
99
+ 'BQ' => __( 'Bonaire, Saint Eustatius and Saba', 'woocommerce' ),
100
+ 'BA' => __( 'Bosnia and Herzegovina', 'woocommerce' ),
101
+ 'BW' => __( 'Botswana', 'woocommerce' ),
102
+ 'BV' => __( 'Bouvet Island', 'woocommerce' ),
103
+ 'BR' => __( 'Brazil', 'woocommerce' ),
104
+ 'IO' => __( 'British Indian Ocean Territory', 'woocommerce' ),
105
+ 'VG' => __( 'British Virgin Islands', 'woocommerce' ),
106
+ 'BN' => __( 'Brunei', 'woocommerce' ),
107
+ 'BG' => __( 'Bulgaria', 'woocommerce' ),
108
+ 'BF' => __( 'Burkina Faso', 'woocommerce' ),
109
+ 'BI' => __( 'Burundi', 'woocommerce' ),
110
+ 'KH' => __( 'Cambodia', 'woocommerce' ),
111
+ 'CM' => __( 'Cameroon', 'woocommerce' ),
112
+ 'CA' => __( 'Canada', 'woocommerce' ),
113
+ 'CV' => __( 'Cape Verde', 'woocommerce' ),
114
+ 'KY' => __( 'Cayman Islands', 'woocommerce' ),
115
+ 'CF' => __( 'Central African Republic', 'woocommerce' ),
116
+ 'TD' => __( 'Chad', 'woocommerce' ),
117
+ 'CL' => __( 'Chile', 'woocommerce' ),
118
+ 'CN' => __( 'China', 'woocommerce' ),
119
+ 'CX' => __( 'Christmas Island', 'woocommerce' ),
120
+ 'CC' => __( 'Cocos (Keeling) Islands', 'woocommerce' ),
121
+ 'CO' => __( 'Colombia', 'woocommerce' ),
122
+ 'KM' => __( 'Comoros', 'woocommerce' ),
123
+ 'CG' => __( 'Congo (Brazzaville)', 'woocommerce' ),
124
+ 'CD' => __( 'Congo (Kinshasa)', 'woocommerce' ),
125
+ 'CK' => __( 'Cook Islands', 'woocommerce' ),
126
+ 'CR' => __( 'Costa Rica', 'woocommerce' ),
127
+ 'HR' => __( 'Croatia', 'woocommerce' ),
128
+ 'CU' => __( 'Cuba', 'woocommerce' ),
129
+ 'CW' => __( 'Cura?ao', 'woocommerce' ),
130
+ 'CY' => __( 'Cyprus', 'woocommerce' ),
131
+ 'CZ' => __( 'Czech Republic', 'woocommerce' ),
132
+ 'DK' => __( 'Denmark', 'woocommerce' ),
133
+ 'DJ' => __( 'Djibouti', 'woocommerce' ),
134
+ 'DM' => __( 'Dominica', 'woocommerce' ),
135
+ 'DO' => __( 'Dominican Republic', 'woocommerce' ),
136
+ 'EC' => __( 'Ecuador', 'woocommerce' ),
137
+ 'EG' => __( 'Egypt', 'woocommerce' ),
138
+ 'SV' => __( 'El Salvador', 'woocommerce' ),
139
+ 'GQ' => __( 'Equatorial Guinea', 'woocommerce' ),
140
+ 'ER' => __( 'Eritrea', 'woocommerce' ),
141
+ 'EE' => __( 'Estonia', 'woocommerce' ),
142
+ 'ET' => __( 'Ethiopia', 'woocommerce' ),
143
+ 'FK' => __( 'Falkland Islands', 'woocommerce' ),
144
+ 'FO' => __( 'Faroe Islands', 'woocommerce' ),
145
+ 'FJ' => __( 'Fiji', 'woocommerce' ),
146
+ 'FI' => __( 'Finland', 'woocommerce' ),
147
+ 'FR' => __( 'France', 'woocommerce' ),
148
+ 'GF' => __( 'French Guiana', 'woocommerce' ),
149
+ 'PF' => __( 'French Polynesia', 'woocommerce' ),
150
+ 'TF' => __( 'French Southern Territories', 'woocommerce' ),
151
+ 'GA' => __( 'Gabon', 'woocommerce' ),
152
+ 'GM' => __( 'Gambia', 'woocommerce' ),
153
+ 'GE' => __( 'Georgia', 'woocommerce' ),
154
+ 'DE' => __( 'Germany', 'woocommerce' ),
155
+ 'GH' => __( 'Ghana', 'woocommerce' ),
156
+ 'GI' => __( 'Gibraltar', 'woocommerce' ),
157
+ 'GR' => __( 'Greece', 'woocommerce' ),
158
+ 'GL' => __( 'Greenland', 'woocommerce' ),
159
+ 'GD' => __( 'Grenada', 'woocommerce' ),
160
+ 'GP' => __( 'Guadeloupe', 'woocommerce' ),
161
+ 'GT' => __( 'Guatemala', 'woocommerce' ),
162
+ 'GG' => __( 'Guernsey', 'woocommerce' ),
163
+ 'GN' => __( 'Guinea', 'woocommerce' ),
164
+ 'GW' => __( 'Guinea-Bissau', 'woocommerce' ),
165
+ 'GY' => __( 'Guyana', 'woocommerce' ),
166
+ 'HT' => __( 'Haiti', 'woocommerce' ),
167
+ 'HM' => __( 'Heard Island and McDonald Islands', 'woocommerce' ),
168
+ 'HN' => __( 'Honduras', 'woocommerce' ),
169
+ 'HK' => __( 'Hong Kong', 'woocommerce' ),
170
+ 'HU' => __( 'Hungary', 'woocommerce' ),
171
+ 'IS' => __( 'Iceland', 'woocommerce' ),
172
+ 'IN' => __( 'India', 'woocommerce' ),
173
+ 'ID' => __( 'Indonesia', 'woocommerce' ),
174
+ 'IR' => __( 'Iran', 'woocommerce' ),
175
+ 'IQ' => __( 'Iraq', 'woocommerce' ),
176
+ 'IM' => __( 'Isle of Man', 'woocommerce' ),
177
+ 'IL' => __( 'Israel', 'woocommerce' ),
178
+ 'IT' => __( 'Italy', 'woocommerce' ),
179
+ 'CI' => __( 'Ivory Coast', 'woocommerce' ),
180
+ 'JM' => __( 'Jamaica', 'woocommerce' ),
181
+ 'JP' => __( 'Japan', 'woocommerce' ),
182
+ 'JE' => __( 'Jersey', 'woocommerce' ),
183
+ 'JO' => __( 'Jordan', 'woocommerce' ),
184
+ 'KZ' => __( 'Kazakhstan', 'woocommerce' ),
185
+ 'KE' => __( 'Kenya', 'woocommerce' ),
186
+ 'KI' => __( 'Kiribati', 'woocommerce' ),
187
+ 'KW' => __( 'Kuwait', 'woocommerce' ),
188
+ 'KG' => __( 'Kyrgyzstan', 'woocommerce' ),
189
+ 'LA' => __( 'Laos', 'woocommerce' ),
190
+ 'LV' => __( 'Latvia', 'woocommerce' ),
191
+ 'LB' => __( 'Lebanon', 'woocommerce' ),
192
+ 'LS' => __( 'Lesotho', 'woocommerce' ),
193
+ 'LR' => __( 'Liberia', 'woocommerce' ),
194
+ 'LY' => __( 'Libya', 'woocommerce' ),
195
+ 'LI' => __( 'Liechtenstein', 'woocommerce' ),
196
+ 'LT' => __( 'Lithuania', 'woocommerce' ),
197
+ 'LU' => __( 'Luxembourg', 'woocommerce' ),
198
+ 'MO' => __( 'Macao S.A.R., China', 'woocommerce' ),
199
+ 'MK' => __( 'Macedonia', 'woocommerce' ),
200
+ 'MG' => __( 'Madagascar', 'woocommerce' ),
201
+ 'MW' => __( 'Malawi', 'woocommerce' ),
202
+ 'MY' => __( 'Malaysia', 'woocommerce' ),
203
+ 'MV' => __( 'Maldives', 'woocommerce' ),
204
+ 'ML' => __( 'Mali', 'woocommerce' ),
205
+ 'MT' => __( 'Malta', 'woocommerce' ),
206
+ 'MH' => __( 'Marshall Islands', 'woocommerce' ),
207
+ 'MQ' => __( 'Martinique', 'woocommerce' ),
208
+ 'MR' => __( 'Mauritania', 'woocommerce' ),
209
+ 'MU' => __( 'Mauritius', 'woocommerce' ),
210
+ 'YT' => __( 'Mayotte', 'woocommerce' ),
211
+ 'MX' => __( 'Mexico', 'woocommerce' ),
212
+ 'FM' => __( 'Micronesia', 'woocommerce' ),
213
+ 'MD' => __( 'Moldova', 'woocommerce' ),
214
+ 'MC' => __( 'Monaco', 'woocommerce' ),
215
+ 'MN' => __( 'Mongolia', 'woocommerce' ),
216
+ 'ME' => __( 'Montenegro', 'woocommerce' ),
217
+ 'MS' => __( 'Montserrat', 'woocommerce' ),
218
+ 'MA' => __( 'Morocco', 'woocommerce' ),
219
+ 'MZ' => __( 'Mozambique', 'woocommerce' ),
220
+ 'MM' => __( 'Myanmar', 'woocommerce' ),
221
+ 'NA' => __( 'Namibia', 'woocommerce' ),
222
+ 'NR' => __( 'Nauru', 'woocommerce' ),
223
+ 'NP' => __( 'Nepal', 'woocommerce' ),
224
+ 'NL' => __( 'Netherlands', 'woocommerce' ),
225
+ 'AN' => __( 'Netherlands Antilles', 'woocommerce' ),
226
+ 'NC' => __( 'New Caledonia', 'woocommerce' ),
227
+ 'NZ' => __( 'New Zealand', 'woocommerce' ),
228
+ 'NI' => __( 'Nicaragua', 'woocommerce' ),
229
+ 'NE' => __( 'Niger', 'woocommerce' ),
230
+ 'NG' => __( 'Nigeria', 'woocommerce' ),
231
+ 'NU' => __( 'Niue', 'woocommerce' ),
232
+ 'NF' => __( 'Norfolk Island', 'woocommerce' ),
233
+ 'KP' => __( 'North Korea', 'woocommerce' ),
234
+ 'NO' => __( 'Norway', 'woocommerce' ),
235
+ 'OM' => __( 'Oman', 'woocommerce' ),
236
+ 'PK' => __( 'Pakistan', 'woocommerce' ),
237
+ 'PS' => __( 'Palestinian Territory', 'woocommerce' ),
238
+ 'PA' => __( 'Panama', 'woocommerce' ),
239
+ 'PG' => __( 'Papua New Guinea', 'woocommerce' ),
240
+ 'PY' => __( 'Paraguay', 'woocommerce' ),
241
+ 'PE' => __( 'Peru', 'woocommerce' ),
242
+ 'PH' => __( 'Philippines', 'woocommerce' ),
243
+ 'PN' => __( 'Pitcairn', 'woocommerce' ),
244
+ 'PL' => __( 'Poland', 'woocommerce' ),
245
+ 'PT' => __( 'Portugal', 'woocommerce' ),
246
+ 'QA' => __( 'Qatar', 'woocommerce' ),
247
+ 'IE' => __( 'Republic of Ireland', 'woocommerce' ),
248
+ 'RE' => __( 'Reunion', 'woocommerce' ),
249
+ 'RO' => __( 'Romania', 'woocommerce' ),
250
+ 'RU' => __( 'Russia', 'woocommerce' ),
251
+ 'RW' => __( 'Rwanda', 'woocommerce' ),
252
+ 'ST' => __( 'S?o Tom� and Pr?ncipe', 'woocommerce' ),
253
+ 'BL' => __( 'Saint Barth�lemy', 'woocommerce' ),
254
+ 'SH' => __( 'Saint Helena', 'woocommerce' ),
255
+ 'KN' => __( 'Saint Kitts and Nevis', 'woocommerce' ),
256
+ 'LC' => __( 'Saint Lucia', 'woocommerce' ),
257
+ 'SX' => __( 'Saint Martin (Dutch part)', 'woocommerce' ),
258
+ 'MF' => __( 'Saint Martin (French part)', 'woocommerce' ),
259
+ 'PM' => __( 'Saint Pierre and Miquelon', 'woocommerce' ),
260
+ 'VC' => __( 'Saint Vincent and the Grenadines', 'woocommerce' ),
261
+ 'SM' => __( 'San Marino', 'woocommerce' ),
262
+ 'SA' => __( 'Saudi Arabia', 'woocommerce' ),
263
+ 'SN' => __( 'Senegal', 'woocommerce' ),
264
+ 'RS' => __( 'Serbia', 'woocommerce' ),
265
+ 'SC' => __( 'Seychelles', 'woocommerce' ),
266
+ 'SL' => __( 'Sierra Leone', 'woocommerce' ),
267
+ 'SG' => __( 'Singapore', 'woocommerce' ),
268
+ 'SK' => __( 'Slovakia', 'woocommerce' ),
269
+ 'SI' => __( 'Slovenia', 'woocommerce' ),
270
+ 'SB' => __( 'Solomon Islands', 'woocommerce' ),
271
+ 'SO' => __( 'Somalia', 'woocommerce' ),
272
+ 'ZA' => __( 'South Africa', 'woocommerce' ),
273
+ 'GS' => __( 'South Georgia/Sandwich Islands', 'woocommerce' ),
274
+ 'KR' => __( 'South Korea', 'woocommerce' ),
275
+ 'SS' => __( 'South Sudan', 'woocommerce' ),
276
+ 'ES' => __( 'Spain', 'woocommerce' ),
277
+ 'LK' => __( 'Sri Lanka', 'woocommerce' ),
278
+ 'SD' => __( 'Sudan', 'woocommerce' ),
279
+ 'SR' => __( 'Suriname', 'woocommerce' ),
280
+ 'SJ' => __( 'Svalbard and Jan Mayen', 'woocommerce' ),
281
+ 'SZ' => __( 'Swaziland', 'woocommerce' ),
282
+ 'SE' => __( 'Sweden', 'woocommerce' ),
283
+ 'CH' => __( 'Switzerland', 'woocommerce' ),
284
+ 'SY' => __( 'Syria', 'woocommerce' ),
285
+ 'TW' => __( 'Taiwan', 'woocommerce' ),
286
+ 'TJ' => __( 'Tajikistan', 'woocommerce' ),
287
+ 'TZ' => __( 'Tanzania', 'woocommerce' ),
288
+ 'TH' => __( 'Thailand', 'woocommerce' ),
289
+ 'TL' => __( 'Timor-Leste', 'woocommerce' ),
290
+ 'TG' => __( 'Togo', 'woocommerce' ),
291
+ 'TK' => __( 'Tokelau', 'woocommerce' ),
292
+ 'TO' => __( 'Tonga', 'woocommerce' ),
293
+ 'TT' => __( 'Trinidad and Tobago', 'woocommerce' ),
294
+ 'TN' => __( 'Tunisia', 'woocommerce' ),
295
+ 'TR' => __( 'Turkey', 'woocommerce' ),
296
+ 'TM' => __( 'Turkmenistan', 'woocommerce' ),
297
+ 'TC' => __( 'Turks and Caicos Islands', 'woocommerce' ),
298
+ 'TV' => __( 'Tuvalu', 'woocommerce' ),
299
+ 'UG' => __( 'Uganda', 'woocommerce' ),
300
+ 'UA' => __( 'Ukraine', 'woocommerce' ),
301
+ 'AE' => __( 'United Arab Emirates', 'woocommerce' ),
302
+ 'GB' => __( 'United Kingdom (UK)', 'woocommerce' ),
303
+ 'US' => __( 'United States (US)', 'woocommerce' ),
304
+ 'UY' => __( 'Uruguay', 'woocommerce' ),
305
+ 'UZ' => __( 'Uzbekistan', 'woocommerce' ),
306
+ 'VU' => __( 'Vanuatu', 'woocommerce' ),
307
+ 'VA' => __( 'Vatican', 'woocommerce' ),
308
+ 'VE' => __( 'Venezuela', 'woocommerce' ),
309
+ 'VN' => __( 'Vietnam', 'woocommerce' ),
310
+ 'WF' => __( 'Wallis and Futuna', 'woocommerce' ),
311
+ 'EH' => __( 'Western Sahara', 'woocommerce' ),
312
+ 'WS' => __( 'Western Samoa', 'woocommerce' ),
313
+ 'YE' => __( 'Yemen', 'woocommerce' ),
314
+ 'ZM' => __( 'Zambia', 'woocommerce' ),
315
+ 'ZW' => __( 'Zimbabwe', 'woocommerce' ),
316
+ );
317
+
318
+ if ( isset( $countries[ $country_code ] ) ) return $countries[ $country_code ];
319
+
320
+ return false;
321
+ }
322
+ }
includes/functions/wcj-debug-functions.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Debug Functions
4
+ *
5
+ * The WooCommerce Jetpack Debug functions.
6
+ *
7
+ * @version 1.0.0
8
+ * @author Algoritmika Ltd.
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) exit;
12
+
13
+ // Debug Mode
14
+ if ( 'yes' === get_option( 'wcj_admin_tools_enabled' ) && 'yes' === get_option( 'wcj_debuging_enabled', 'no' ) ) {
15
+ error_reporting( E_ALL );
16
+ }
17
+
18
+ /**
19
+ * wcj_log.
20
+ */
21
+ if ( ! function_exists( 'wcj_log' ) ) {
22
+ function wcj_log( $message = '' ) {
23
+ if ( 'no' === get_option( 'wcj_admin_tools_enabled' ) || 'no' === get_option( 'wcj_logging_enabled', 'no' ) ) return;
24
+ if ( '' == $message ) $message = 'CHECKPOINT';
25
+ if ( is_array( $message ) || is_object( $message ) ) {
26
+ $message = print_r( $message, true );
27
+ }
28
+ update_option( 'wcj_log', date( 'Y-m-d H:i:s' ) . ' ' . $_SERVER['REQUEST_URI'] . ' [' . $message . ']' . '<br>' . get_option( 'wcj_log', '' ) );
29
+ }
30
+ }
includes/functions/wcj-functions.php ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * validate_VAT.
5
+ *
6
+ * @return mixed: bool on successful checking (can be true or false), null otherwise
7
+ */
8
+ if ( ! function_exists( 'validate_VAT' ) ) {
9
+ function validate_VAT( $country_code, $vat_number ) {
10
+ $client = new SoapClient( 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' );
11
+ $result = $client->checkVat( array(
12
+ 'countryCode' => $country_code,
13
+ 'vatNumber' => $vat_number,
14
+ ) );
15
+ return ( isset( $result->valid ) ) ? $result->valid : null;
16
+ }
17
+ }
18
+
19
+ /**
20
+ * convert_number_to_words.
21
+ *
22
+ * @return string
23
+ */
24
+ if ( ! function_exists( 'convert_number_to_words' ) ) {
25
+ function convert_number_to_words( $number ) {
26
+ $hyphen = '-';
27
+ $conjunction = ' and ';
28
+ $separator = ', ';
29
+ $negative = 'negative ';
30
+ $decimal = ' point ';
31
+ $dictionary = array(
32
+ 0 => 'zero',
33
+ 1 => 'one',
34
+ 2 => 'two',
35
+ 3 => 'three',
36
+ 4 => 'four',
37
+ 5 => 'five',
38
+ 6 => 'six',
39
+ 7 => 'seven',
40
+ 8 => 'eight',
41
+ 9 => 'nine',
42
+ 10 => 'ten',
43
+ 11 => 'eleven',
44
+ 12 => 'twelve',
45
+ 13 => 'thirteen',
46
+ 14 => 'fourteen',
47
+ 15 => 'fifteen',
48
+ 16 => 'sixteen',
49
+ 17 => 'seventeen',
50
+ 18 => 'eighteen',
51
+ 19 => 'nineteen',
52
+ 20 => 'twenty',
53
+ 30 => 'thirty',
54
+ 40 => 'fourty',
55
+ 50 => 'fifty',
56
+ 60 => 'sixty',
57
+ 70 => 'seventy',
58
+ 80 => 'eighty',
59
+ 90 => 'ninety',
60
+ 100 => 'hundred',
61
+ 1000 => 'thousand',
62
+ 1000000 => 'million',
63
+ 1000000000 => 'billion',
64
+ 1000000000000 => 'trillion',
65
+ 1000000000000000 => 'quadrillion',
66
+ 1000000000000000000 => 'quintillion'
67
+ );
68
+
69
+ if (!is_numeric($number)) {
70
+ return false;
71
+ }
72
+
73
+ if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
74
+ // overflow
75
+ trigger_error(
76
+ 'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
77
+ E_USER_WARNING
78
+ );
79
+ return false;
80
+ }
81
+
82
+ if ($number < 0) {
83
+ return $negative . convert_number_to_words(abs($number));
84
+ }
85
+
86
+ $string = $fraction = null;
87
+
88
+ if (strpos($number, '.') !== false) {
89
+ list($number, $fraction) = explode('.', $number);
90
+ }
91
+
92
+ switch (true) {
93
+ case $number < 21:
94
+ $string = $dictionary[$number];
95
+ break;
96
+ case $number < 100:
97
+ $tens = ((int) ($number / 10)) * 10;
98
+ $units = $number % 10;
99
+ $string = $dictionary[$tens];
100
+ if ($units) {
101
+ $string .= $hyphen . $dictionary[$units];
102
+ }
103
+ break;
104
+ case $number < 1000:
105
+ $hundreds = $number / 100;
106
+ $remainder = $number % 100;
107
+ $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
108
+ if ($remainder) {
109
+ $string .= $conjunction . convert_number_to_words($remainder);
110
+ }
111
+ break;
112
+ default:
113
+ $baseUnit = pow(1000, floor(log($number, 1000)));
114
+ $numBaseUnits = (int) ($number / $baseUnit);
115
+ $remainder = $number % $baseUnit;
116
+ $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
117
+ if ($remainder) {
118
+ $string .= $remainder < 100 ? $conjunction : $separator;
119
+ $string .= convert_number_to_words($remainder);
120
+ }
121
+ break;
122
+ }
123
+
124
+ if (null !== $fraction && is_numeric($fraction)) {
125
+ $string .= $decimal;
126
+ $words = array();
127
+ foreach (str_split((string) $fraction) as $number) {
128
+ $words[] = $dictionary[$number];
129
+ }
130
+ $string .= implode(' ', $words);
131
+ }
132
+
133
+ return $string;
134
+ }
135
+ }
136
+
137
+ /**
138
+ * wcj_plugin_url.
139
+ *
140
+ * @todo
141
+ *
142
+ if ( ! function_exists( 'wcj_plugin_url' ) ) {
143
+ function wcj_plugin_url() {
144
+ return untrailingslashit( plugin_dir_url( __FILE__ ) );
145
+ //return untrailingslashit( realpath( dirname(__FILE__) . '/..' ) );
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Get the plugin path.
151
+ *
152
+ * @return string
153
+ */
154
+ if ( ! function_exists( 'wcj_plugin_path' ) ) {
155
+ function wcj_plugin_path() {
156
+ //return untrailingslashit( plugin_dir_path( __FILE__ ) );
157
+ return untrailingslashit( realpath( plugin_dir_path( __FILE__ ) . '/../..' ) );
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Convert the php date format string to a js date format.
163
+ * https://gist.github.com/clubduece/4053820
164
+ */
165
+ if ( ! function_exists( 'wcj_date_format_php_to_js' ) ) {
166
+ function wcj_date_format_php_to_js( $php_date_format ) {
167
+ $date_formats_php_to_js = array(
168
+ 'F j, Y' => 'MM dd, yy',
169
+ 'Y/m/d' => 'yy/mm/dd',
170
+ 'm/d/Y' => 'mm/dd/yy',
171
+ 'd/m/Y' => 'dd/mm/yy',
172
+ );
173
+ return isset( $date_formats_php_to_js[ $php_date_format ] ) ? $date_formats_php_to_js[ $php_date_format ] : 'MM dd, yy';
174
+ }
175
+ }
176
+
177
+ /**
178
+ * wcj_hex2rgb.
179
+ */
180
+ if ( ! function_exists( 'wcj_hex2rgb' ) ) {
181
+ function wcj_hex2rgb( $hex ) {
182
+ return sscanf( $hex, "#%2x%2x%2x" );
183
+ }
184
+ }
185
+
186
+ /**
187
+ * wcj_get_the_ip.
188
+ * http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
189
+ */
190
+ if ( ! function_exists( 'wcj_get_the_ip' ) ) {
191
+ function wcj_get_the_ip( ) {
192
+ $ip = null;
193
+ if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
194
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
195
+ } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
196
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
197
+ } else {
198
+ $ip = $_SERVER['REMOTE_ADDR'];
199
+ }
200
+ return $ip;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * wcj_get_shortcodes_atts_list.
206
+ *
207
+ if ( ! function_exists( 'wcj_get_shortcodes_atts_list' ) ) {
208
+ function wcj_get_shortcodes_atts_list() {
209
+ return apply_filters( 'wcj_shortcodes_atts', array(
210
+ 'before' => '',
211
+ 'after' => '',
212
+ 'visibility' => '',
213
+ ) );
214
+ }
215
+ }
216
+
217
+ /**
218
+ * wcj_get_shortcodes_list.
219
+ */
220
+ if ( ! function_exists( 'wcj_get_shortcodes_list' ) ) {
221
+ function wcj_get_shortcodes_list() {
222
+ $the_array = apply_filters( 'wcj_shortcodes_list', array() );
223
+ return implode( ', ', $the_array );
224
+ //return implode( PHP_EOL, $the_array );
225
+ }
226
+ }
227
+
228
+ /**
229
+ * wcj_get_order_statuses.
230
+ */
231
+ if ( ! function_exists( 'wcj_get_order_statuses' ) ) {
232
+ function wcj_get_order_statuses( $cut_the_prefix ) {
233
+ $order_statuses = array(
234
+ 'wc-pending' => _x( 'Pending Payment', 'Order status', 'woocommerce' ),
235
+ 'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ),
236
+ 'wc-on-hold' => _x( 'On Hold', 'Order status', 'woocommerce' ),
237
+ 'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ),
238
+ 'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ),
239
+ 'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ),
240
+ 'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ),
241
+ );
242
+ $order_statuses = apply_filters( 'wc_order_statuses', $order_statuses );
243
+ if ( $cut_the_prefix ) {
244
+ $order_statuses_no_prefix = array();
245
+ foreach ( $order_statuses as $status => $desc ) {
246
+ $order_statuses_no_prefix[ substr( $status, 3 ) ] = $desc;
247
+ }
248
+ return $order_statuses_no_prefix;
249
+ }
250
+ return $order_statuses;
251
+ }
252
+ }
253
+
254
+ /**
255
+ * wcj_get_currencies_names_and_symbols.
256
+ */
257
+ if ( ! function_exists( 'wcj_get_currencies_names_and_symbols' ) ) {
258
+ function wcj_get_currencies_names_and_symbols() {
259
+ $currencies = include( wcj_plugin_path() . '/includes/currencies/wcj-currencies.php' );
260
+ foreach( $currencies as $data ) {
261
+ $currency_names_and_symbols[ $data['code'] ] = $data['name'] . ' (' . $data['symbol'] . ')';
262
+ }
263
+ return $currency_names_and_symbols;
264
+ }
265
+ }
266
+
267
+ /**
268
+ * wcj_get_currency_symbol.
269
+ */
270
+ if ( ! function_exists( 'wcj_get_currency_symbol' ) ) {
271
+ function wcj_get_currency_symbol( $currency_code ) {
272
+ $currencies = include( wcj_plugin_path() . '/includes/currencies/wcj-currencies.php' );
273
+ foreach( $currencies as $data ) {
274
+ if ( $currency_code == $data['code'] )
275
+ return $data['symbol'];
276
+ }
277
+ return false;
278
+ }
279
+ }
280
+
281
+ /**
282
+ * wcj_price.
283
+ */
284
+ if ( ! function_exists( 'wcj_price' ) ) {
285
+ function wcj_price( $price, $currency, $hide_currency ) {
286
+ return ( 'yes' === $hide_currency ) ? wc_price( $price, array( 'currency' => 'DISABLED' ) ) : wc_price( $price, array( 'currency' => $currency ) );
287
+ }
288
+ }
includes/functions/wcj-html-functions.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack HTML Functions
4
+ *
5
+ * The WooCommerce Jetpack HTML functions.
6
+ *
7
+ * @version 1.0.0
8
+ * @author Algoritmika Ltd.
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) exit;
12
+
13
+ /**
14
+ * wcj_get_table_html.
15
+ */
16
+ if ( ! function_exists( 'wcj_get_table_html' ) ) {
17
+ //function wcj_get_table_html( $data, $table_class = '', $table_heading_type = 'horizontal', $columns_classes = array(), $columns_styles = array() ) {
18
+ function wcj_get_table_html( $data, $args = array() ) {
19
+ $defaults = array(
20
+ 'table_class' => '',
21
+ 'table_style' => '',
22
+ 'table_heading_type' => 'horizontal',
23
+ 'columns_classes' => array(),
24
+ 'columns_styles' => array(),
25
+ );
26
+ //wp_parse_args( $args, $defaults );
27
+ $args = array_merge( $defaults, $args );
28
+ extract( $args );
29
+ $table_class = ( '' == $table_class ) ? '' : ' class="' . $table_class . '"';
30
+ $table_style = ( '' == $table_style ) ? '' : ' style="' . $table_style . '"';
31
+ $html = '';
32
+ $html .= '<table' . $table_class . $table_style . '>';
33
+ $html .= '<tbody>';
34
+ foreach( $data as $row_number => $row ) {
35
+ $html .= '<tr>';
36
+ foreach( $row as $column_number => $value ) {
37
+ $th_or_td = ( ( 0 === $row_number && 'horizontal' === $table_heading_type ) || ( 0 === $column_number && 'vertical' === $table_heading_type ) ) ? 'th' : 'td';
38
+ $column_class = ( ! empty( $columns_classes ) && isset( $columns_classes[ $column_number ] ) ) ? ' class="' . $columns_classes[ $column_number ] . '"' : '';
39
+ $column_style = ( ! empty( $columns_styles ) && isset( $columns_styles[ $column_number ] ) ) ? ' style="' . $columns_styles[ $column_number ] . '"' : '';
40
+
41
+ $html .= '<' . $th_or_td . $column_class . $column_style . '>';
42
+ $html .= $value;
43
+ $html .= '</' . $th_or_td . '>';
44
+ }
45
+ $html .= '</tr>';
46
+ }
47
+ $html .= '</tbody>';
48
+ $html .= '</table>';
49
+ return $html;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * wcj_get_option_html.
55
+ */
56
+ if ( ! function_exists( 'wcj_get_option_html' ) ) {
57
+ function wcj_get_option_html( $option_type, $option_id, $option_value, $option_description, $option_class ) {
58
+
59
+ if ( 'checkbox' === $option_type )
60
+ $is_checked = checked( $option_value, 'on', false );
61
+
62
+ $html = '';
63
+ switch ( $option_type ) {
64
+ case 'number':
65
+ case 'text':
66
+ $html .= '<input type="' . $option_type . '" class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '" value="' . $option_value . '">';
67
+ break;
68
+ case 'textarea':
69
+ $html .= '<textarea class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</textarea>';
70
+ break;
71
+ case 'checkbox':
72
+ $html .= '<input class="checkbox" type="checkbox" name="' . $option_id . '" id="' . $option_id . '" ' . $is_checked . ' />';
73
+ break;
74
+ case 'select':
75
+ $html .= '<select class="' . $option_class . '" id="' . $option_id . '" name="' . $option_id . '">' . $option_value . '</select>';
76
+ break;
77
+ }
78
+ $html .= '<span class="description">' . $option_description . '</span>';
79
+
80
+ return $html;
81
+ }
82
+ }
includes/functions/wcj-invoicing-functions.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * wcj_get_invoice_types.
4
+ */
5
+ if ( ! function_exists( 'wcj_get_invoice_types' ) ) {
6
+ function wcj_get_invoice_types() {
7
+ $invoice_types = array(
8
+ array(
9
+ 'id' => 'invoice',
10
+ 'title' => __( 'Invoice', 'woocommerce-jetpack' ),
11
+ 'desc' => __( 'Invoices', 'woocommerce-jetpack' ),
12
+ 'defaults' => array( 'init' => 'disabled', ),
13
+ 'icon' => '\e028',
14
+ ),
15
+
16
+ array(
17
+ 'id' => 'proforma_invoice',
18
+ 'title' => __( 'Proforma Invoice', 'woocommerce-jetpack' ),
19
+ 'desc' => __( 'Proforma Invoices', 'woocommerce-jetpack' ),
20
+ 'defaults' => array( 'init' => 'disabled', ),
21
+ 'icon' => '\e030',
22
+ ),
23
+
24
+ array(
25
+ 'id' => 'packing_slip',
26
+ 'title' => __( 'Packing Slip', 'woocommerce-jetpack' ),
27
+ 'desc' => __( 'Packing Slips', 'woocommerce-jetpack' ),
28
+ 'defaults' => array( 'init' => 'disabled', ),
29
+ 'icon' => '\e019',
30
+ ),
31
+ );
32
+ return $invoice_types;
33
+ }
34
+ }
35
+
36
+ /*
37
+ * wcj_get_enabled_invoice_types.
38
+ */
39
+ if ( ! function_exists( 'wcj_get_enabled_invoice_types' ) ) {
40
+ function wcj_get_enabled_invoice_types() {
41
+ $invoice_types = wcj_get_invoice_types();
42
+ $enabled_invoice_types = array();
43
+ foreach ( $invoice_types as $k => $invoice_type ) {
44
+ $z = ( 0 === $k ) ? get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_create_on' ) : apply_filters( 'wcj_get_option_filter', 'disabled', get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_create_on' ) );
45
+ if ( 'disabled' === $z )
46
+ continue;
47
+ $enabled_invoice_types[] = $invoice_type;
48
+ }
49
+ return $enabled_invoice_types;
50
+ }
51
+ }
52
+
53
+ /*
54
+ * wcj_get_enabled_invoice_types_ids.
55
+ */
56
+ if ( ! function_exists( 'wcj_get_enabled_invoice_types_ids' ) ) {
57
+ function wcj_get_enabled_invoice_types_ids() {
58
+ $invoice_types = wcj_get_enabled_invoice_types();
59
+ $invoice_types_ids = array();
60
+ foreach( $invoice_types as $invoice_type ) {
61
+ $invoice_types_ids[] = $invoice_type['id'];
62
+ }
63
+ return $invoice_types_ids;
64
+ }
65
+ }
66
+
67
+ /*
68
+ * wcj_get_pdf_invoice.
69
+ */
70
+ if ( ! function_exists( 'wcj_get_pdf_invoice' ) ) {
71
+ function wcj_get_pdf_invoice( $order_id, $invoice_type_id ) {
72
+ $the_invoice = new WCJ_PDF_Invoice( $order_id, $invoice_type_id );
73
+ return $the_invoice;
74
+ }
75
+ }
76
+
77
+ /*
78
+ * wcj_get_invoice.
79
+ */
80
+ if ( ! function_exists( 'wcj_get_invoice' ) ) {
81
+ function wcj_get_invoice( $order_id, $invoice_type_id ) {
82
+ $the_invoice = new WCJ_Invoice( $order_id, $invoice_type_id );
83
+ return $the_invoice;
84
+ }
85
+ }
86
+
87
+ /*
88
+ * wcj_get_invoice_date.
89
+ */
90
+ if ( ! function_exists( 'wcj_get_invoice_date' ) ) {
91
+ function wcj_get_invoice_date( $order_id, $invoice_type_id, $extra_days, $date_format ) {
92
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
93
+ $extra_days_in_sec = $extra_days * 24 * 60 * 60;
94
+ return date_i18n( $date_format, date( $the_invoice->get_invoice_date() ) + $extra_days_in_sec );
95
+ }
96
+ }
97
+
98
+ /*
99
+ * wcj_get_invoice_number.
100
+ */
101
+ if ( ! function_exists( 'wcj_get_invoice_number' ) ) {
102
+ function wcj_get_invoice_number( $order_id, $invoice_type_id ) {
103
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
104
+ return $the_invoice->get_invoice_number();
105
+ }
106
+ }
107
+
108
+ /*
109
+ * wcj_delete_invoice.
110
+ */
111
+ if ( ! function_exists( 'wcj_delete_invoice' ) ) {
112
+ function wcj_delete_invoice( $order_id, $invoice_type_id ) {
113
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
114
+ $the_invoice->delete();
115
+ }
116
+ }
117
+
118
+ /*
119
+ * wcj_create_invoice.
120
+ */
121
+ if ( ! function_exists( 'wcj_create_invoice' ) ) {
122
+ function wcj_create_invoice( $order_id, $invoice_type_id, $date = '' ) {
123
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
124
+ $the_invoice->create( $date );
125
+ }
126
+ }
127
+
128
+ /*
129
+ * wcj_is_invoice_created.
130
+ */
131
+ if ( ! function_exists( 'wcj_is_invoice_created' ) ) {
132
+ function wcj_is_invoice_created( $order_id, $invoice_type_id ) {
133
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
134
+ return $the_invoice->is_created();
135
+ }
136
+ }
includes/gateways/class-wc-gateway-wcj-custom.php CHANGED
@@ -258,7 +258,7 @@ function init_wc_gateway_wcj_custom_class() {
258
  */
259
  public function thankyou_page() {
260
  if ( $this->instructions )
261
- echo wpautop( wptexturize( $this->instructions ) );
262
  }
263
 
264
  /**
@@ -270,9 +270,8 @@ function init_wc_gateway_wcj_custom_class() {
270
  * @param bool $plain_text
271
  */
272
  public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
273
- // if ( $this->instructions_in_email && ! $sent_to_admin && 'jetpack_custom_gateway' === $order->payment_method && 'on-hold' === $order->status ) {
274
  if ( $this->instructions_in_email && ! $sent_to_admin && $this->id === $order->payment_method && 'on-hold' === $order->status ) {
275
- echo wpautop( wptexturize( $this->instructions_in_email ) ) . PHP_EOL;
276
  }
277
  }
278
 
258
  */
259
  public function thankyou_page() {
260
  if ( $this->instructions )
261
+ echo do_shortcode( wpautop( wptexturize( $this->instructions ) ) );
262
  }
263
 
264
  /**
270
  * @param bool $plain_text
271
  */
272
  public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
 
273
  if ( $this->instructions_in_email && ! $sent_to_admin && $this->id === $order->payment_method && 'on-hold' === $order->status ) {
274
+ echo do_shortcode( wpautop( wptexturize( $this->instructions_in_email ) ) . PHP_EOL );
275
  }
276
  }
277
 
includes/{abstracts/class-wcj-product-input-fields.php → input-fields/class-wcj-product-input-fields-abstract.php} RENAMED
@@ -4,7 +4,7 @@
4
  *
5
  * The WooCommerce Jetpack Product Input Fields abstract class.
6
  *
7
- * @class WCJ_Product_Input_Fields
8
  * @version 1.0.0
9
  * @category Class
10
  * @author Algoritmika Ltd.
@@ -12,9 +12,9 @@
12
 
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
- if ( ! class_exists( 'WCJ_Product_Input_Fields' ) ) :
16
 
17
- class WCJ_Product_Input_Fields {
18
 
19
  /** @var string scope. */
20
  public $scope = '';
@@ -140,7 +140,7 @@ class WCJ_Product_Input_Fields {
140
  case 'number':
141
  case 'text':
142
  case 'checkbox':
143
- echo '<p>' . $title . '<input type="' . $type . '" name="wcj_product_input_fields_' . $this->scope . '_' . $i . '" value="' . $placeholder . '">' . '</p>';
144
  break;
145
  }
146
  }
4
  *
5
  * The WooCommerce Jetpack Product Input Fields abstract class.
6
  *
7
+ * @class WCJ_Product_Input_Fields_Abstract
8
  * @version 1.0.0
9
  * @category Class
10
  * @author Algoritmika Ltd.
12
 
13
  if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
+ if ( ! class_exists( 'WCJ_Product_Input_Fields_Abstract' ) ) :
16
 
17
+ class WCJ_Product_Input_Fields_Abstract {
18
 
19
  /** @var string scope. */
20
  public $scope = '';
140
  case 'number':
141
  case 'text':
142
  case 'checkbox':
143
+ echo '<p>' . $title . '<input type="' . $type . '" name="wcj_product_input_fields_' . $this->scope . '_' . $i . '" placeholder="' . $placeholder . '" value>' . '</p>';
144
  break;
145
  }
146
  }
includes/{class-wcj-product-input-fields-global.php → input-fields/class-wcj-product-input-fields-global.php} RENAMED
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  if ( ! class_exists( 'WCJ_Product_Input_Fields_Global' ) ) :
16
 
17
- class WCJ_Product_Input_Fields_Global extends WCJ_Product_Input_Fields {
18
 
19
  /**
20
  * Constructor.
@@ -50,12 +50,15 @@ class WCJ_Product_Input_Fields_Global extends WCJ_Product_Input_Fields {
50
  //add_action( 'woocommerce_ajax_added_to_cart', array( $this, 'ajax_add_to_cart' ), 100 );
51
  //add_action( 'woocommerce_loop_add_to_cart_link', array( $this, 'replace_loop_add_to_cart_button' ), 100, 2 );
52
  //add_action( 'woocommerce_after_shop_loop_item', array( $this, 'add_product_input_fields_to_frontend' ), 100 );
 
 
 
53
  }
54
 
55
  // Settings hooks
56
- add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
57
- add_filter( 'wcj_settings_product_input_fields_global', array( $this, 'get_settings' ), 100 );
58
- add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
59
  }
60
 
61
  /**
@@ -103,81 +106,7 @@ class WCJ_Product_Input_Fields_Global extends WCJ_Product_Input_Fields {
103
  return get_option( $option_name, $default );
104
  }
105
 
106
- /**
107
- * add_enabled_option.
108
- */
109
- public function add_enabled_option( $settings ) {
110
- $all_settings = $this->get_settings();
111
- $settings[] = $all_settings[1];
112
- return $settings;
113
- }
114
-
115
- /**
116
- * get_settings.
117
- */
118
- function get_settings() {
119
-
120
- $settings = array(
121
-
122
- array(
123
- 'title' => __( 'Product Input Fields Global Options', 'woocommerce-jetpack' ),
124
- 'type' => 'title',
125
- 'desc' => __( 'Add custom input fields to product\'s single page for customer to fill before adding product to cart.', 'woocommerce-jetpack' ),
126
- 'id' => 'wcj_product_input_fields_global_options',
127
- ),
128
-
129
- array(
130
- 'title' => __( 'Product Input Fields - All Products', 'woocommerce-jetpack' ),
131
- 'desc' => '<strong>' . __( 'Enable', 'woocommerce-jetpack' ) . '</strong>',
132
- 'desc_tip' => __( 'Add custom input fields to all products.', 'woocommerce-jetpack' ),
133
- 'id' => 'wcj_product_input_fields_global_enabled',
134
- 'default' => 'no',
135
- 'type' => 'checkbox',
136
- ),
137
-
138
- array(
139
- 'title' => __( 'Product Input Fields Number', 'woocommerce-jetpack' ),
140
- 'desc_tip' => __( 'Click "Save changes" after you change this number.', 'woocommerce-jetpack' ),
141
- 'id' => 'wcj_product_input_fields_global_total_number',
142
- 'default' => 1,
143
- 'type' => 'number',
144
- 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
145
- 'custom_attributes'
146
- => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
147
- ),
148
- );
149
-
150
- $options = $this->get_options();
151
- for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_product_input_fields_global_total_number', 1 ) ); $i++ ) {
152
- foreach( $options as $option ) {
153
- $settings[] =
154
- array(
155
- 'title' => ( 'wcj_product_input_fields_enabled_global_' === $option['id'] ) ? __( 'Product Input Field', 'woocommerce-jetpack' ) . ' #' . $i : '',
156
- 'desc' => $option['title'],
157
- 'id' => $option['id'] . $i,
158
- 'default' => $option['default'],
159
- 'type' => $option['type'],
160
- 'css' => 'width:30%;min-width:300px;',
161
- );
162
- }
163
- }
164
-
165
- $settings[] =
166
- array(
167
- 'type' => 'sectionend',
168
- 'id' => 'wcj_product_input_fields_global_options',
169
- );
170
-
171
- return $settings;
172
- }
173
-
174
- /**
175
- * settings_section.
176
- */
177
- function settings_section( $sections ) {
178
- $sections['product_input_fields_global'] = __( 'Product Input Fields - All Products', 'woocommerce-jetpack' );
179
- return $sections;
180
- }
181
  }
182
 
183
  endif;
14
 
15
  if ( ! class_exists( 'WCJ_Product_Input_Fields_Global' ) ) :
16
 
17
+ class WCJ_Product_Input_Fields_Global extends WCJ_Product_Input_Fields_Abstract {
18
 
19
  /**
20
  * Constructor.
50
  //add_action( 'woocommerce_ajax_added_to_cart', array( $this, 'ajax_add_to_cart' ), 100 );
51
  //add_action( 'woocommerce_loop_add_to_cart_link', array( $this, 'replace_loop_add_to_cart_button' ), 100, 2 );
52
  //add_action( 'woocommerce_after_shop_loop_item', array( $this, 'add_product_input_fields_to_frontend' ), 100 );
53
+
54
+
55
+
56
  }
57
 
58
  // Settings hooks
59
+ //add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
60
+ //add_filter( 'wcj_settings_product_input_fields_global', array( $this, 'get_settings' ), 100 );
61
+ //add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
62
  }
63
 
64
  /**
106
  return get_option( $option_name, $default );
107
  }
108
 
109
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
111
 
112
  endif;
includes/{class-wcj-product-input-fields-per-product.php → input-fields/class-wcj-product-input-fields-per-product.php} RENAMED
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
14
 
15
  if ( ! class_exists( 'WCJ_Product_Input_Fields_Per_Product' ) ) :
16
 
17
- class WCJ_Product_Input_Fields_Per_Product extends WCJ_Product_Input_Fields {
18
 
19
  /**
20
  * Constructor.
@@ -49,12 +49,14 @@ class WCJ_Product_Input_Fields_Per_Product extends WCJ_Product_Input_Fields {
49
  // Make nicer name for product input fields in order at backend (shop manager)
50
  add_action( 'woocommerce_before_order_itemmeta', array( $this, 'start_making_nicer_name_for_product_input_fields' ), 100, 3 );
51
  add_action( 'woocommerce_after_order_itemmeta', array( $this, 'finish_making_nicer_name_for_product_input_fields' ), 100, 3 );
 
 
52
  }
53
 
54
  // Settings hooks
55
- add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
56
- add_filter( 'wcj_settings_product_input_fields_local', array( $this, 'get_settings' ), 100 );
57
- add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
58
  }
59
 
60
  /**
@@ -174,68 +176,7 @@ class WCJ_Product_Input_Fields_Per_Product extends WCJ_Product_Input_Fields {
174
  // Output
175
  echo $html;
176
  }
177
-
178
- /**
179
- * add_enabled_option.
180
- */
181
- public function add_enabled_option( $settings ) {
182
- $all_settings = $this->get_settings();
183
- $settings[] = $all_settings[1];
184
- return $settings;
185
- }
186
-
187
- /**
188
- * get_settings.
189
- */
190
- function get_settings() {
191
-
192
- $settings = array(
193
-
194
- array(
195
- 'title' => __( 'Product Input Fields per Product Options', 'woocommerce-jetpack' ),
196
- 'type' => 'title',
197
- 'desc' => __( 'Add custom input fields to product\'s single page for customer to fill before adding product to cart.', 'woocommerce-jetpack' )
198
- . ' '
199
- . __( 'When enabled this module will add "Product Input Fields" tab to product\'s "Edit" page.', 'woocommerce-jetpack' ),
200
- 'id' => 'wcj_product_input_fields_local_options',
201
- ),
202
-
203
- array(
204
- 'title' => __( 'Product Input Fields - per Product', 'woocommerce-jetpack' ),
205
- 'desc' => '<strong>' . __( 'Enable', 'woocommerce-jetpack' ) . '</strong>',
206
- 'desc_tip' => __( 'Add custom input field on per product basis.', 'woocommerce-jetpack' ),
207
- 'id' => 'wcj_product_input_fields_local_enabled',
208
- 'default' => 'no',
209
- 'type' => 'checkbox',
210
- ),
211
-
212
- array(
213
- 'title' => __( 'Default Number of Product Input Fields per Product', 'woocommerce-jetpack' ),
214
- 'id' => 'wcj_product_input_fields_local_total_number_default',
215
- 'desc_tip' => __( 'You will be able to change this number later as well as define the fields, for each product individually, in product\'s "Edit".', 'woocommerce-jetpack' ),
216
- 'default' => 1,
217
- 'type' => 'number',
218
- 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
219
- 'custom_attributes'
220
- => apply_filters( 'get_wc_jetpack_plus_message', '', 'readonly' ),
221
- ),
222
-
223
- array(
224
- 'type' => 'sectionend',
225
- 'id' => 'wcj_product_input_fields_local_options',
226
- ),
227
- );
228
-
229
- return $settings;
230
- }
231
-
232
- /**
233
- * settings_section.
234
- */
235
- function settings_section( $sections ) {
236
- $sections['product_input_fields_local'] = __( 'Product Input Fields - per Product', 'woocommerce-jetpack' );
237
- return $sections;
238
- }
239
  }
240
 
241
  endif;
14
 
15
  if ( ! class_exists( 'WCJ_Product_Input_Fields_Per_Product' ) ) :
16
 
17
+ class WCJ_Product_Input_Fields_Per_Product extends WCJ_Product_Input_Fields_Abstract {
18
 
19
  /**
20
  * Constructor.
49
  // Make nicer name for product input fields in order at backend (shop manager)
50
  add_action( 'woocommerce_before_order_itemmeta', array( $this, 'start_making_nicer_name_for_product_input_fields' ), 100, 3 );
51
  add_action( 'woocommerce_after_order_itemmeta', array( $this, 'finish_making_nicer_name_for_product_input_fields' ), 100, 3 );
52
+
53
+
54
  }
55
 
56
  // Settings hooks
57
+ //add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
58
+ //add_filter( 'wcj_settings_product_input_fields_local', array( $this, 'get_settings' ), 100 );
59
+ //add_filter( 'wcj_features_status', array( $this, 'add_enabled_option' ), 100 );
60
  }
61
 
62
  /**
176
  // Output
177
  echo $html;
178
  }
179
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  }
181
 
182
  endif;
includes/js/exchange_rates.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var jsonpCallbacks = {cntr: 0};
2
+
3
+ function doJSONP(from, to, callbackFuncName) {
4
+ var url = "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json";
5
+ var fullURL = url + "&callback=" + callbackFuncName;
6
+ // generate the script tag here
7
+ var script = document.createElement('script');
8
+ script.setAttribute('src', fullURL);
9
+ document.body.appendChild(script);
10
+ }
11
+
12
+ function getRate(from, to, id, fn) {
13
+ // create a globally unique function name
14
+ var name = "fn" + jsonpCallbacks.cntr++;
15
+
16
+ // put that function in a globally accessible place for JSONP to call
17
+ jsonpCallbacks[name] = function() {
18
+ // upon success, remove the name
19
+ delete jsonpCallbacks[name];
20
+ // now call the desired callback internally and pass it the id
21
+ var args = Array.prototype.slice.call(arguments);
22
+ args.unshift(id);
23
+ fn.apply(this, args);
24
+ }
25
+
26
+ doJSONP(from, to, "jsonpCallbacks." + name);
27
+ }
28
+
29
+ function parseExchangeRate(id, data) {
30
+ var name = data.query.results.row.name;
31
+ var rate = parseFloat(data.query.results.row.rate, 10);
32
+ jQuery("#"+id).val(rate);
33
+ }
34
+
35
+ jQuery(document).ready(function() {
36
+ jQuery(".exchage_rate_button").click(function(){
37
+ getRate(this.getAttribute('currency_from'), this.getAttribute('currency_to'), this.getAttribute('multiply_by_field_id'), parseExchangeRate);
38
+ return false;
39
+ });
40
+ });
includes/js/product-input-fields.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery('input,textarea').focus(function(){
3
+ jQuery(this).data('placeholder',jQuery(this).attr('placeholder'))
4
+ jQuery(this).attr('placeholder','');
5
+ });
6
+ jQuery('input,textarea').blur(function(){
7
+ jQuery(this).attr('placeholder',jQuery(this).data('placeholder'));
8
+ });
9
+ });
includes/{tcpdf_min → lib/tcpdf_min}/CHANGELOG.TXT RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/LICENSE.TXT RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/README.TXT RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/composer.json RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/config/tcpdf_config.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/courier.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/courierb.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/courierbi.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/courieri.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.ctg.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusans.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.ctg.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansb.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.ctg.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/dejavusansbi.z RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/helvetica.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticab.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticabi.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/helveticai.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/symbol.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/times.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesb.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesbi.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/timesi.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/fonts/zapfdingbats.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/datamatrix.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/pdf417.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/barcodes/qrcode.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/sRGB.icc RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_colors.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_filters.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_font_data.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_fonts.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_images.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/include/tcpdf_static.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_autoconfig.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_barcodes_1d.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_barcodes_2d.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_import.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tcpdf_parser.php RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tools/.htaccess RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tools/convert_fonts_examples.txt RENAMED
File without changes
includes/{tcpdf_min → lib/tcpdf_min}/tools/tcpdf_addfont.php RENAMED
File without changes
includes/pdf-invoices/class-wcj-pdf-invoicing-renumerate-tool.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoices Renumerate Tool
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoices Renumerate Tool class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Renumerate_Tool
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Renumerate_Tool' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Renumerate_Tool {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ add_filter( 'wcj_tools_tabs', array( $this, 'add_renumerate_invoices_tool_tab' ), 100 );
24
+ add_action( 'wcj_tools_renumerate_invoices', array( $this, 'create_renumerate_invoices_tool' ), 100 );
25
+ add_action( 'wcj_tools_dashboard', array( $this, 'add_renumerate_invoices_tool_info_to_tools_dashboard' ), 100 );
26
+
27
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
28
+ add_action( 'admin_head', array( $this, 'add_datepicker_script' ) );
29
+ }
30
+
31
+ /**
32
+ * enqueue_scripts.
33
+ */
34
+ public function enqueue_scripts() {
35
+ wp_enqueue_script('jquery-ui-datepicker');
36
+ wp_enqueue_style( 'jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
37
+ }
38
+
39
+ public function add_datepicker_script() {
40
+ ?>
41
+ <script>
42
+ jQuery(document).ready(function() {
43
+ jQuery("input[display='date']").datepicker({
44
+ dateFormat : '<?php echo wcj_date_format_php_to_js( get_option( 'date_format' ) ); ?>'
45
+ });
46
+ });
47
+ </script>
48
+ <?php
49
+ }
50
+
51
+ /**
52
+ * add_renumerate_invoices_tool_info_to_tools_dashboard.
53
+ */
54
+ public function add_renumerate_invoices_tool_info_to_tools_dashboard() {
55
+ echo '<tr>';
56
+ if ( 'yes' === get_option( 'wcj_pdf_invoicing_enabled') )
57
+ $is_enabled = '<span style="color:green;font-style:italic;">' . __( 'enabled', 'woocommerce-jetpack' ) . '</span>';
58
+ else
59
+ $is_enabled = '<span style="color:gray;font-style:italic;">' . __( 'disabled', 'woocommerce-jetpack' ) . '</span>';
60
+ echo '<td>' . __( 'Invoices Renumerate', 'woocommerce-jetpack' ) . '</td>';
61
+ echo '<td>' . $is_enabled . '</td>';
62
+ echo '<td>' . __( 'Tool renumerates all invoices, proforma invoices and packing slips.', 'woocommerce-jetpack' ) . '</td>';
63
+ echo '</tr>';
64
+ }
65
+
66
+ /**
67
+ * add_renumerate_invoices_tool_tab.
68
+ */
69
+ public function add_renumerate_invoices_tool_tab( $tabs ) {
70
+ $tabs[] = array(
71
+ 'id' => 'renumerate_invoices',
72
+ 'title' => __( 'Renumerate Invoices', 'woocommerce-jetpack' ),
73
+ );
74
+ return $tabs;
75
+ }
76
+
77
+ function wcj_multi_selected( $selected, $current_multi ) {
78
+ if ( ! is_array( $current_multi ) ) return selected( $selected, $current_multi, false );
79
+ foreach( $current_multi as $current ) {
80
+ $selected_single = selected( $selected, $current, false );
81
+ if ( '' != $selected_single ) return $selected_single;
82
+ }
83
+ return '';
84
+ }
85
+
86
+ /**
87
+ * Add Renumerate Invoices tool to WooCommerce menu (the content).
88
+ */
89
+ public function create_renumerate_invoices_tool() {
90
+ $result_message = '';
91
+ $renumerate_result = '';
92
+
93
+ $the_invoice_type = ( ! empty( $_POST['invoice_type'] ) ) ? $_POST['invoice_type'] : 'invoice';
94
+ $the_start_number = ( ! empty( $_POST['start_number'] ) ) ? $_POST['start_number'] : 0;
95
+ $the_start_date = ( ! empty( $_POST['start_date'] ) ) ? $_POST['start_date'] : '';
96
+ $the_order_statuses = ( ! empty( $_POST['order_statuses'] ) ) ? $_POST['order_statuses'] : array();
97
+ $the_delete_all = ( isset( $_POST['delete_all'] ) ) ? true : false;
98
+
99
+ if ( isset( $_POST['renumerate_invoices'] ) ) {
100
+ if ( ! empty( $the_order_statuses ) ) {
101
+ $renumerate_result = $this->renumerate_invoices( $the_invoice_type, $the_start_number, $the_start_date, $the_order_statuses, $the_delete_all );
102
+ $result_message = '<div class="updated"><p><strong>' . __( 'Invoices successfully renumerated!', 'woocommerce-jetpack' ) . '</strong></p></div>';
103
+ } else {
104
+ $result_message = '<div class="error"><p><strong>' . __( 'Please select at leat one order status.', 'woocommerce-jetpack' ) . '</strong></p></div>';
105
+ }
106
+ //$result_message .= '<p>' . $renumerate_result . '</p>';
107
+ }
108
+ ?><div>
109
+ <h2><?php echo __( 'WooCommerce Jetpack - Renumerate Invoices', 'woocommerce-jetpack' ); ?></h2>
110
+ <p><?php echo __( 'The tool renumerates invoices from choosen date. Invoice number format is set in WooCommerce > Settings > Jetpack > PDF Invoices (v2) > Numbering.', 'woocommerce-jetpack' ); ?></p>
111
+ <?php echo $result_message; ?>
112
+ <p><form method="post" action="">
113
+ <?php
114
+
115
+ // Date
116
+ $data[] = array(
117
+ __( 'Start Date', 'woocommerce-jetpack' ),
118
+ '<input class="input-text" display="date" type="text" name="start_date" value="' . $the_start_date . '">',
119
+ '<em>' . __( 'Date to start renumerating. Leave blank to renumerate all invoices.', 'woocommerce-jetpack' ) . '</em>',
120
+ );
121
+
122
+ // Number
123
+ $data[] = array(
124
+ __( 'Start Number', 'woocommerce-jetpack' ),
125
+ '<input class="input-text" type="text" name="start_number" value="' . $the_start_number . '">',
126
+ '<em>' . __( 'Counter to start renumerating. Leave 0 to continue from current counter.', 'woocommerce-jetpack' ) . '</em>',
127
+ );
128
+
129
+ // Delete All
130
+ $data[] = array(
131
+ __( 'Delete All', 'woocommerce-jetpack' ),
132
+ '<input type="checkbox" name="delete_all" value="" ' . checked( $the_delete_all, true, false ) . '>',
133
+ '<em>' . __( 'Clear all invoices before renumerating.', 'woocommerce-jetpack' ) . '</em>',
134
+ );
135
+
136
+ // Type
137
+ $invoice_type_select_html = '<select name="invoice_type">';
138
+ //$invoice_types = wcj_get_invoice_types();
139
+ $invoice_types = wcj_get_enabled_invoice_types();
140
+ foreach ( $invoice_types as $invoice_type ) {
141
+ $invoice_type_select_html .= '<option value="' . $invoice_type['id'] . '" ' . selected( $invoice_type['id'], $the_invoice_type, false ) . '>' . $invoice_type['title'] . '</option>';
142
+ }
143
+ $invoice_type_select_html .= '</select>';
144
+ $data[] = array( __( 'Document Type', 'woocommerce-jetpack' ), $invoice_type_select_html, '', );
145
+
146
+ // Statuses
147
+ $order_statuses_select_html = '<select id="order_statuses" name="order_statuses[]" multiple size="5">';
148
+ $order_statuses = wcj_get_order_statuses( false );
149
+ foreach ( $order_statuses as $status => $desc ) {
150
+ //$order_statuses_select_html .= '<option value="' . $status . '">' . $desc . '</option>';
151
+ $order_statuses_select_html .= '<option value="' . $status . '" ' . $this->wcj_multi_selected( $status, $the_order_statuses ) . '>' . $desc . '</option>';
152
+ }
153
+ $order_statuses_select_html .= '</select>';
154
+ $data[] = array( __( 'Order Statuses', 'woocommerce-jetpack' ), $order_statuses_select_html, '', );
155
+
156
+ // Print all
157
+ echo wcj_get_table_html( $data, array( 'table_heading_type' => 'vertical', ) );
158
+
159
+ ?>
160
+ <input type="submit" name="renumerate_invoices" value="Renumerate invoices">
161
+ </form></p>
162
+ <?php
163
+ if ( '' != $renumerate_result ) {
164
+ echo '<h3>' . __( 'Results', 'woocommerce-jetpack' ) . '</h3>';
165
+ echo '<p>' . $renumerate_result . '</p>';
166
+ }
167
+ ?>
168
+ </div><?php
169
+ }
170
+
171
+ /**
172
+ * Renumerate invoices function.
173
+ */
174
+ public function renumerate_invoices( $invoice_type, $start_number, $start_date, $order_statuses, $the_delete_all ) {
175
+
176
+ $output = '';
177
+
178
+ if ( 0 != $start_number ) {
179
+ update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', $start_number );
180
+ }
181
+
182
+ $args = array(
183
+ 'post_type' => 'shop_order',
184
+ 'post_status' => 'any',
185
+ 'posts_per_page' => -1,
186
+ 'orderby' => 'date',
187
+ 'order' => 'ASC',
188
+ );
189
+
190
+ $loop = new WP_Query( $args );
191
+
192
+ $deleted_invoices_counter = 0;
193
+ $created_invoices_counter = 0;
194
+ while ( $loop->have_posts() ) : $loop->the_post();
195
+
196
+ $order_id = $loop->post->ID;
197
+ if ( in_array( $loop->post->post_status, $order_statuses ) && strtotime( $loop->post->post_date ) >= strtotime( $start_date ) ) {
198
+
199
+ $the_order = wc_get_order( $order_id );
200
+ if ( 0 != $the_order->get_total() ) {
201
+
202
+ wcj_create_invoice( $order_id, $invoice_type, strtotime( $loop->post->post_date ) );
203
+ $created_invoices_counter++;
204
+ }
205
+ } else {
206
+ if ( $the_delete_all && wcj_is_invoice_created( $order_id, $invoice_type ) ) {
207
+ wcj_delete_invoice( $order_id, $invoice_type );
208
+ $deleted_invoices_counter++;
209
+ }
210
+ }
211
+
212
+ endwhile;
213
+
214
+ $output .= '<p>' . sprintf( __( 'Total documents created: %d', 'woocommerce-jetpack' ), $created_invoices_counter ) . '</p>';
215
+ $output .= '<p>' . sprintf( __( 'Total documents deleted: %d', 'woocommerce-jetpack' ), $deleted_invoices_counter ) . '</p>';
216
+
217
+ return $output;
218
+ }
219
+ }
220
+
221
+ endif;
222
+
223
+ return new WCJ_PDF_Invoicing_Renumerate_Tool();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-display.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Display
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Display class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Display
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Display' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Display {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ function __construct() {
23
+
24
+ if ( 'yes' === get_option( 'wcj_pdf_invoicing_enabled' ) ) {
25
+
26
+ // Columns on Admin's Orders page
27
+ add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_order_column' ), PHP_INT_MAX );
28
+ add_action( 'manage_shop_order_posts_custom_column', array( $this, 'render_order_columns' ), 2 );
29
+
30
+ // Action Links on Admin's Orders page
31
+ //add_filter( 'woocommerce_admin_order_actions', array( $this, 'add_pdf_invoices_action_links' ), PHP_INT_MAX, 2 );
32
+ //add_action( 'admin_head', array( $this, 'add_pdf_invoice_icon_css' ) );
33
+
34
+ // Action Links on Customer's My Account page
35
+ add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'add_pdf_invoices_action_links' ), PHP_INT_MAX, 2 );
36
+ }
37
+
38
+ // Settings hooks
39
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
40
+ add_filter( 'wcj_settings_pdf_invoicing_display', array( $this, 'get_settings' ), 100 );
41
+ }
42
+
43
+ /**
44
+ * add_order_column.
45
+ */
46
+ function add_order_column( $columns ) {
47
+ $invoice_types = wcj_get_enabled_invoice_types();
48
+ foreach ( $invoice_types as $invoice_type ) {
49
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page_column', 'yes' ) ) {
50
+ $columns[ $invoice_type['id'] ] = $invoice_type['title'];
51
+ }
52
+ }
53
+ return $columns;
54
+ }
55
+
56
+ /**
57
+ * Ouput custom columns for products
58
+ * @param string $column
59
+ */
60
+ public function render_order_columns( $column ) {
61
+
62
+ $invoice_types_ids = wcj_get_enabled_invoice_types_ids();
63
+ if ( ! in_array( $column, $invoice_types_ids ) ) {
64
+ return;
65
+ }
66
+
67
+ $order_id = get_the_ID();
68
+ $invoice_type_id = $column;
69
+
70
+ if ( ! wcj_is_invoice_created( $order_id, $invoice_type_id ) )
71
+ return;
72
+
73
+ $the_invoice = wcj_get_invoice( $order_id, $invoice_type_id );
74
+ //$the_number = $the_invoice->get_invoice_full_number();
75
+ $the_number = $the_invoice->get_invoice_number();
76
+ //$the_url = $the_invoice->get_invoice_url();
77
+ //$the_link = $the_invoice->get_invoice_link();
78
+ $query_args = array( 'order_id' => $order_id, 'invoice_type_id' => $invoice_type_id, 'get_invoice' => '1', );
79
+ $the_link = '<a href="' . add_query_arg( $query_args ) . '">' . $the_number . '</a>';
80
+
81
+ echo $the_link;
82
+ }
83
+
84
+ /**
85
+ * add_pdf_invoice_icon_css.
86
+ *
87
+ function add_pdf_invoice_icon_css() {
88
+ $invoice_types = wcj_get_enabled_invoice_types();
89
+ foreach ( $invoice_types as $invoice_type ) {
90
+ echo '<style> a.button.tips.view.' . $invoice_type['id'] . ':after { content: "' . $invoice_type['icon'] . '" !important; } </style>';
91
+ }
92
+ }
93
+
94
+ /**
95
+ * add_pdf_invoices_action_links.
96
+ */
97
+ function add_pdf_invoices_action_links( $actions, $the_order ) {
98
+
99
+
100
+
101
+ $invoice_types = wcj_get_enabled_invoice_types();
102
+ foreach ( $invoice_types as $invoice_type ) {
103
+
104
+ if ( ! wcj_is_invoice_created( $the_order->id, $invoice_type['id'] ) )
105
+ continue;
106
+
107
+ //$admin_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page';
108
+ $my_account_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers';
109
+
110
+ /*if ( ( 'woocommerce_admin_order_actions' === current_filter() && 'add_action_link' === get_option( $admin_option_name, 'add_column' ) ) ||
111
+ ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) ) {*/
112
+
113
+ //if ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) {
114
+ if ( 'yes' === get_option( $my_account_option_name, 'no' ) ) {
115
+
116
+ $the_action_id = $invoice_type['id'];
117
+
118
+ //$the_url = basename( $_SERVER['REQUEST_URI'] ) . '&order_id=' . $the_order->id . '&invoice_type_id=' . $invoice_type['id'] . '&get_invoice=1';
119
+ $query_args = array( 'order_id' => $the_order->id, 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1', );
120
+ $the_url = add_query_arg( $query_args );
121
+
122
+ $the_name = $invoice_type['desc'];
123
+ $the_action = 'view ' . $invoice_type['id'];
124
+
125
+ if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
126
+ $the_url .= '&save_pdf_invoice=1';
127
+ }
128
+
129
+ $actions[ $the_action_id ] = array( 'url' => $the_url, 'name' => $the_name, 'action' => $the_action, );
130
+ }
131
+ }
132
+
133
+ return $actions;
134
+ }
135
+
136
+ /**
137
+ * get_settings.
138
+ */
139
+ function get_settings() {
140
+
141
+ $settings = array();
142
+ $invoice_types = wcj_get_invoice_types();
143
+ foreach ( $invoice_types as $invoice_type ) {
144
+
145
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_display_options' );
146
+
147
+ $settings = array_merge( $settings, array(
148
+ array(
149
+ 'title' => __( 'Admin\'s "Orders" Page', 'woocommerce-jetpack' ),
150
+ 'desc' => __( 'Add Column', 'woocommerce-jetpack' ),
151
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page_column',
152
+ 'default' => 'yes',
153
+ 'type' => 'checkbox',
154
+ /*'class' => 'chosen_select',
155
+ 'options' => array(
156
+ 'add_column' => __( 'Add Column', 'woocommerce-jetpack' ),
157
+ 'add_action_link' => __( 'Add Action Link', 'woocommerce-jetpack' ),
158
+ ),*/
159
+ ),
160
+
161
+ array(
162
+ 'title' => __( 'Customer\'s "My Account" Page', 'woocommerce-jetpack' ),
163
+ //'desc' => __( 'Enable the PDF Invoices in customers account', 'woocommerce-jetpack' ),
164
+ 'desc' => __( 'Add link', 'woocommerce-jetpack' ),
165
+ 'desc_tip' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
166
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers',
167
+ 'default' => 'no',
168
+ 'type' => 'checkbox',
169
+ 'custom_attributes' => apply_filters( 'get_wc_jetpack_plus_message', '', 'disabled' ),
170
+ ),
171
+
172
+ array(
173
+ 'title' => __( 'Enable "Save as"', 'woocommerce-jetpack' ),
174
+ 'desc' => __( 'Enable', 'woocommerce-jetpack' ),
175
+ 'desc_tip' => __( 'Enable "save as" pdf instead of view pdf in browser', 'woocommerce-jetpack' ),
176
+ //'desc_tip' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
177
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled',
178
+ 'default' => 'no',
179
+ 'type' => 'checkbox',
180
+ //'custom_attributes' => apply_filters( 'get_wc_jetpack_plus_message', '', 'disabled' ),
181
+ ),
182
+
183
+ array(
184
+ 'title' => __( 'PDF File Name', 'woocommerce-jetpack' ),
185
+ 'desc' => __( 'Enter file name for PDF documents. You can use shortcodes here, e.g. [wcj_' . $invoice_type['id'] . '_number]', 'woocommerce-jetpack' ),
186
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_file_name',
187
+ 'default' => '[wcj_' . $invoice_type['id'] . '_number]',
188
+ 'type' => 'text',
189
+ ),
190
+ ) );
191
+
192
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_display_options' );
193
+ }
194
+
195
+ return $settings;
196
+ }
197
+
198
+ /**
199
+ * settings_section.
200
+ */
201
+ function settings_section( $sections ) {
202
+ $sections['pdf_invoicing_display'] = __( 'Misc.', 'woocommerce-jetpack' );
203
+ return $sections;
204
+ }
205
+ }
206
+
207
+ endif;
208
+
209
+ return new WCJ_PDF_Invoicing_Display();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-emails.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Emails
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Emails class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Emails
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Emails' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Emails {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ function __construct() {
23
+
24
+ if ( 'yes' === get_option( 'wcj_pdf_invoicing_enabled' ) ) {
25
+ add_filter( 'woocommerce_email_attachments', array( $this, 'add_pdf_invoice_email_attachment' ), PHP_INT_MAX, 3 );
26
+ }
27
+
28
+ // Settings hooks
29
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
30
+ add_filter( 'wcj_settings_pdf_invoicing_emails', array( $this, 'get_settings' ), 100 );
31
+ }
32
+
33
+ /**
34
+ * do_attach_for_payment_method.
35
+ *
36
+ function do_attach_for_payment_method( $payment_method ) {
37
+ return ( 'no' === get_option( 'wcj_gateways_attach_invoice_' . $payment_method, 'yes' ) ) ? false : true;
38
+ }
39
+
40
+ /**
41
+ * add_pdf_invoice_email_attachment.
42
+ */
43
+ function add_pdf_invoice_email_attachment( $attachments, $status, $order ) {
44
+ $invoice_types_ids = wcj_get_enabled_invoice_types_ids();
45
+ foreach ( $invoice_types_ids as $invoice_type_id ) {
46
+ //if ( 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( 'wcj_invoicing_' . $invoice_type_id . '_attach_to_email_enabled' ) ) ) {
47
+ //if ( isset( $status ) && 'customer_completed_order' === $status && isset( $order ) && true === $this->do_attach_for_payment_method( $order->payment_method ) ) {
48
+ //if ( 'customer_completed_order' === $status ) {
49
+ $send_on_statuses = get_option( 'wcj_invoicing_' . $invoice_type_id . '_attach_to_emails', array() );
50
+ if ( '' == $send_on_statuses )
51
+ $send_on_statuses = array();
52
+ if ( in_array( $status, $send_on_statuses ) ) {
53
+ $the_invoice = wcj_get_pdf_invoice( $order->id, $invoice_type_id );
54
+ $file_name = $the_invoice->get_pdf( 'F' );
55
+ if ( '' != $file_name ) {
56
+ $attachments[] = $file_name;
57
+ }
58
+ }
59
+ }
60
+ return $attachments;
61
+ }
62
+
63
+ /**
64
+ * get_settings.
65
+ */
66
+ function get_settings() {
67
+
68
+ $settings = array();
69
+ $invoice_types = wcj_get_invoice_types();
70
+ foreach ( $invoice_types as $invoice_type ) {
71
+
72
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_emails_options' );
73
+
74
+ //$available_emails = apply_filters( 'woocommerce_resend_order_emails_available', array( 'new_order', 'customer_processing_order', 'customer_completed_order', 'customer_invoice' ) );
75
+ $available_emails = array(
76
+ 'new_order' => __( 'New Order (Admin and Customer)', 'woocommerce' ),
77
+ 'customer_processing_order' => __( 'Customer Processing Order', 'woocommerce' ),
78
+ 'customer_completed_order' => __( 'Customer Completed Order', 'woocommerce' ),
79
+ 'customer_invoice' => __( 'Customer Invoice', 'woocommerce' ),
80
+ );
81
+
82
+ $settings[] = array(
83
+ 'title' => __( 'Attach PDF to emails', 'woocommerce' ),
84
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_attach_to_emails',
85
+ 'type' => 'multiselect',
86
+ 'class' => 'chosen_select',
87
+ 'css' => 'width: 450px;',
88
+ //'default' => 'new_order',
89
+ 'default' => '',
90
+ 'options' => $available_emails,
91
+ 'custom_attributes' => array(
92
+ 'data-placeholder' => __( 'Select some emails', 'woocommerce' )
93
+ )
94
+ );
95
+
96
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_emails_options' );
97
+ }
98
+
99
+ return $settings;
100
+ }
101
+
102
+ /**
103
+ * settings_section.
104
+ */
105
+ function settings_section( $sections ) {
106
+ $sections['pdf_invoicing_emails'] = __( 'Email Options', 'woocommerce-jetpack' );
107
+ return $sections;
108
+ }
109
+ }
110
+
111
+ endif;
112
+
113
+ return new WCJ_PDF_Invoicing_Emails();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-footer.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Footer
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Footer class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Footer
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Footer' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Footer {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // Settings hooks
24
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
25
+ add_filter( 'wcj_settings_pdf_invoicing_footer', array( $this, 'get_settings' ), 100 );
26
+ }
27
+
28
+ /**
29
+ * get_settings.
30
+ */
31
+ function get_settings() {
32
+
33
+ $settings = array();
34
+ $invoice_types = wcj_get_invoice_types();
35
+ foreach ( $invoice_types as $invoice_type ) {
36
+
37
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_options' );
38
+
39
+ $settings = array_merge( $settings, array(
40
+
41
+ array(
42
+ 'title' => __( 'Enable Footer', 'woocommerce-jetpack' ),
43
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_enabled',
44
+ 'default' => 'yes',
45
+ 'type' => 'checkbox',
46
+ ),
47
+
48
+ array(
49
+ 'title' => __( 'Footer Text Color', 'woocommerce-jetpack' ),
50
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_text_color',
51
+ 'default' => '#cccccc',
52
+ 'type' => 'color',
53
+ 'css' => 'width:6em;',
54
+ ),
55
+
56
+ array(
57
+ 'title' => __( 'Footer Line Color', 'woocommerce-jetpack' ),
58
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_line_color',
59
+ 'default' => '#cccccc',
60
+ 'type' => 'color',
61
+ 'css' => 'width:6em;',
62
+ ),
63
+
64
+ array(
65
+ 'title' => __( 'Footer Margin', 'woocommerce-jetpack' ),
66
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_footer',
67
+ 'default' => 10,//PDF_MARGIN_FOOTER
68
+ 'type' => 'number',
69
+ ),
70
+
71
+ ) );
72
+
73
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_footer_options' );
74
+ }
75
+
76
+ return $settings;
77
+ }
78
+
79
+ /**
80
+ * settings_section.
81
+ */
82
+ function settings_section( $sections ) {
83
+ $sections['pdf_invoicing_footer'] = __( 'Footer', 'woocommerce-jetpack' );
84
+ return $sections;
85
+ }
86
+ }
87
+
88
+ endif;
89
+
90
+ return new WCJ_PDF_Invoicing_Footer();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-header.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Header
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Header class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Header
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Header' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Header {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // Settings hooks
24
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
25
+ add_filter( 'wcj_settings_pdf_invoicing_header', array( $this, 'get_settings' ), 100 );
26
+ }
27
+
28
+ /**
29
+ * get_settings.
30
+ */
31
+ function get_settings() {
32
+
33
+ $settings = array();
34
+ $invoice_types = wcj_get_invoice_types();
35
+ foreach ( $invoice_types as $invoice_type ) {
36
+
37
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options' );
38
+
39
+ $settings = array_merge( $settings, array(
40
+
41
+ array(
42
+ 'title' => __( 'Enable Header', 'woocommerce-jetpack' ),
43
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_enabled',
44
+ 'default' => 'yes',
45
+ 'type' => 'checkbox',
46
+ ),
47
+
48
+ array(
49
+ 'title' => __( 'Header Image', 'woocommerce-jetpack' ),
50
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image',
51
+ 'default' => '',
52
+ 'type' => 'text',
53
+ 'css' => 'width:33%;min-width:300px;',
54
+ 'desc' => __( 'Enter a URL to an image you want to show in the invoice\'s header. Upload your image using the <a href="/wp-admin/media-new.php">media uploader</a>.', 'woocommerce-jetpack' ),
55
+ 'desc_tip' => __( 'Leave blank to disable', 'woocommerce-jetpack' ),
56
+ ),
57
+
58
+ array(
59
+ 'title' => __( 'Header Image Width in mm', 'woocommerce-jetpack' ),
60
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_image_width_mm',
61
+ 'default' => 50,
62
+ 'type' => 'number',
63
+ ),
64
+
65
+ array(
66
+ 'title' => __( 'Header Title', 'woocommerce-jetpack' ),
67
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_title_text',
68
+ 'default' => $invoice_type['title'],
69
+ 'type' => 'text',
70
+ //'css' => 'width:66%;min-width:300px;height:165px;',
71
+ ),
72
+
73
+ array(
74
+ 'title' => __( 'Header Text', 'woocommerce-jetpack' ),
75
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text',
76
+ 'default' => __( 'Company Name', 'woocommerce-jetpack' ),
77
+ 'type' => 'text',
78
+ //'css' => 'width:66%;min-width:300px;height:165px;',
79
+ 'desc' => apply_filters( 'wcj_get_option_filter', __( 'free version will add "powered by woojetpack.com" to heading text', 'woocommerce-jetpack' ), '' ),
80
+ ),
81
+
82
+ array(
83
+ 'title' => __( 'Header Text Color', 'woocommerce-jetpack' ),
84
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_text_color',
85
+ 'default' => '#cccccc',
86
+ 'type' => 'color',
87
+ 'css' => 'width:6em;',
88
+ ),
89
+
90
+ array(
91
+ 'title' => __( 'Header Line Color', 'woocommerce-jetpack' ),
92
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_line_color',
93
+ 'default' => '#cccccc',
94
+ 'type' => 'color',
95
+ 'css' => 'width:6em;',
96
+ ),
97
+
98
+ array(
99
+ 'title' => __( 'Header Margin', 'woocommerce-jetpack' ),
100
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_header',
101
+ 'default' => 10,//PDF_MARGIN_HEADER
102
+ 'type' => 'number',
103
+ ),
104
+ ) );
105
+
106
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_header_options' );
107
+ }
108
+
109
+ return $settings;
110
+ }
111
+
112
+ /**
113
+ * settings_section.
114
+ */
115
+ function settings_section( $sections ) {
116
+ $sections['pdf_invoicing_header'] = __( 'Header', 'woocommerce-jetpack' );
117
+ return $sections;
118
+ }
119
+ }
120
+
121
+ endif;
122
+
123
+ return new WCJ_PDF_Invoicing_Header();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-numbering.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoices Numbering
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoices Numbering class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Numbering
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Numbering' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Numbering {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // Settings hooks
24
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
25
+ add_filter( 'wcj_settings_pdf_invoicing_numbering', array( $this, 'get_settings' ), 100 );
26
+ }
27
+
28
+ /**
29
+ * get_settings.
30
+ */
31
+ function get_settings() {
32
+
33
+ $settings = array();
34
+ $invoice_types = wcj_get_invoice_types();
35
+ foreach ( $invoice_types as $invoice_type ) {
36
+
37
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_options' );
38
+ $settings[] = array(
39
+ 'title' => __( 'Sequential', 'woocommerce-jetpack' ),
40
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_sequential_enabled',
41
+ 'default' => 'no',
42
+ 'type' => 'checkbox',
43
+ );
44
+ $settings[] = array(
45
+ 'title' => __( 'Counter', 'woocommerce-jetpack' ),
46
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_counter',
47
+ 'default' => 1,
48
+ 'type' => 'number',
49
+ );
50
+ $settings[] = array(
51
+ 'title' => __( 'Prefix', 'woocommerce-jetpack' ),
52
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_prefix',
53
+ 'default' => '',
54
+ 'type' => 'text',
55
+ );
56
+ $settings[] = array(
57
+ 'title' => __( 'Counter Width', 'woocommerce-jetpack' ),
58
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_counter_width',
59
+ 'default' => 0,
60
+ 'type' => 'number',
61
+ );
62
+ $settings[] = array(
63
+ 'title' => __( 'Suffix', 'woocommerce-jetpack' ),
64
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_suffix',
65
+ 'default' => '',
66
+ 'type' => 'text',
67
+ );
68
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_numbering_options' );
69
+ }
70
+
71
+ return $settings;
72
+ }
73
+
74
+ /**
75
+ * settings_section.
76
+ */
77
+ function settings_section( $sections ) {
78
+ $sections['pdf_invoicing_numbering'] = __( 'Numbering', 'woocommerce-jetpack' );
79
+ return $sections;
80
+ }
81
+ }
82
+
83
+ endif;
84
+
85
+ return new WCJ_PDF_Invoicing_Numbering();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-page.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Page
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Page class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Page
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Page' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Page {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ function __construct() {
23
+ /*if ( 'yes' === get_option( 'wcj_pdf_invoicing_enabled' ) ) {
24
+
25
+ }*/
26
+ // Settings hooks
27
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
28
+ add_filter( 'wcj_settings_pdf_invoicing_page', array( $this, 'get_settings' ), 100 );
29
+ }
30
+
31
+ /**
32
+ * get_settings.
33
+ */
34
+ function get_settings() {
35
+
36
+ $settings = array();
37
+ $invoice_types = wcj_get_invoice_types();
38
+ foreach ( $invoice_types as $invoice_type ) {
39
+
40
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_options' );
41
+
42
+ $settings[] = array(
43
+ 'title' => __( 'Page Orientation', 'woocommerce-jetpack' ),
44
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_orientation',
45
+ 'default' => 'P',
46
+ 'type' => 'select',
47
+ 'options' => array(
48
+ 'P' => __( 'Portrait', 'woocommerce-jetpack' ),
49
+ 'L' => __( 'Landscape', 'woocommerce-jetpack' ),
50
+ ),
51
+ );
52
+
53
+ $settings[] = array(
54
+ 'title' => __( 'Margin Left', 'woocommerce-jetpack' ),
55
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_left',
56
+ 'default' => 15,//PDF_MARGIN_LEFT,
57
+ 'type' => 'number',
58
+ );
59
+
60
+ $settings[] = array(
61
+ 'title' => __( 'Margin Right', 'woocommerce-jetpack' ),
62
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_right',
63
+ 'default' => 15,//PDF_MARGIN_RIGHT,
64
+ 'type' => 'number',
65
+ );
66
+
67
+ $settings[] = array(
68
+ 'title' => __( 'Margin Top', 'woocommerce-jetpack' ),
69
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_top',
70
+ 'default' => 27,//PDF_MARGIN_TOP,
71
+ 'type' => 'number',
72
+ );
73
+
74
+ $settings[] = array(
75
+ 'title' => __( 'Margin Bottom', 'woocommerce-jetpack' ),
76
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_margin_bottom',
77
+ 'default' => 0,//PDF_MARGIN_BOTTOM,
78
+ 'type' => 'number',
79
+ );
80
+
81
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_page_options' );
82
+ }
83
+
84
+ return $settings;
85
+ }
86
+
87
+ /**
88
+ * settings_section.
89
+ */
90
+ function settings_section( $sections ) {
91
+ $sections['pdf_invoicing_page'] = __( 'Page Settings', 'woocommerce-jetpack' );
92
+ return $sections;
93
+ }
94
+ }
95
+
96
+ endif;
97
+
98
+ return new WCJ_PDF_Invoicing_Page();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-styling.php ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoicing Styling
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoicing Styling class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Styling
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Styling' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Styling {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // Settings hooks
24
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
25
+ add_filter( 'wcj_settings_pdf_invoicing_styling', array( $this, 'get_settings' ), 100 );
26
+ }
27
+
28
+ /**
29
+ * get_settings.
30
+ */
31
+ function get_settings() {
32
+
33
+ $settings = array();
34
+
35
+ $invoice_types = wcj_get_invoice_types();
36
+ foreach ( $invoice_types as $invoice_type ) {
37
+
38
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_styling_options' );
39
+
40
+ //$default_template = include( 'defaults/' . $invoice_type['id'] . '/wcj-content-template.php' );
41
+ ob_start();
42
+ include( 'defaults/wcj-' . $invoice_type['id'] . '.css' );
43
+ $default_template = ob_get_clean();
44
+
45
+ $settings[] = array(
46
+ 'title' => __( 'CSS', 'woocommerce-jetpack' ),
47
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_css',
48
+ 'default' => $default_template,
49
+ 'type' => 'textarea',
50
+ 'css' => 'width:66%;min-width:300px;height:200px;',
51
+ );
52
+
53
+ $settings[] = array(
54
+ 'title' => __( 'Font Family', 'woocommerce-jetpack' ),
55
+ //'desc' => __( 'Default: dejavusans', 'woocommerce-jetpack' ),
56
+ 'desc' => apply_filters( 'get_wc_jetpack_plus_message', '', 'desc' ),
57
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_family',
58
+ 'default' => 'dejavusans',
59
+ 'type' => 'select',
60
+ 'options' => array(
61
+ 'dejavusans' => 'DejaVu Sans',
62
+ 'courier' => 'Courier',
63
+ 'helvetica' => 'Helvetica',
64
+ 'times' => 'Times',
65
+ ),
66
+ 'custom_attributes' => apply_filters( 'get_wc_jetpack_plus_message', '', 'disabled' ),
67
+ );
68
+
69
+ $settings[] = array(
70
+ 'title' => __( 'Font Size', 'woocommerce-jetpack' ),
71
+ //'desc' => __( 'Default: 8', 'woocommerce-jetpack' ),
72
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_size',
73
+ 'default' => 8,
74
+ 'type' => 'number',
75
+ //'css' => 'width:50px;',
76
+ );
77
+
78
+ $settings[] = array(
79
+ 'title' => __( 'Make Font Shadowed', 'woocommerce-jetpack' ),
80
+ //'desc' => __( 'Default: Yes', 'woocommerce-jetpack' ),
81
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_general_font_shadowed',
82
+ 'default' => 'no',
83
+ 'type' => 'checkbox',
84
+ );
85
+
86
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_styling_options' );
87
+ }
88
+
89
+ return $settings;
90
+ }
91
+
92
+ /**
93
+ * settings_section.
94
+ */
95
+ function settings_section( $sections ) {
96
+ $sections['pdf_invoicing_styling'] = __( 'Styling', 'woocommerce-jetpack' );
97
+ return $sections;
98
+ }
99
+ }
100
+
101
+ endif;
102
+
103
+ return new WCJ_PDF_Invoicing_Styling();
includes/pdf-invoices/settings/class-wcj-pdf-invoicing-templates.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack PDF Invoices Templates
4
+ *
5
+ * The WooCommerce Jetpack PDF Invoices Templates class.
6
+ *
7
+ * @class WCJ_PDF_Invoicing_Templates
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_PDF_Invoicing_Templates' ) ) :
16
+
17
+ class WCJ_PDF_Invoicing_Templates {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // Settings hooks
24
+ add_filter( 'wcj_settings_sections', array( $this, 'settings_section' ) );
25
+ add_filter( 'wcj_settings_pdf_invoicing_templates', array( $this, 'get_settings' ), 100 );
26
+ }
27
+
28
+ /**
29
+ * get_settings.
30
+ */
31
+ function get_settings() {
32
+
33
+ $settings = array();
34
+ $invoice_types = wcj_get_invoice_types();
35
+ foreach ( $invoice_types as $invoice_type ) {
36
+
37
+ ob_start();
38
+ include( 'defaults/wcj-content-template-' . $invoice_type['id'] . '.php' );
39
+ $default_template = ob_get_clean();
40
+
41
+ $settings[] = array( 'title' => strtoupper( $invoice_type['desc'] ), 'type' => 'title', 'desc' => '', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options' );
42
+ $settings[] = array(
43
+ 'title' => __( 'HTML Template', 'woocommerce-jetpack' ),
44
+ //'title' => $invoice_type['title'],
45
+ 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_template',
46
+ 'default' => $default_template,
47
+ 'type' => 'textarea',
48
+ 'css' => 'width:66%;min-width:300px;height:500px;',
49
+ );
50
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_' . $invoice_type['id'] . '_templates_options' );
51
+ }
52
+
53
+ $settings[] = array( 'title' => __( 'Available Shortcodes', 'woocommerce-jetpack' ), 'type' => 'title', 'desc' => wcj_get_shortcodes_list(), 'id' => 'wcj_invoicing_templates_desc' );
54
+ $settings[] = array( 'type' => 'sectionend', 'id' => 'wcj_invoicing_templates_desc' );
55
+
56
+ ;
57
+
58
+ return $settings;
59
+ }
60
+
61
+ /**
62
+ * settings_section.
63
+ */
64
+ function settings_section( $sections ) {
65
+ $sections['pdf_invoicing_templates'] = __( 'Templates', 'woocommerce-jetpack' );
66
+ return $sections;
67
+ }
68
+ }
69
+
70
+ endif;
71
+
72
+ return new WCJ_PDF_Invoicing_Templates();
includes/pdf-invoices/settings/defaults/wcj-content-template-invoice.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1>Invoice</h1>
2
+ <p>
3
+ <table class="pdf_invoice_heading_table">
4
+ <tbody>
5
+ <tr><th>Invoice Nr.</th><td>[wcj_invoice_number]</td></tr>
6
+ <tr><th>Invoice Date</th><td>[wcj_invoice_date]</td></tr>
7
+ <tr><th>Order Nr.</th><td>[wcj_order_number]</td></tr>
8
+ </tbody>
9
+ </table>
10
+ </p>
11
+ <p>
12
+ <table class="pdf_invoice_seller_buyer_table">
13
+ <tbody>
14
+ <tr><th>Seller</th><th>Buyer</th></tr>
15
+ <tr><td>COMPANY NAME<br>COMPANY ADDRESS 1<br>COMPANY ADDRESS 2<br></td><td>[wcj_order_billing_address]</td></tr>
16
+ </tbody>
17
+ </table>
18
+ </p>
19
+ <p>
20
+ [wcj_order_items_table table_class="pdf_invoice_items_table"
21
+ columns="item_number|item_name|item_quantity|line_total_tax_excl"
22
+ columns_titles="|Product|Qty|Total"
23
+ columns_styles="width:5%;|width:75%;|width:5%;|width:15%;text-align:right;"]
24
+ <table class="pdf_invoice_totals_table">
25
+ <tbody>
26
+ <tr><th>Total (excl. TAX)</th><td>[wcj_order_total_excl_tax]</td></tr>
27
+ <tr><th>Taxes</th><td>[wcj_order_total_tax hide_if_zero="no"]</td></tr>
28
+ <tr><th>Order Total</th><td>[wcj_order_total]</td></tr>
29
+ </tbody>
30
+ </table>
31
+ </p>
32
+ <p>Payment method: [wcj_order_payment_method]</p>
includes/pdf-invoices/settings/defaults/wcj-content-template-packing_slip.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1>Packing Slip</h1>
2
+ <p>
3
+ <table class="pdf_invoice_heading_table">
4
+ <tbody>
5
+ <tr><th>Shipping method</th><td>[wcj_order_shipping_method]</td></tr>
6
+ <tr><th>Proforma Invoice Nr.</th><td>[wcj_proforma_invoice_number]</td></tr>
7
+ <tr><th>Invoice Nr.</th><td>[wcj_invoice_number]</td></tr>
8
+ <tr><th>Order Nr.</th><td>[wcj_order_number]</td></tr>
9
+ <tr><th>Order Date</th><td>[wcj_order_date]</td></tr>
10
+ </tbody>
11
+ </table>
12
+ </p>
13
+ <h2>Shipping address</h2>
14
+ <p>
15
+ <table>
16
+ <tbody>
17
+ <tr><td>[wcj_order_shipping_address]</td></tr>
18
+ </tbody>
19
+ </table>
20
+ </p>
21
+ <h2>Items</h2>
22
+ <p>
23
+ [wcj_order_items_table table_class="pdf_invoice_items_table"
24
+ columns="item_number|item_name|item_quantity"
25
+ columns_titles="|Item|Qty"
26
+ columns_styles="width:5%;|width:80%;|width:15%;text-align:right;"]
27
+ </p>
includes/pdf-invoices/settings/defaults/wcj-content-template-proforma_invoice.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1>Proforma Invoice</h1>
2
+ <p>
3
+ <table class="pdf_invoice_heading_table">
4
+ <tbody>
5
+ <tr><th>Proforma Invoice Nr.</th><td>[wcj_proforma_invoice_number]</td></tr>
6
+ <tr><th>Proforma Invoice Date</th><td>[wcj_proforma_invoice_date]</td></tr>
7
+ <tr><th>Order Nr.</th><td>[wcj_order_number]</td></tr>
8
+ </tbody>
9
+ </table>
10
+ </p>
11
+ <p>
12
+ <table class="pdf_invoice_seller_buyer_table">
13
+ <tbody>
14
+ <tr><th>Seller</th><th>Buyer</th></tr>
15
+ <tr><td>COMPANY NAME<br>COMPANY ADDRESS 1<br>COMPANY ADDRESS 2<br></td><td>[wcj_order_billing_address]</td></tr>
16
+ </tbody>
17
+ </table>
18
+ </p>
19
+ <p>
20
+ [wcj_order_items_table table_class="pdf_invoice_items_table"
21
+ columns="item_number|item_name|item_quantity|line_total_tax_excl"
22
+ columns_titles="|Product|Qty|Total"
23
+ columns_styles="width:5%;|width:75%;|width:5%;|width:15%;text-align:right;"
24
+ discount_as_item="Discount"]
25
+ <table class="pdf_invoice_totals_table">
26
+ <tbody>
27
+ <tr><th>Total (excl. TAX)</th><td>[wcj_order_total_excl_tax]</td></tr>
28
+ <tr><th>Taxes</th><td>[wcj_order_total_tax hide_if_zero="no"]</td></tr>
29
+ <tr><th>Order Total</th><td>[wcj_order_total]</td></tr>
30
+ </tbody>
31
+ </table>
32
+ </p>
includes/pdf-invoices/settings/defaults/wcj-invoice.css ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .pdf_invoice_heading_table {
2
+ width: 50%;
3
+ }
4
+
5
+ .pdf_invoice_seller_buyer_table th {
6
+ font-weight: bold;
7
+ }
8
+ /* pdf_invoice_items_table */
9
+ .pdf_invoice_items_table {
10
+ padding: 5px;
11
+ }
12
+ .pdf_invoice_items_table th {
13
+ font-weight: bold;
14
+ border: 1px solid #F0F0F0;
15
+ }
16
+ .pdf_invoice_items_table td {
17
+ border: 1px solid #F0F0F0;
18
+ }
19
+ /* pdf_invoice_totals_table */
20
+ .pdf_invoice_totals_table {
21
+ padding: 5px;
22
+ }
23
+ .pdf_invoice_totals_table th {
24
+ width: 85%;
25
+ text-align: right;
26
+ }
27
+ .pdf_invoice_totals_table td {
28
+ width: 15%;
29
+ text-align: right;
30
+ border: 1px solid #F0F0F0;
31
+ }
includes/pdf-invoices/settings/defaults/wcj-packing_slip.css ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .pdf_invoice_heading_table {
2
+ width: 50%;
3
+ }
4
+ .pdf_invoice_items_table {
5
+ padding: 5px;
6
+ }
7
+ .pdf_invoice_items_table th {
8
+ font-weight: bold;
9
+ border: 1px solid #F0F0F0;
10
+ }
11
+ .pdf_invoice_items_table td {
12
+ border: 1px solid #F0F0F0;
13
+ }
includes/pdf-invoices/settings/defaults/wcj-proforma_invoice.css ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .pdf_invoice_heading_table {
2
+ width: 50%;
3
+ }
4
+
5
+ .pdf_invoice_seller_buyer_table th {
6
+ font-weight: bold;
7
+ }
8
+ /* pdf_invoice_items_table */
9
+ .pdf_invoice_items_table {
10
+ padding: 5px;
11
+ }
12
+ .pdf_invoice_items_table th {
13
+ font-weight: bold;
14
+ border: 1px solid #F0F0F0;
15
+ }
16
+ .pdf_invoice_items_table td {
17
+ border: 1px solid #F0F0F0;
18
+ }
19
+ /* pdf_invoice_totals_table */
20
+ .pdf_invoice_totals_table {
21
+ padding: 5px;
22
+ }
23
+ .pdf_invoice_totals_table th {
24
+ width: 85%;
25
+ text-align: right;
26
+ }
27
+ .pdf_invoice_totals_table td {
28
+ width: 15%;
29
+ text-align: right;
30
+ border: 1px solid #F0F0F0;
31
+ }
includes/price-by-country/class-wcj-country-by-ip.php ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Country by IP
4
+ *
5
+ * The WooCommerce Jetpack Country by IP class.
6
+ *
7
+ * @class WCJ_Country_By_IP
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Country_By_IP' ) ) :
16
+
17
+ class WCJ_Country_By_IP {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ // Debug
25
+ add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'add_debug_info' ), PHP_INT_MAX, 0 );
26
+ add_action( 'admin_init', array( $this, 'reinstall_ip_db' ), PHP_INT_MAX, 0 );
27
+
28
+ add_action( 'init', array( $this, 'init_hooks' ) );
29
+
30
+ $this->current_db_file_version = 6;
31
+ $this->customer_country = null;
32
+ }
33
+
34
+
35
+ /**
36
+ * reinstall_ip_db.
37
+ */
38
+ function reinstall_ip_db() {
39
+ //global $current_db_file_version;
40
+ if ( isset( $_GET['wcj-install-ip-db'] ) && '1' == $_GET['wcj-install-ip-db'] ) {
41
+ $this->update_database( $this->current_db_file_version );
42
+ }
43
+ }
44
+
45
+ /**
46
+ * add_debug_info.
47
+ */
48
+ function add_debug_info() {
49
+ if ( isset( $_GET['wcj-debug'] ) ) {
50
+ //global $current_db_file_version;
51
+ echo '<input type="hidden" name="wcj-get-ip" value="' . wcj_get_the_ip() . '" />';
52
+ echo '<input type="hidden" name="wcj-get-country" value="' . $this->get_user_country_by_ip_internal() . '" />';
53
+ echo '<input type="hidden" name="wcj-get-country-external" value="' . $this->get_user_country_by_ip_external() . '" />';
54
+ echo '<input type="hidden" name="wcj-get-country-db-cur-ver" value="' . $this->current_db_file_version . '" />';
55
+ echo '<input type="hidden" name="wcj-get-country-db-ver" value="' . get_option( 'wcj_geoipcountry_db_version', 0 ) . '" />';
56
+ }
57
+ }
58
+
59
+ /**
60
+ * init_hooks.
61
+ */
62
+ function init_hooks() {
63
+ add_filter( 'wcj_get_ip_db_status_html', array( $this, 'get_ip_db_status_html' ) );
64
+ }
65
+
66
+ /**
67
+ * get_ip_db_status_html.
68
+ */
69
+ function get_ip_db_status_html() {
70
+
71
+ $installed_db_version = get_option( 'wcj_geoipcountry_db_version', 0 );
72
+
73
+ if ( WCJ()->country_by_ip->current_db_file_version != $installed_db_version ) {
74
+ if ( $installed_db_version < 0 )
75
+ $installed_db_version = abs( $installed_db_version ) + 10000;
76
+ return __( 'IP DB not installed', 'woocommerce-jetpack' ) . ' (' . $installed_db_version . ').'
77
+ . ' ' . '<a href="' . add_query_arg( 'wcj-install-ip-db', '1' ) . '">' . __( 'Fix', 'woocommerce-jetpack' ) . '</a>';
78
+ }
79
+ else
80
+ return __( 'IP DB version: ', 'woocommerce-jetpack' ) . WCJ()->country_by_ip->current_db_file_version;
81
+ }
82
+
83
+ /**
84
+ * convert_ip_to_int.
85
+ */
86
+ function convert_ip_to_int( $ip ) {
87
+ // Convert IP to int
88
+ $calc = array( 16777216, 65536, 256, 1 );
89
+ $i = 0;
90
+ $result = 0;
91
+ $token = strtok( $ip , '.' );
92
+ while ( $token !== false ) {
93
+ $result += $calc[ $i++ ] * $token;
94
+ $token = strtok( '.' );
95
+ }
96
+ return $result;
97
+ }
98
+
99
+ /**
100
+ * parse_csv_line.
101
+ */
102
+ function parse_csv_line( $line ) {
103
+ return explode( ',', trim( $line ) );
104
+ }
105
+
106
+ /**
107
+ * check_and_update_database.
108
+ */
109
+ function update_database( $current_db_file_version ) {
110
+ // Get IPs from file
111
+ // This product includes GeoLite data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
112
+
113
+ // Started
114
+ update_option( 'wcj_geoipcountry_db_version', -1 );
115
+
116
+ global $wpdb;
117
+
118
+ $charset_collate = $wpdb->get_charset_collate();
119
+ $table_name = $wpdb->prefix . 'woojetpack_country_ip';
120
+
121
+ $wpdb->query( "DROP TABLE $table_name;" );
122
+
123
+ $sql = "CREATE TABLE $table_name (
124
+ ip_from BIGINT NOT NULL,
125
+ ip_to BIGINT NOT NULL,
126
+ country_code VARCHAR(2) NOT NULL,
127
+ UNIQUE KEY ip_from (ip_from)
128
+ ) $charset_collate;";
129
+ $wpdb->query( $sql );
130
+
131
+ $the_values = '';
132
+ $max_insert_size = 10000;
133
+ $the_offset = 0;
134
+ $the_predifined_size = 104402;
135
+
136
+ //$the_array = file( plugin_dir_path( __FILE__ ) . 'lib/ipdb.csv' );
137
+ $the_array = file( WCJ()->plugin_path() . '/includes/lib/ipdb.csv' );
138
+
139
+ // Adding data to table
140
+ while ( $the_offset < $the_predifined_size ) {
141
+ $the_array_slice = array_slice( $the_array, $the_offset, $max_insert_size, true );
142
+ $csv = array_map( array( $this, 'parse_csv_line' ), $the_array_slice );
143
+ if ( ! empty ( $csv ) ) {
144
+ foreach ( $csv as $key => $data ) {
145
+ $the_values .= "('$data[0]', '$data[1]', '$data[2]'), ";
146
+ //$the_values .= "('" . implode( "', '", $data ) . "'), ";
147
+ }
148
+ $the_values = rtrim( $the_values, ', ' );
149
+ $wpdb->query( "INSERT INTO $table_name (`ip_from`, `ip_to`, `country_code`) VALUES $the_values;" );
150
+ $the_values = '';
151
+ }
152
+ $the_offset += $max_insert_size;
153
+ }
154
+
155
+ // Checking if OK
156
+ $count_db_table = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name;" );
157
+ if ( $the_predifined_size != $count_db_table ) {
158
+ // Something went wrong
159
+ update_option( 'wcj_geoipcountry_db_version', -2 );
160
+ }
161
+ else {
162
+ // Finished
163
+ update_option( 'wcj_geoipcountry_db_version', $current_db_file_version );
164
+ }
165
+
166
+ // Depreciated - cleaning
167
+ update_option( 'wcj_geoipcountry_db_from', array() );
168
+ update_option( 'wcj_geoipcountry_db_to', array() );
169
+ update_option( 'wcj_geoipcountry_db_country', array() );
170
+ }
171
+
172
+ /**
173
+ * get_country_by_ip_mysql.
174
+ */
175
+ function get_country_by_ip_mysql( $ip ) {
176
+ global $wpdb;
177
+ $results = $wpdb->get_results( "SELECT `country_code` FROM `{$wpdb->prefix}woojetpack_country_ip` WHERE `ip_from` <= $ip AND `ip_to` >= $ip", OBJECT );
178
+ if ( 1 !== count( $results ) || ! isset( $results[0]->country_code ) ) {
179
+ return get_option( 'woocommerce_default_country', 'GB' );
180
+ //return null;
181
+ }
182
+ return $results[0]->country_code;
183
+ }
184
+
185
+ /**
186
+ * check_and_update_database.
187
+ */
188
+ function check_and_update_database() {
189
+ //global $current_db_file_version;
190
+ $current_version = get_option( 'wcj_geoipcountry_db_version', 0 );
191
+ if ( $current_version < 0 )
192
+ return;
193
+ if ( $current_version != $this->current_db_file_version ) {
194
+ $this->update_database( $this->current_db_file_version );
195
+ }
196
+ }
197
+
198
+ /**
199
+ * get_user_country_by_ip.
200
+ */
201
+ function get_user_country_by_ip( $method ) {
202
+
203
+ //return 'LT';
204
+ // We already know the country - nothing to calculate - return country
205
+ // if ( null != $this->customer_country )
206
+ // return $this->customer_country;
207
+
208
+ // Debug
209
+ //if ( is_super_admin() && isset( $_GET['wcj-debug-country'] ) && '' != isset( $_GET['wcj-debug-country'] ) )
210
+
211
+
212
+
213
+ //if ( is_super_admin() && isset( $_GET['wcj-debug-country'] ) && '' != $_GET['wcj-debug-country'] ) {
214
+ if ( isset( $_GET['country'] ) && '' != $_GET['country'] && is_super_admin() ) {
215
+
216
+ //wcj_log( 'wcj-debug-country' );
217
+ return $_GET['country'];
218
+
219
+ }
220
+
221
+ // WooCommerce's geolocate_ip()
222
+ if ( 'internal_wc' === $method ) {
223
+ // WooCommerce's geolocate_ip()
224
+ /**/
225
+ //include_once( 'includes/class-wc-geolocation.php' );
226
+ $location = WC_Geolocation::geolocate_ip();
227
+ // Base fallback
228
+ if ( empty( $location['country'] ) ) {
229
+ $location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', get_option( 'woocommerce_default_country' ) ) );
230
+ }
231
+ //wcj_log( $location );
232
+ return ( isset( $location['country'] ) ) ? $location['country'] : null;
233
+ /**/
234
+ //wcj_log( $location['country'] );
235
+ //return wc_get_customer_default_location();
236
+ }
237
+
238
+ // External method
239
+ if ( 'external' === $method ) {
240
+ return $this->get_user_country_by_ip_external();
241
+ }
242
+
243
+ // Default - internal method
244
+ return $this->get_user_country_by_ip_internal();
245
+ }
246
+
247
+ /**
248
+ * get_user_country_by_ip_internal.
249
+ */
250
+ private function get_user_country_by_ip_internal() {
251
+
252
+
253
+
254
+ // Default value
255
+ //$this->customer_country = WC()->countries->get_base_country();
256
+
257
+ // Get user IP
258
+ $customer_ip = wcj_get_the_ip();
259
+
260
+ // Convert IP to int
261
+ $ip_as_int = $this->convert_ip_to_int( $customer_ip );
262
+
263
+ // Update DB if needed
264
+ $this->check_and_update_database();
265
+
266
+ // Search for IP in DB
267
+ return $this->get_country_by_ip_mysql( $ip_as_int );
268
+ }
269
+
270
+ /**
271
+ * get_user_country_by_ip_external.
272
+ */
273
+ private function get_user_country_by_ip_external() {
274
+
275
+ ob_start();
276
+ $max_execution_time = ini_get( 'max_execution_time' );
277
+ set_time_limit( 2 );
278
+
279
+ $country = file_get_contents( 'http://api.hostip.info/country.php?ip=' . wcj_get_the_ip() );
280
+ //$json = file_get_contents( 'http://api.hostip.info/country.php?ip=' . $this->get_the_ip() );//file_get_contents( 'http://ipinfo.io/' . $this->get_the_ip() . '/country' );
281
+ //$country = json_decode( $json );
282
+
283
+ set_time_limit( $max_execution_time );
284
+ ob_end_clean();
285
+
286
+ return ( '' != $country ) ? $country : null;
287
+ }
288
+ }
289
+
290
+ endif;
291
+
292
+ return new WCJ_Country_By_IP();
includes/price-by-country/class-wcj-exchange-rates-crons.php ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Exchange Rates Crons
4
+ *
5
+ * The WooCommerce Jetpack Exchange Rates Crons class.
6
+ *
7
+ * @class WCJ_Exchange_Rates_Crons
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Exchange_Rates_Crons' ) ) :
16
+
17
+ class WCJ_Exchange_Rates_Crons {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ add_action( 'wp', array( $this, 'schedule_the_events' ) );
24
+ $this->update_intervals = array(
25
+ 'manual' => __( 'Enter Rates Manually', 'woocommerce-jetpack' ),
26
+ 'hourly' => __( 'Automatically: Update Hourly', 'woocommerce-jetpack' ),
27
+ 'twicedaily' => __( 'Automatically: Update Twice Daily', 'woocommerce-jetpack' ),
28
+ 'daily' => __( 'Automatically: Update Daily', 'woocommerce-jetpack' ),
29
+ 'weekly' => __( 'Automatically: Update Weekly', 'woocommerce-jetpack' ),
30
+ 'minutely' => __( 'Automatically: Update Every Minute', 'woocommerce-jetpack' ),
31
+ );
32
+ /*foreach ( $this->update_intervals as $interval => $desc ) {
33
+ if ( 'manual' === $interval )
34
+ continue;
35
+ add_action( 'auto_update_exchange_rates_hook_' . $interval,
36
+ array( $this, 'update_the_exchange_rates' ) );
37
+ }*/
38
+ $selected_interval = get_option( 'wcj_price_by_country_auto_exchange_rates', 'manual' );
39
+ if ( 'manual' != $selected_interval ) {
40
+ //add_action( 'auto_update_exchange_rates_hook_' . $selected_interval,
41
+ add_action( 'auto_update_exchange_rates_hook',
42
+ array( $this, 'update_the_exchange_rates' ) );
43
+ }
44
+ add_filter( 'cron_schedules', array( $this, 'cron_add_custom_intervals' ) );
45
+ }
46
+
47
+
48
+ /**
49
+ * On an early action hook, check if the hook is scheduled - if not, schedule it.
50
+ */
51
+ function schedule_the_events() {
52
+
53
+ $selected_interval = apply_filters( 'wcj_get_option_filter', 'manual', get_option( 'wcj_price_by_country_auto_exchange_rates', 'manual' ) );
54
+ foreach ( $this->update_intervals as $interval => $desc ) {
55
+ if ( 'manual' === $interval )
56
+ continue;
57
+ $event_hook = 'auto_update_exchange_rates_hook';//_' . $interval;
58
+ $event_timestamp = wp_next_scheduled( $event_hook, array( $interval ) );
59
+ if ( ! $event_timestamp && $selected_interval === $interval ) {
60
+ wp_schedule_event( time(), $selected_interval, $event_hook, array( $selected_interval ) );
61
+ } elseif ( $event_timestamp && $selected_interval !== $interval ) {
62
+ wp_unschedule_event( $event_timestamp, $event_hook, array( $interval ) );
63
+ }
64
+ }
65
+
66
+ ////wcj_log( _get_cron_array() );
67
+ //wcj_log( get_option( 'cron' ) );
68
+ }
69
+
70
+ /*
71
+ * Functions gets currency exchange rate from rate-exchange.appspot.com server.
72
+ * returns rate on success, else 0
73
+ */
74
+ function get_exchange_rate( $currency_from, $currency_to ) {
75
+
76
+
77
+
78
+ $url = "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D" . $currency_from . $currency_to . "%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json";
79
+ //$url = 'http://rate-exchange.appspot.com/currency?from=' . $currency_from . '&to=' . $currency_to;
80
+
81
+ ob_start();
82
+ $max_execution_time = ini_get( 'max_execution_time' );
83
+ set_time_limit( 2 );
84
+
85
+ $exchange_rate = json_decode( file_get_contents( $url ) );
86
+
87
+ set_time_limit( $max_execution_time );
88
+ ob_end_clean();
89
+
90
+ return ( isset( $exchange_rate->query->results->row->rate ) ) ? floatval( $exchange_rate->query->results->row->rate ) : 0;
91
+ //return ( isset( $exchange_rate->rate ) ) ? $exchange_rate->rate : 0;
92
+ }
93
+
94
+ /**
95
+ * On the scheduled action hook, run a function.
96
+ */
97
+ function update_the_exchange_rates( $interval ) {
98
+
99
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
100
+ $currency_from = get_option( 'woocommerce_currency' );
101
+ $currency_to = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i );
102
+ $the_rate = $this->get_exchange_rate( $currency_from, $currency_to );
103
+ if ( 0 != $the_rate ) {
104
+ if ( $currency_from != $currency_to ) {
105
+ update_option( 'wcj_price_by_country_exchange_rate_group_' . $i, $the_rate );
106
+ $result_message = __( 'Cron job: exchange rates successfully updated', 'woocommerce-jetpack' );
107
+ } else {
108
+ $result_message = __( 'Cron job: exchange rates not updated, as currency_from == currency_to', 'woocommerce-jetpack' );
109
+ }
110
+ } else {
111
+ $result_message = __( 'Cron job: exchange rates update failed', 'woocommerce-jetpack' );
112
+ }
113
+ wcj_log( $result_message . ': ' . $currency_from . $currency_to . ': ' . $the_rate . ': ' . 'update_the_exchange_rates: ' . $interval );
114
+ }
115
+ }
116
+
117
+ /**
118
+ * cron_add_custom_intervals.
119
+ */
120
+ function cron_add_custom_intervals( $schedules ) {
121
+
122
+ $schedules['weekly'] = array(
123
+ 'interval' => 604800,
124
+ 'display' => __( 'Once Weekly', 'woocommerce-jetpack' )
125
+ );
126
+
127
+ $schedules['minutely'] = array(
128
+ 'interval' => 60,
129
+ 'display' => __( 'Once a Minute', 'woocommerce-jetpack' )
130
+ );
131
+
132
+ return $schedules;
133
+ }
134
+ }
135
+
136
+ endif;
137
+
138
+ return new WCJ_Exchange_Rates_Crons();
includes/price-by-country/class-wcj-exchange-rates.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Exchange Rates
4
+ *
5
+ * The WooCommerce Jetpack Exchange Rates class.
6
+ *
7
+ * @class WCJ_Exchange_Rates
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Exchange_Rates' ) ) :
16
+
17
+ class WCJ_Exchange_Rates {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ add_action( 'admin_enqueue_scripts' , array( $this, 'enqueue_exchange_rates_script' ) );
25
+ add_action( 'admin_init', array( $this, 'register_script' ) );
26
+
27
+ add_action( 'woocommerce_admin_field_button', array( $this, 'output_settings_button' ) );
28
+ }
29
+
30
+ /**
31
+ * register_script.
32
+ */
33
+ public function register_script() {
34
+ if( isset( $_GET['section'] ) && 'price_by_country' === $_GET['section'] ) {
35
+ wp_register_script( 'wcj-exchange-rates', trailingslashit( WCJ()->plugin_url() ) . 'includes/js/exchange_rates.js', array( 'jquery' ), false, true );
36
+ }
37
+ }
38
+
39
+ /**
40
+ * enqueue_exchange_rates_script.
41
+ */
42
+ public function enqueue_exchange_rates_script() {
43
+ if( isset( $_GET['section'] ) && 'price_by_country' === $_GET['section'] ) {
44
+ wp_enqueue_script( 'wcj-exchange-rates' );
45
+ }
46
+ }
47
+
48
+ /**
49
+ * output_settings_button.
50
+ */
51
+ function output_settings_button( $value ) {
52
+
53
+ // Custom attribute handling
54
+ $custom_attributes = array();
55
+ if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
56
+ foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
57
+ $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
58
+ }
59
+ }
60
+ $tip = '';
61
+ ?>
62
+ <tr valign="top">
63
+ <th scope="row" class="titledesc">
64
+ <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
65
+ <?php echo $tip; ?>
66
+ </th>
67
+ <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
68
+ <input
69
+ name="<?php echo esc_attr( $value['id'] ); ?>"
70
+ id="<?php echo esc_attr( $value['id'] ); ?>"
71
+ type="<?php echo esc_attr( $value['type'] ); ?>"
72
+ style="<?php echo esc_attr( $value['css'] ); ?>"
73
+ value="<?php echo esc_attr( $value['value'] ); ?>"
74
+ class="<?php echo esc_attr( $value['class'] ); ?>"
75
+ <?php echo implode( ' ', $custom_attributes ); ?>
76
+ />
77
+ </td>
78
+ </tr>
79
+ <?php
80
+ }
81
+
82
+ }
83
+
84
+ endif;
85
+
86
+ return new WCJ_Exchange_Rates();
includes/price-by-country/class-wcj-price-by-country-core.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Price by Country Core
4
+ *
5
+ * The WooCommerce Jetpack Price by Country Core class.
6
+ *
7
+ * @class WCJ_Price_by_Country_Core
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Price_by_Country_Core' ) ) :
16
+
17
+ class WCJ_Price_by_Country_Core {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->country_by_ip = include_once( 'class-wcj-country-by-ip.php' );
25
+ $this->customer_country_group_id = null;
26
+
27
+ add_action( 'woocommerce_loaded', array( $this, 'add_hooks' ) );
28
+ }
29
+
30
+ /**
31
+ * add_hooks.
32
+ */
33
+ function add_hooks() {
34
+ // Price hooks
35
+
36
+ add_filter( 'woocommerce_get_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX, 2 );
37
+ add_filter( 'woocommerce_get_sale_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX, 2 );
38
+ add_filter( 'woocommerce_get_regular_price', array( $this, 'change_price_by_country' ), PHP_INT_MAX, 2 );
39
+ // add_filter( 'booking_form_calculated_booking_cost', array( $this, 'change_price_by_country' ), PHP_INT_MAX );
40
+ add_filter( 'woocommerce_get_price_html', array( $this, 'fix_variable_product_price_on_sale' ), 10 , 2 );
41
+
42
+ // Currency hooks
43
+ add_filter( 'woocommerce_currency_symbol', array( $this, 'change_currency_symbol' ), PHP_INT_MAX, 2 );
44
+ add_filter( 'woocommerce_currency', array( $this, 'change_currency_code' ), PHP_INT_MAX, 1 );
45
+
46
+ add_shortcode( 'wcj_debug_price_by_country', array( $this, 'get_debug_info' ) );
47
+ }
48
+
49
+ /**
50
+ * get_debug_info.
51
+ */
52
+ function get_debug_info( $args ) {
53
+ $html = '';
54
+ /*$html .= '<p>';
55
+ $html .= __( 'internal: ', 'woocommerce-jetpack' ) . WCJ()->country_by_ip->get_user_country_by_ip( 'internal' );
56
+ $html .= '</p>';
57
+ $html .= '<p>';
58
+ $html .= __( 'external: ', 'woocommerce-jetpack' ) . WCJ()->country_by_ip->get_user_country_by_ip( 'external' );
59
+ $html .= '</p>';*/
60
+ if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled' ) ) {
61
+ $html .= '<p>';
62
+ $html .= __( 'Price by Country on per Product Basis is enabled.', 'woocommerce-jetpack' );
63
+ $html .= '</p>';
64
+ }
65
+
66
+ $data = array();
67
+ $data[] = array( '#', __( 'Countries', 'woocommerce-jetpack' ), __( 'Focus Country', 'woocommerce-jetpack' ), __( 'Regular Price', 'woocommerce-jetpack' ), __( 'Sale Price', 'woocommerce-jetpack' ) );
68
+ global $product;
69
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
70
+
71
+ $row = array();
72
+
73
+ $row[] = $i;
74
+
75
+ $country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
76
+ $country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
77
+ $row[] = $country_exchange_rate_group;
78
+
79
+ $country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
80
+ $_GET['country'] = $country_exchange_rate_group[0];
81
+ $row[] = $country_exchange_rate_group[0];
82
+ $currency_code = wcj_get_currency_symbol( get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i ) );
83
+ $row[] = $product->get_regular_price() . ' ' . $currency_code;
84
+ $row[] = $product->get_sale_price() . ' ' . $currency_code;
85
+
86
+ $data[] = $row;
87
+ }
88
+ //$html .= wcj_get_table_html( $data, '', false );
89
+ $html = wcj_get_table_html( $data, array( 'table_heading_type' => 'vertical', ) );
90
+ return $html;
91
+ }
92
+
93
+ /**
94
+ * fix_variable_product_price_on_sale.
95
+ */
96
+ public function fix_variable_product_price_on_sale( $price, $product ) {
97
+ if ( $product->is_type( 'variable' ) ) {
98
+ if ( ! $product->is_on_sale() ) {
99
+ $start_position = strpos( $price, '<del>' );
100
+ $length = strpos( $price, '</del>' ) - $start_position;
101
+ // Fixing the price, i.e. removing the sale tags
102
+ return substr_replace( $price, '', $start_position, $length );
103
+ }
104
+ }
105
+ // No changes
106
+ return $price;
107
+ }
108
+
109
+ /**
110
+ * get_customer_country_group_id.
111
+ */
112
+ public function get_customer_country_group_id() {
113
+
114
+ // We already know the group - nothing to calculate - return group
115
+ // if ( null != $this->customer_country_group_id && $this->customer_country_group_id > 0 )
116
+ // return $this->customer_country_group_id;
117
+
118
+ // We've already tried - no country was detected, no need to try again
119
+ if ( -1 === $this->customer_country_group_id )
120
+ return null;
121
+
122
+ // Get the country by IP
123
+ //wcj_log( WCJ() );
124
+
125
+ //$does_exist = ( method_exists( WCJ()->country_by_ip, 'get_user_country_by_ip' ) ) ? 'true' : 'false';
126
+ //wcj_log ( WC() );
127
+
128
+ //if ( null == $this->country_by_ip ) $this->country_by_ip = include_once( 'class-wcj-country-by-ip.php' );
129
+
130
+
131
+ /**/
132
+ switch( get_option( 'wcj_price_by_country_by_ip_detection_type', 'internal' ) ) {
133
+ case 'internal':
134
+ $country = $this->country_by_ip->get_user_country_by_ip( 'internal' );
135
+ break;
136
+ case 'internal_wc':
137
+ $country = $this->country_by_ip->get_user_country_by_ip( 'internal_wc' );
138
+ break;
139
+ case 'hostip_info':
140
+ $country = $this->country_by_ip->get_user_country_by_ip( 'external' );
141
+ break;
142
+ }
143
+ /**/
144
+
145
+
146
+ if ( null === $country ) {
147
+ $this->customer_country_group_id = -1;
148
+ return null;
149
+ }
150
+
151
+
152
+ // Get the country group id - go through all the groups, first found group is returned
153
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
154
+ $country_exchange_rate_group = get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
155
+ $country_exchange_rate_group = str_replace( ' ', '', $country_exchange_rate_group );
156
+ $country_exchange_rate_group = explode( ',', $country_exchange_rate_group );
157
+ if ( in_array( $country, $country_exchange_rate_group ) ) {
158
+ $this->customer_country_group_id = $i;
159
+ //wcj_log( 'customer_country_group_id=' . $this->customer_country_group_id );
160
+ return $i;
161
+ }
162
+ }
163
+ // No country group found
164
+
165
+ $this->customer_country_group_id = -1;
166
+ return null;
167
+ }
168
+
169
+ /**
170
+ * change_currency_symbol.
171
+ */
172
+ public function change_currency_symbol( $currency_symbol, $currency ) {
173
+ if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
174
+ $country_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
175
+ //wcj_log( 'country_currency_code=' . $country_currency_code );
176
+ if ( '' != $country_currency_code )
177
+ return wcj_get_currency_symbol( $country_currency_code );
178
+ //return $this->currency_symbols[ $country_currency_code ];
179
+ }
180
+ return $currency_symbol;
181
+ }
182
+
183
+ /**
184
+ * change_currency_code.
185
+ */
186
+ public function change_currency_code( $currency ) {
187
+ if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
188
+ $country_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $group_id );
189
+ //wcj_log( 'country_currency_code=' . $country_currency_code );
190
+ if ( '' != $country_currency_code )
191
+ return $country_currency_code;
192
+ }
193
+ return $currency;
194
+ }
195
+
196
+ /**
197
+ * change_price_by_country.
198
+ */
199
+ public function change_price_by_country( $price, $product ) {
200
+
201
+ $the_product_id = ( isset( $product->variation_id ) ) ? $product->variation_id : $product->id;
202
+
203
+ if ( null != ( $group_id = $this->get_customer_country_group_id() ) ) {
204
+
205
+ $is_price_modified = false;
206
+
207
+ if ( 'yes' === get_option( 'wcj_price_by_country_local_enabled' ) ) {
208
+ // Per product
209
+ $meta_box_id = 'price_by_country';
210
+ $scope = 'local';
211
+
212
+ $meta_id = '_' . 'wcj_' . $meta_box_id . '_make_empty_price_' . $scope . '_' . $group_id;
213
+ if ( 'on' === get_post_meta( $the_product_id, $meta_id, true ) ) {
214
+ return '';
215
+ }
216
+
217
+ if ( 'woocommerce_get_price' == current_filter() ) {
218
+
219
+ $regular_or_sale = '_regular_price_';
220
+ $meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
221
+ $regular_price = get_post_meta( $the_product_id, $meta_id, true );
222
+
223
+ $regular_or_sale = '_sale_price_';
224
+ $meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
225
+ $sale_price = get_post_meta( $the_product_id, $meta_id, true );
226
+
227
+ if ( ! empty( $sale_price ) && $sale_price < $regular_price )
228
+ $price_by_country = $sale_price;
229
+ else
230
+ $price_by_country = $regular_price;
231
+
232
+ }
233
+ elseif ( 'woocommerce_get_regular_price' == current_filter() || 'woocommerce_get_sale_price' == current_filter() ) {
234
+ $regular_or_sale = ( 'woocommerce_get_regular_price' == current_filter() ) ? '_regular_price_' : '_sale_price_';
235
+ $meta_id = '_' . 'wcj_' . $meta_box_id . $regular_or_sale . $scope . '_' . $group_id;
236
+ $price_by_country = get_post_meta( $the_product_id, $meta_id, true );
237
+ }
238
+
239
+ if ( '' != $price_by_country ) {
240
+ $modified_price = $price_by_country;
241
+ $is_price_modified = true;
242
+ }
243
+ }
244
+
245
+ if ( ! $is_price_modified ) {
246
+ if ( 'yes' === get_option( 'wcj_price_by_country_make_empty_price_group_' . $group_id, 1 ) ) {
247
+ return '';
248
+ }
249
+ }
250
+
251
+ if ( ! $is_price_modified ) {
252
+ // Globally
253
+ $country_exchange_rate = get_option( 'wcj_price_by_country_exchange_rate_group_' . $group_id, 1 );
254
+ if ( 1 != $country_exchange_rate ) {
255
+ $modified_price = $price * $country_exchange_rate;
256
+ $is_price_modified = true;
257
+ }
258
+ }
259
+
260
+ if ( $is_price_modified ) {
261
+ $rounding = get_option( 'wcj_price_by_country_rounding', 'none' );
262
+ $precision = get_option( 'woocommerce_price_num_decimals', 2 );
263
+ switch ( $rounding ) {
264
+ case 'none':
265
+ //return ( $modified_price );
266
+ return round( $modified_price, $precision );
267
+ case 'round':
268
+ return round( $modified_price );
269
+ case 'floor':
270
+ return floor( $modified_price );
271
+ case 'ceil':
272
+ return ceil( $modified_price );
273
+ }
274
+ }
275
+ }
276
+ // No changes
277
+ return $price;
278
+ }
279
+ }
280
+
281
+ endif;
282
+
283
+ return new WCJ_Price_by_Country_Core();
includes/price-by-country/class-wcj-price-by-country-local.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Price by Country Local
4
+ *
5
+ * The WooCommerce Jetpack Price by Country Local class.
6
+ *
7
+ * @class WCJ_Price_by_Country_Local
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Price_by_Country_Local' ) ) :
16
+
17
+ class WCJ_Price_by_Country_Local {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+ // add_action( 'add_meta_boxes', array( $this, 'add_custom_meta_box_to_product_edit' ) );
24
+ add_action( 'save_post_product', array( $this, 'save_custom_meta_box_on_product_edit' ), PHP_INT_MAX, 2 );
25
+ add_action( 'woocommerce_product_options_pricing', array( $this, 'add_simple_pricing' ), PHP_INT_MAX, 0 );
26
+ add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'add_variable_pricing' ), PHP_INT_MAX, 3 );
27
+ //add_action( 'woocommerce_variation_options', array( $this, 'add_variable_pricing' ), PHP_INT_MAX, 3 );
28
+ add_action( 'woocommerce_product_options_general_product_data', array( $this, 'add_hidden_save' ), PHP_INT_MAX, 0 );
29
+ }
30
+
31
+ /**
32
+ * add_custom_meta_box_to_product_edit.
33
+ *
34
+ public function add_custom_meta_box_to_product_edit() {
35
+ add_meta_box(
36
+ 'wc-jetpack-' . 'price-by-country',
37
+ __( 'Price and Currency by Country', 'woocommerce-jetpack' ),
38
+ array( $this, 'create_custom_meta_box' ),
39
+ 'product',
40
+ 'normal',
41
+ 'high' );
42
+ }
43
+
44
+ /**
45
+ * add_simple_pricing.
46
+ */
47
+ function add_simple_pricing() {
48
+ $this->create_custom_meta_box( 'simple' );
49
+ }
50
+
51
+ /**
52
+ * add_variable_pricing.
53
+ */
54
+ function add_variable_pricing( $loop, $variation_data, $variation ) {
55
+ $this->create_custom_meta_box( 'variable', $variation->ID );
56
+ }
57
+
58
+ /**
59
+ * create_custom_meta_box.
60
+ */
61
+ //public function create_custom_meta_box() {
62
+ public function create_custom_meta_box( $simple_or_variable, $product_id = 0 ) {
63
+
64
+ $current_post_id = ( $product_id == 0) ? get_the_ID() : $product_id;
65
+ $the_product = wc_get_product( $current_post_id );
66
+ if ( ! $the_product )
67
+ return;
68
+
69
+
70
+ $total_country_groups_number = $this->get_total_country_groups_number();
71
+
72
+ // Start html
73
+ $html = '';
74
+
75
+ if ( $the_product->is_type( 'variation' ) ) {
76
+ $html .= $this->get_all_options_html( $simple_or_variable, $current_post_id, $total_country_groups_number, '_' . $current_post_id );
77
+ //wcj_log( $simple_or_variable . '|' . $current_post_id . '|' . $total_country_groups_number . '|' . '_' . $current_post_id );
78
+ //wcj_log( $current_post_id );
79
+ //$html = '</p>' . $html . '<p>';
80
+ }
81
+ /*
82
+ //if ( $the_product->is_type( 'variable' ) ) {
83
+ if ( true === false ) {
84
+ $variations = $the_product->get_available_variations();
85
+ if ( ! empty( $variations ) ) {
86
+ $variation_counter = 1;
87
+ foreach ( $variations as $variation ) {
88
+ $html .= $this->get_all_options_html( $simple_or_variable, $variation['variation_id'], $total_country_groups_number, '_' . $variation_counter );
89
+ $variation_counter++;
90
+ }
91
+ }
92
+ }
93
+ */
94
+ else {
95
+ $html .= $this->get_all_options_html( $simple_or_variable, $current_post_id, $total_country_groups_number );
96
+ }
97
+
98
+ // Output
99
+ echo $html;
100
+ }
101
+
102
+ /**
103
+ * add_hidden_save.
104
+ */
105
+ function add_hidden_save() {
106
+ $meta_box_id = 'price_by_country';
107
+ echo '<input type="hidden" name="woojetpack_' . $meta_box_id . '_save_post" value="woojetpack_' . $meta_box_id . '_save_post">';
108
+ }
109
+
110
+ /**
111
+ * get_total_country_groups_number.
112
+ */
113
+ function get_total_country_groups_number() {
114
+ return apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) );
115
+ }
116
+
117
+ /**
118
+ * get_prices_options.
119
+ */
120
+ public function get_prices_options() {
121
+
122
+ $meta_box_id = 'price_by_country';
123
+ $this->scope = 'local';
124
+
125
+ $options = array(
126
+
127
+ array(
128
+ 'id' => 'wcj_' . $meta_box_id . '_regular_price_' . $this->scope . '_',
129
+ 'title' => __( 'Regular Price', 'woocommerce' ),
130
+ 'type' => 'text',
131
+ 'default' => 0,
132
+ ),
133
+
134
+ array(
135
+ 'id' => 'wcj_' . $meta_box_id . '_sale_price_' . $this->scope . '_',
136
+ 'title' => __( 'Sale Price', 'woocommerce' ),
137
+ 'type' => 'text',
138
+ 'default' => 0,
139
+ ),
140
+
141
+ array(
142
+ 'id' => 'wcj_' . $meta_box_id . '_make_empty_price_' . $this->scope . '_',
143
+ 'title' => __( 'Make empty price', 'woocommerce' ),
144
+ 'type' => 'checkbox',
145
+ 'default' => 'off',
146
+ ),
147
+
148
+ );
149
+ return $options;
150
+ }
151
+
152
+ /**
153
+ * Save options.
154
+ */
155
+ function save_options( $post_id, $total_options_groups, $variation_id_addon = '' ) {
156
+
157
+ $options = $this->get_prices_options();
158
+ for ( $i = 1; $i <= $total_options_groups; $i++ ) {
159
+ foreach ( $options as $option ) {
160
+ if ( isset( $_POST[ $option['id'] . $i . $variation_id_addon ] ) ) {
161
+ update_post_meta( $post_id, '_' . $option['id'] . $i, $_POST[ $option['id'] . $i . $variation_id_addon ] );
162
+ }
163
+ elseif ( 'checkbox' === $option['type'] )
164
+ update_post_meta( $post_id, '_' . $option['id'] . $i, 'off' );
165
+ }
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Save Custom Meta Box on Product Edit.
171
+ */
172
+ public function save_custom_meta_box_on_product_edit( $post_id, $post ) {
173
+
174
+ $meta_box_id = 'price_by_country';
175
+
176
+ // Check that we are saving with custom meta box displayed.
177
+ if ( ! isset( $_POST[ 'woojetpack_' . $meta_box_id . '_save_post' ] ) )
178
+ return;
179
+
180
+ $the_product = wc_get_product( $post_id );
181
+ if ( ! $the_product )
182
+ return;
183
+
184
+ $total_options_groups = $this->get_total_country_groups_number();
185
+
186
+ if ( $the_product->is_type( 'variable' ) ) {
187
+ $variations = $the_product->get_available_variations();
188
+ if ( empty( $variations ) )
189
+ return;
190
+ //$variation_counter = 1;
191
+ foreach ( $variations as $variation ) {
192
+ //$this->save_options( $variation['variation_id'], $total_options_groups, '_' . $variation_counter );
193
+ //$variation_counter++;
194
+ $this->save_options( $variation['variation_id'], $total_options_groups, '_' . $variation['variation_id'] );
195
+ }
196
+ }
197
+ else {
198
+ $this->save_options( $post_id, $total_options_groups );
199
+ }
200
+ }
201
+
202
+ /**
203
+ * get_option_field_html.
204
+ */
205
+ function get_option_field_html( $current_post_id, $option_id, $option, $variation_id_addon = '' ) {
206
+ $html = '';
207
+ $option_value = get_post_meta( $current_post_id, '_' . $option_id, true );
208
+ $option_id .= $variation_id_addon;
209
+ /*if ( 'select' === $option['type'] ) {
210
+ $original_value = $option_value;
211
+ $option_value = '';
212
+ $currency_names_and_symbols = wcj_get_currencies_and_symbols();
213
+ foreach( $currency_names_and_symbols as $symbol => $name ) {
214
+ $option_value .= '<option value="' . $symbol . '" ' . selected( $original_value, $symbol, false ) . '>';
215
+ $option_value .= $name;
216
+ $option_value .= '</option>';
217
+ }
218
+ }*/
219
+ $html .= wcj_get_option_html( $option['type'], $option_id, $option_value, '', 'short' );
220
+ return $html;
221
+ }
222
+
223
+ /**
224
+ * get_all_options_html.
225
+ */
226
+ public function get_all_options_html( $simple_or_variable, $current_post_id, $total_number, $variation_id_addon = '' ) {
227
+ $html = '';
228
+ $options = $this->get_prices_options();
229
+ for ( $i = 1; $i <= $total_number; $i++ ) {
230
+
231
+ if ( 'variable' == $simple_or_variable ) {
232
+ $html .= '<div>';
233
+ }
234
+
235
+ //if ( 'simple' == $simple_or_variable ) {
236
+ $html .= '<p>';
237
+ $html .= '<strong>';
238
+ $html .= __( 'Country Group Nr.', 'woocommerce-jetpack' ) . ' ' . $i;
239
+ $html .= ': ';
240
+ $html .= get_option( 'wcj_price_by_country_exchange_rate_countries_group_' . $i );
241
+ $html .= '</strong>';
242
+ $html .= '</p>';
243
+ //}
244
+ //elseif ( 'variable' == $simple_or_variable ) {
245
+ // $html .= '<tr>';
246
+ //}
247
+
248
+ foreach ( $options as $option ) {
249
+
250
+ // $option_id = $option['id'] . $i . $variation_id_addon;
251
+ $option_id = $option['id'] . $i;
252
+
253
+ if ( 'simple' == $simple_or_variable ) {
254
+ $html .= '<p class="form-field ' . $option_id . $variation_id_addon . '_field">';
255
+ } else {
256
+ $column_position = 'full';
257
+ if ( 'checkbox' != $option['type'] ) {
258
+ $column_position = ( false !== strpos( $option['id'], '_regular_price_' ) ) ? 'first' : 'last';
259
+ }
260
+ $html .= '<p class="form-row form-row-' . $column_position . '">';
261
+ }
262
+ $group_currency_code = get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i );
263
+ $currency_code_html = ( 'checkbox' != $option['type'] ) ? ' (' . wcj_get_currency_symbol( $group_currency_code ) . ')' : '';
264
+ $html .= '<label for="' . $option_id . $variation_id_addon . '">' . $option['title'] . $currency_code_html . '</label>';
265
+ //}
266
+ //elseif ( 'variable' == $simple_or_variable ) {
267
+ // $html .= '<td>';
268
+ //}
269
+
270
+ $html .= $this->get_option_field_html( $current_post_id, $option_id, $option, $variation_id_addon );
271
+
272
+ //if ( 'simple' == $simple_or_variable ) {
273
+ $html .= '</p>';
274
+ //}
275
+ //elseif ( 'variable' == $simple_or_variable ) {
276
+ // $html .= '</td>';
277
+ //}
278
+ }
279
+
280
+ //if ( 'variable' == $simple_or_variable ) {
281
+ // $html .= '</tr>';
282
+ //}
283
+ if ( 'variable' == $simple_or_variable ) {
284
+ $html .= '</div>';
285
+ }
286
+ }
287
+ return $html;
288
+ }
289
+
290
+ }
291
+
292
+ endif;
293
+
294
+ return new WCJ_Price_by_Country_Local();
includes/price-by-country/class-wcj-price-by-country-reports.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Price By Country Reports
4
+ *
5
+ * The WooCommerce Jetpack Price By Country Reports class.
6
+ *
7
+ * @class WCJ_Price_By_Country_Reports
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Price_By_Country_Reports' ) ) :
16
+
17
+ class WCJ_Price_By_Country_Reports {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ function __construct() {
23
+
24
+ add_filter( 'woocommerce_reports_get_order_report_data_args', array( $this, 'filter_reports'), PHP_INT_MAX, 1 );
25
+ add_filter( 'woocommerce_currency_symbol', array( $this, 'change_currency_symbol_reports'), PHP_INT_MAX, 2 );
26
+ add_action( 'admin_bar_menu', array( $this, 'add_reports_currency_to_admin_bar' ), PHP_INT_MAX );
27
+ }
28
+
29
+ /**
30
+ * add_reports_currency_to_admin_bar.
31
+ */
32
+ function add_reports_currency_to_admin_bar( $wp_admin_bar ) {
33
+
34
+ if ( isset( $_GET['page'] ) && 'wc-reports' === $_GET['page'] ) {
35
+ $the_current_code = isset( $_GET['currency'] ) ? $_GET['currency'] : get_woocommerce_currency();
36
+ $parent = 'reports_currency_select';
37
+ $args = array(
38
+ 'parent' => false,
39
+ 'id' => $parent,
40
+ 'title' => __( 'Reports currency:', 'woocommerce-jetpack' ) . ' ' . $the_current_code,
41
+ 'href' => false,
42
+ 'meta' => array( 'title' => __( 'Show reports only in', 'woocommerce-jetpack' ) . ' ' . $the_current_code, ),
43
+ );
44
+
45
+ $wp_admin_bar->add_node( $args );
46
+
47
+ $currency_symbols = array();
48
+ $currency_symbols[ $the_current_code ] = '';
49
+ $currency_symbols[ get_woocommerce_currency() ] = '';
50
+ for ( $i = 1; $i <= apply_filters( 'wcj_get_option_filter', 1, get_option( 'wcj_price_by_country_total_groups_number', 1 ) ); $i++ ) {
51
+ $currency_symbols[ get_option( 'wcj_price_by_country_exchange_rate_currency_group_' . $i ) ] = '';
52
+ }
53
+ $this->reports_currency_symbols = $currency_symbols;
54
+
55
+ foreach ( $this->reports_currency_symbols as $code => $symbol ) {
56
+ //if ( $code === $the_current_code )
57
+ // continue;
58
+ $args = array(
59
+ 'parent' => $parent,
60
+ 'id' => $parent . '_' . $code,
61
+ 'title' => $code,// . ' ' . $symbol,
62
+ 'href' => add_query_arg( 'currency', $code),
63
+ 'meta' => array( 'title' => __( 'Show reports only in', 'woocommerce-jetpack' ) . ' ' . $code, ),
64
+ );
65
+
66
+ $wp_admin_bar->add_node( $args );
67
+ }
68
+ }
69
+ }
70
+
71
+ /**
72
+ * change_currency_symbol_reports.
73
+ */
74
+ function change_currency_symbol_reports( $currency_symbol, $currency ) {
75
+ if ( isset( $_GET['page'] ) && 'wc-reports' === $_GET['page'] ) {
76
+ if ( isset( $_GET['currency'] ) ) {
77
+ if ( isset( $this->currency_symbols[ strtoupper( $_GET['currency'] ) ] ) ) {
78
+ return $this->currency_symbols[ strtoupper( $_GET['currency'] ) ];
79
+ }
80
+ }
81
+ }
82
+ return $currency_symbol;
83
+ }
84
+
85
+ /**
86
+ * filter_reports.
87
+ */
88
+ function filter_reports( $args ) {
89
+ $args['where_meta'] = array(
90
+ array(
91
+ 'meta_key' => '_order_currency',
92
+ 'meta_value' => isset( $_GET['currency'] ) ? $_GET['currency'] : get_woocommerce_currency(),
93
+ 'operator' => '=',
94
+ ),
95
+ );
96
+ return $args;
97
+ }
98
+ }
99
+
100
+ endif;
101
+
102
+ return new WCJ_Price_By_Country_Reports();
103
+
104
+
105
+
106
+
includes/reports/wcj-class-reports-customers.php CHANGED
@@ -88,7 +88,7 @@ class WCJ_Reports_Customers {
88
  $html .= '<td>' . $country_code . '</td>';
89
  $html .= '<td>' . $counter . '</td>';
90
  $html .= ( 0 != $total_customers ) ? '<td>' . number_format( ( $counter / $total_customers ) * 100, 2 ) . '%' . '</td>' : '<td></td>';
91
- $html .= ( 2 == strlen( $country_code ) ) ? '<td>' . '<img src="' . plugins_url() . '/' . 'woocommerce-jetpack' . '/assets/images/flag-icons/' . strtolower( $country_code ) . '.png">' . '</td>' : '<td></td>';
92
  //$html .= ( 2 == strlen( $country_code ) ) ? '<td>' . '<img src="' . plugin_dir_url ( __FILE__ ) . 'assets/images/flag-icons/' . strtolower( $country_code ) . '.png' . '">' . '</td>' : '<td></td>';
93
  $html .= '</tr>';
94
  }
88
  $html .= '<td>' . $country_code . '</td>';
89
  $html .= '<td>' . $counter . '</td>';
90
  $html .= ( 0 != $total_customers ) ? '<td>' . number_format( ( $counter / $total_customers ) * 100, 2 ) . '%' . '</td>' : '<td></td>';
91
+ $html .= ( 2 == strlen( $country_code ) ) ? '<td>' . '<img src="' . plugins_url() . '/' . 'woocommerce-jetpack' . '/assets/images/flag-icons/' . strtolower( $country_code ) . '.png" title="' . wcj_get_country_name_by_code( $country_code ) . '">' . ' ' . wcj_get_country_name_by_code( $country_code ) . '</td>' : '<td></td>';
92
  //$html .= ( 2 == strlen( $country_code ) ) ? '<td>' . '<img src="' . plugin_dir_url ( __FILE__ ) . 'assets/images/flag-icons/' . strtolower( $country_code ) . '.png' . '">' . '</td>' : '<td></td>';
93
  $html .= '</tr>';
94
  }
includes/shortcodes/class-wcj-general-shortcodes.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack General Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack General Shortcodes class.
6
+ *
7
+ * @class WCJ_General_Shortcodes
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_General_Shortcodes' ) ) :
16
+
17
+ class WCJ_General_Shortcodes extends WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->the_shortcodes = array(
25
+ 'wcj_current_date',
26
+ //'wcj_image',
27
+ );
28
+
29
+ $this->the_atts = array(
30
+ 'date_format' => get_option( 'date_format' ),
31
+ /*'url' => '',
32
+ 'class' => '',
33
+ 'width' => '',
34
+ 'height' => '',*/
35
+ );
36
+
37
+ parent::__construct();
38
+
39
+ }
40
+
41
+ /**
42
+ * wcj_current_date.
43
+ */
44
+ function wcj_current_date( $atts ) {
45
+ return date_i18n( $atts['date_format'] );
46
+ }
47
+
48
+ /**
49
+ * wcj_image.
50
+ */
51
+ /*function wcj_image( $atts ) {
52
+ return '<img src="' . $atts['url'] . '" class="' . $atts['class'] . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '">';
53
+ }*/
54
+ }
55
+
56
+ endif;
57
+
58
+ return new WCJ_General_Shortcodes();
includes/shortcodes/class-wcj-invoices-shortcodes.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Invoices Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack Invoices Shortcodes class.
6
+ *
7
+ * @class WCJ_PDF_Invoices_Shortcodes
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Invoices_Shortcodes' ) ) :
16
+
17
+ class WCJ_Invoices_Shortcodes extends WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->the_shortcodes = array(
25
+
26
+ 'wcj_invoice_number',
27
+ 'wcj_proforma_invoice_number',
28
+ 'wcj_packing_slip_number',
29
+
30
+ 'wcj_invoice_date',
31
+ 'wcj_proforma_invoice_date',
32
+ 'wcj_packing_slip_date',
33
+
34
+ );
35
+
36
+ $this->the_atts = array(
37
+ 'order_id' => 0,
38
+ 'date_format' => get_option( 'date_format' ),
39
+ 'days' => 0,
40
+ 'invoice_type' => 'invoice',
41
+ );
42
+
43
+ parent::__construct();
44
+ }
45
+
46
+ /**
47
+ * init_atts.
48
+ */
49
+ function init_atts( $atts ) {
50
+
51
+ // Atts
52
+ if ( 0 == $atts['order_id'] ) {
53
+ $atts['order_id'] = ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID();
54
+ if ( 0 == $atts['order_id'] ) return false;
55
+ }
56
+ if ( 'shop_order' !== get_post_type( $atts['order_id'] ) ) return false;
57
+
58
+ // Class properties
59
+ /*if ( ! in_array( $atts['invoice_type'], wcj_enabled_invoice_types_ids() ) ) return false;
60
+ $this->the_invoice = wc_get_invoice( $atts['order_id'], $atts['invoice_type'] );
61
+ if ( ! $this->the_invoice ) return false;*/
62
+
63
+ return $atts;
64
+ }
65
+
66
+ /**
67
+ * wcj_invoice_date.
68
+ */
69
+ function wcj_invoice_date( $atts ) {
70
+ return wcj_get_invoice_date( $atts['order_id'], $atts['invoice_type'], $atts['days'], $atts['date_format'] );
71
+ }
72
+ function wcj_proforma_invoice_date( $atts ) {
73
+ return wcj_get_invoice_date( $atts['order_id'], 'proforma_invoice', $atts['days'], $atts['date_format'] );
74
+ }
75
+ function wcj_packing_slip_date( $atts ) {
76
+ return wcj_get_invoice_date( $atts['order_id'], 'packing_slip', $atts['days'], $atts['date_format'] );
77
+ }
78
+
79
+ /**
80
+ * wcj_invoice_number.
81
+ */
82
+ function wcj_invoice_number( $atts ) {
83
+ return wcj_get_invoice_number( $atts['order_id'], $atts['invoice_type'] );
84
+ }
85
+ function wcj_proforma_invoice_number( $atts ) {
86
+ return wcj_get_invoice_number( $atts['order_id'], 'proforma_invoice' );
87
+ }
88
+ function wcj_packing_slip_number( $atts ) {
89
+ return wcj_get_invoice_number( $atts['order_id'], 'packing_slip' );
90
+ }
91
+ }
92
+
93
+ endif;
94
+
95
+ return new WCJ_Invoices_Shortcodes();
includes/shortcodes/class-wcj-order-items-shortcodes.php ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Order Items Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack Order Items Shortcodes class.
6
+ *
7
+ * @class WCJ_Order_Items_Shortcodes
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Order_Items_Shortcodes' ) ) :
16
+
17
+ class WCJ_Order_Items_Shortcodes extends WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->the_shortcodes = array(
25
+ 'wcj_order_items_table',
26
+ );
27
+
28
+ parent::__construct();
29
+ }
30
+
31
+ /**
32
+ * add_extra_atts.
33
+ */
34
+ function add_extra_atts( $atts ) {
35
+ $modified_atts = array_merge( array(
36
+ 'order_id' => ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID(),
37
+ 'hide_currency' => 'no',
38
+ 'table_class' => '',
39
+ 'shipping_as_item' => '',//__( 'Shipping', 'woocommerce-jetpack' ),
40
+ 'discount_as_item' => '',//__( 'Discount', 'woocommerce-jetpack' ),
41
+ 'columns' => '',
42
+ 'columns_titles' => '',
43
+ 'columns_styles' => '',
44
+ 'tax_percent_format' => '%.2f %%',
45
+ 'item_image_width' => 0,
46
+ 'item_image_height' => 0,
47
+ ), $atts );
48
+ return $modified_atts;
49
+ }
50
+
51
+ /**
52
+ * init_atts.
53
+ */
54
+ function init_atts( $atts ) {
55
+ $this->the_order = ( 'shop_order' === get_post_type( $atts['order_id'] ) ) ? wc_get_order( $atts['order_id'] ) : null;
56
+ if ( ! $this->the_order ) return false;
57
+ return $atts;
58
+ }
59
+
60
+ /**
61
+ * wcj_price_shortcode.
62
+ */
63
+ private function wcj_price_shortcode( $raw_price, $atts ) {
64
+ return wcj_price( $raw_price, $this->the_order->get_order_currency(), $atts['hide_currency'] );
65
+ }
66
+
67
+ /**
68
+ * add_item.
69
+ */
70
+ private function add_item( $items, $new_item_args = array() ) {
71
+ if ( empty ( $new_item_args ) ) return $items;
72
+ extract( $new_item_args );
73
+ // Create item
74
+ $items[] = array(
75
+ 'is_custom' => true,
76
+ 'name' => $name,
77
+ 'type' => 'line_item',
78
+ 'qty' => $qty,
79
+ 'line_subtotal' => $line_subtotal,
80
+ 'line_total' => $line_total,
81
+ 'line_tax' => $line_tax,
82
+ 'line_subtotal_tax' => $line_subtotal_tax,
83
+ 'item_meta' => array(
84
+ '_qty' => array( $qty ),
85
+ '_line_subtotal' => array( $line_subtotal ),
86
+ '_line_total' => array( $line_total ),
87
+ '_line_tax' => array( $line_tax ),
88
+ '_line_subtotal_tax' => array( $line_subtotal_tax ),
89
+ ),
90
+ );
91
+ return $items;
92
+ }
93
+
94
+ /**
95
+ * wcj_order_items_table.
96
+ */
97
+ function wcj_order_items_table( $atts, $content = '' ) {
98
+
99
+ $html = '';
100
+ $the_order = $this->the_order;
101
+
102
+ // Get columns
103
+ $columns = explode( '|', $atts['columns'] );
104
+ if ( empty( $columns ) ) return '';
105
+ $columns_total_number = count( $columns );
106
+ // Check all possible args
107
+ $columns_titles = ( '' == $atts['columns_titles'] ) ? array() : explode( '|', $atts['columns_titles'] );
108
+ $columns_styles = ( '' == $atts['columns_styles'] ) ? array() : explode( '|', $atts['columns_styles'] );
109
+ //if ( ! ( $columns_total_number === count( $columns_titles ) === count( $columns_styles ) ) ) return '';
110
+
111
+ // The Items
112
+ $the_items = $the_order->get_items();
113
+
114
+ // Shipping as item
115
+ if ( '' != $atts['shipping_as_item'] && $the_order->get_total_shipping() > 0 ) {
116
+ $name = str_replace( '%shipping_method_name%', $the_order->get_shipping_method(), $atts['shipping_as_item'] );
117
+ $total_tax_excl = $the_order->get_total_shipping();
118
+ $tax = $the_order->get_shipping_tax();
119
+
120
+ $the_items = $this->add_item( $the_items, array( 'name' => $name, 'qty' => 1, 'line_subtotal' => $total_tax_excl, 'line_total' => $total_tax_excl, 'line_tax' => $tax, 'line_subtotal_tax' => $tax, ) );
121
+ }
122
+
123
+ // Discount as item
124
+ if ( '' != $atts['discount_as_item'] && $the_order->get_total_discount( true ) > 0 ) {
125
+ $name = $atts['discount_as_item'];
126
+ $total_tax_excl = $the_order->get_total_discount( true );
127
+ $tax = $the_order->get_total_discount( false ) - $total_tax_excl;
128
+
129
+ $the_items = $this->add_item( $the_items, array( 'name' => $name, 'qty' => 1, 'line_subtotal' => $total_tax_excl, 'line_total' => $total_tax_excl, 'line_tax' => $tax, 'line_subtotal_tax' => $tax, ) );
130
+ }
131
+
132
+ // Starting data[] by adding columns titles
133
+ $data = array();
134
+ foreach( $columns_titles as $column_title ) {
135
+ $data[0][] = $column_title;
136
+ }
137
+ // Items to data[]
138
+ $item_counter = 0;
139
+ foreach ( $the_items as $item ) {
140
+ $item['is_custom'] = ( isset( $item['is_custom'] ) ) ? true : false;
141
+ $the_product = ( true === $item['is_custom'] ) ? null : $the_order->get_product_from_item( $item );
142
+ $item_counter++;
143
+ // Columns
144
+ foreach( $columns as $column ) {
145
+ switch ( $column ) {
146
+ case 'item_number':
147
+ $data[ $item_counter ][] = $item_counter;
148
+ break;
149
+ case 'item_name':
150
+ //$data[ $item_counter ][] = ( true === $item['is_custom'] ) ? $item['name'] : $the_product->get_title();
151
+ if ( true === $item['is_custom'] ) {
152
+ $data[ $item_counter ][] = $item['name'];
153
+ } else {
154
+ $the_item_title = $the_product->get_title();
155
+ // Variation (if needed)
156
+ if ( $the_product->is_type( 'variation' ) )
157
+ $the_item_title .= '<div style="font-size:smaller;">' . wc_get_formatted_variation( $the_product->variation_data, true ) . '</div>';
158
+ $data[ $item_counter ][] = $the_item_title;
159
+ }
160
+ break;
161
+ case 'item_thumbnail':
162
+ //$data[ $item_counter ][] = $the_product->get_image();
163
+ $image_id = ( true === $item['is_custom'] ) ? 0 : $the_product->get_image_id();
164
+ $image_src = ( 0 != $image_id ) ? wp_get_attachment_image_src( $image_id ) : wc_placeholder_img_src();
165
+ if ( is_array( $image_src ) ) $image_src = $image_src[0];
166
+ $maybe_width = ( 0 != $atts['item_image_width'] ) ? ' width="' . $atts['item_image_width'] . '"' : '';
167
+ $maybe_height = ( 0 != $atts['item_image_height'] ) ? ' height="' . $atts['item_image_height'] . '"' : '';
168
+ $data[ $item_counter ][] = '<img src="' . $image_src . '"' . $maybe_width . $maybe_height . '>';
169
+ break;
170
+ case 'item_sku':
171
+ $data[ $item_counter ][] = ( true === $item['is_custom'] ) ? '' : $the_product->get_sku();
172
+ break;
173
+ case 'item_quantity':
174
+ $data[ $item_counter ][] = $item['qty'];
175
+ break;
176
+ case 'item_total_tax_excl':
177
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_item_total( $item, false, true ), $atts );
178
+ break;
179
+ case 'item_total_tax_incl':
180
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_item_total( $item, true, true ), $atts );
181
+ break;
182
+ case 'item_subtotal_tax_excl':
183
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_item_subtotal( $item, false, true ), $atts );
184
+ break;
185
+ case 'item_subtotal_tax_incl':
186
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_item_subtotal( $item, true, true ), $atts );
187
+ break;
188
+ case 'item_tax':
189
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_item_tax( $item, true ), $atts );
190
+ break;
191
+ case 'line_total_tax_excl':
192
+ $line_total_tax_excl = $the_order->get_line_total( $item, false, true );
193
+ $line_total_tax_excl = apply_filters( 'wcj_line_total_tax_excl', $line_total_tax_excl, $the_order );
194
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $line_total_tax_excl, $atts );
195
+ break;
196
+ case 'line_total_tax_incl':
197
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_line_total( $item, true, true ), $atts );
198
+ break;
199
+ case 'line_subtotal_tax_excl':
200
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_line_subtotal( $item, false, true ), $atts );
201
+ break;
202
+ case 'line_subtotal_tax_incl':
203
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $the_order->get_line_subtotal( $item, true, true ), $atts );
204
+ break;
205
+ case 'line_tax':
206
+ $line_tax = $the_order->get_line_tax( $item );
207
+ $line_tax = apply_filters( 'wcj_line_tax', $line_tax, $the_order );
208
+ $data[ $item_counter ][] = $this->wcj_price_shortcode( $line_tax, $atts );
209
+ break;
210
+ case 'item_tax_percent':
211
+ $item_total = $the_order->get_item_total( $item, false, true );
212
+ $item_tax_percent = ( 0 != $item_total ) ? $the_order->get_item_tax( $item, false ) / $item_total * 100 : 0;
213
+ $data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $item_tax_percent );
214
+ break;
215
+ case 'line_tax_percent':
216
+ $line_total = $the_order->get_line_total( $item, false, true );
217
+ $line_tax_percent = ( 0 != $line_total ) ? $the_order->get_line_tax( $item ) / $line_total * 100 : 0;
218
+ $line_tax_percent = apply_filters( 'wcj_line_tax_percent', $line_tax_percent, $the_order );
219
+ $data[ $item_counter ][] = sprintf( $atts['tax_percent_format'], $line_tax_percent );
220
+ break;
221
+ default:
222
+ $data[ $item_counter ][] = '';
223
+ }
224
+ }
225
+ }
226
+
227
+ $html = wcj_get_table_html( $data, array(
228
+ 'table_class' => $atts['table_class'],
229
+ 'table_heading_type' => 'horizontal',
230
+ 'columns_classes' => array(),
231
+ 'columns_styles' => $columns_styles,
232
+ ) );
233
+
234
+ return $html;
235
+ }
236
+ }
237
+
238
+ endif;
239
+
240
+ return new WCJ_Order_Items_Shortcodes();
includes/shortcodes/class-wcj-orders-shortcodes.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Orders Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack Orders Shortcodes class.
6
+ *
7
+ * @class WCJ_Orders_Shortcodes
8
+ * @version 2.1.1
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Orders_Shortcodes' ) ) :
16
+
17
+ class WCJ_Orders_Shortcodes extends WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->the_shortcodes = array(
25
+ 'wcj_order_date',
26
+ 'wcj_order_time',
27
+ 'wcj_order_number',
28
+ 'wcj_order_id',
29
+ 'wcj_order_billing_address',
30
+ 'wcj_order_shipping_address',
31
+ 'wcj_order_subtotal',
32
+ 'wcj_order_total_discount',
33
+ 'wcj_order_shipping_tax',
34
+ 'wcj_order_total_tax',
35
+ 'wcj_order_total_tax_percent',
36
+ 'wcj_order_total',
37
+ 'wcj_order_currency',
38
+ 'wcj_order_total_in_words',
39
+ 'wcj_order_total_excl_tax',
40
+ 'wcj_order_shipping_price',
41
+ 'wcj_order_payment_method',
42
+ 'wcj_order_shipping_method',
43
+ 'wcj_order_items_total_weight',
44
+ 'wcj_order_items_total_quantity',
45
+ 'wcj_order_items_total_number',
46
+ );
47
+
48
+ parent::__construct();
49
+ }
50
+
51
+ /**
52
+ * add_extra_atts.
53
+ */
54
+ function add_extra_atts( $atts ) {
55
+ $modified_atts = array_merge( array(
56
+ //'order_id' => ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID(),
57
+ 'order_id' => 0,
58
+ 'hide_currency' => 'no',
59
+ 'excl_tax' => 'no',
60
+ 'date_format' => get_option( 'date_format' ),
61
+ 'time_format' => get_option( 'time_format' ),
62
+ 'hide_if_zero' => 'no',
63
+ ), $atts );
64
+
65
+ return $modified_atts;
66
+ }
67
+
68
+ /**
69
+ * init_atts.
70
+ */
71
+ function init_atts( $atts ) {
72
+
73
+ // Atts
74
+ $atts['excl_tax'] = ( 'yes' === $atts['excl_tax'] ) ? true : false;
75
+
76
+ if ( 0 == $atts['order_id'] ) $atts['order_id'] = ( isset( $_GET['order_id'] ) ) ? $_GET['order_id'] : get_the_ID();
77
+ if ( 0 == $atts['order_id'] ) $atts['order_id'] = ( isset( $_GET['pdf_invoice'] ) ) ? $_GET['pdf_invoice'] : 0;
78
+ //if ( 0 == $atts['order_id'] ) $atts['order_id'] = get_the_ID();
79
+ if ( 0 == $atts['order_id'] ) return false;
80
+ //if ( 'shop_order' !== get_post_type( $atts['order_id'] ) ) return false;
81
+
82
+ // Class properties
83
+ $this->the_order = ( 'shop_order' === get_post_type( $atts['order_id'] ) ) ? wc_get_order( $atts['order_id'] ) : null;
84
+ if ( ! $this->the_order ) return false;
85
+
86
+ return $atts;
87
+ }
88
+
89
+ /**
90
+ * wcj_price_shortcode.
91
+ */
92
+ private function wcj_price_shortcode( $raw_price, $atts ) {
93
+ return ( 'yes' === $atts['hide_if_zero'] && 0 == $raw_price ) ? '' : wcj_price( $raw_price, $this->the_order->get_order_currency(), $atts['hide_currency'] );
94
+ }
95
+
96
+ /**
97
+ * wcj_order_shipping_method.
98
+ */
99
+ function wcj_order_shipping_method( $atts ) {
100
+ return $this->the_order->get_shipping_method();
101
+ }
102
+
103
+ /**
104
+ * wcj_order_payment_method.
105
+ */
106
+ function wcj_order_payment_method( $atts ) {
107
+ //return $this->the_order->payment_method_title;
108
+ return get_post_meta( $this->the_order->id, '_payment_method_title', true );
109
+ }
110
+
111
+ /**
112
+ * wcj_order_items_total_weight.
113
+ */
114
+ function wcj_order_items_total_weight( $atts ) {
115
+ $total_weight = 0;
116
+ $the_items = $this->the_order->get_items();
117
+ foreach( $the_items as $the_item ) {
118
+ $the_product = wc_get_product( $the_item['product_id'] );
119
+ $total_weight += $the_item['qty'] * $the_product->get_weight();
120
+ }
121
+ return ( 0 == $total_weight && 'yes' === $atts['hide_if_zero'] ) ? '' : $total_weight;
122
+ }
123
+
124
+ /**
125
+ * wcj_order_items_total_quantity.
126
+ */
127
+ function wcj_order_items_total_quantity( $atts ) {
128
+ $total_quantity = 0;
129
+ $the_items = $this->the_order->get_items();
130
+ foreach( $the_items as $the_item ) {
131
+ $total_quantity += $the_item['qty'];
132
+ }
133
+ return ( 0 == $total_quantity && 'yes' === $atts['hide_if_zero'] ) ? '' : $total_quantity;
134
+ }
135
+
136
+ /**
137
+ * wcj_order_items_total_number.
138
+ */
139
+ function wcj_order_items_total_number( $atts ) {
140
+ $total_number = count( $this->the_order->get_items() );
141
+ return ( 0 == $total_number && 'yes' === $atts['hide_if_zero'] ) ? '' : $total_number;
142
+ }
143
+
144
+ /**
145
+ * wcj_order_billing_address.
146
+ */
147
+ function wcj_order_billing_address( $atts ) {
148
+ return $this->the_order->get_formatted_billing_address();
149
+ }
150
+
151
+ /**
152
+ * wcj_order_shipping_address.
153
+ */
154
+ function wcj_order_shipping_address( $atts ) {
155
+ return $this->the_order->get_formatted_shipping_address();
156
+ }
157
+
158
+ /**
159
+ * wcj_order_date.
160
+ */
161
+ function wcj_order_date( $atts ) {
162
+ return date_i18n( $atts['date_format'], strtotime( $this->the_order->order_date ) );
163
+ }
164
+
165
+ /**
166
+ * wcj_order_time.
167
+ */
168
+ function wcj_order_time( $atts ) {
169
+ return date_i18n( $atts['time_format'], strtotime( $this->the_order->order_date ) );
170
+ }
171
+
172
+ /**
173
+ * wcj_order_number.
174
+ */
175
+ function wcj_order_number( $atts ) {
176
+ return $this->the_order->get_order_number();
177
+ }
178
+
179
+ /**
180
+ * wcj_order_id.
181
+ */
182
+ function wcj_order_id( $atts ) {
183
+ return $atts['order_id'];
184
+ }
185
+
186
+ /**
187
+ * wcj_order_shipping_price.
188
+ */
189
+ function wcj_order_shipping_price( $atts ) {
190
+ $the_result = ( true === $atts['excl_tax'] ) ? $this->the_order->get_total_shipping() - $this->the_order->get_shipping_tax() : $this->the_order->get_total_shipping();
191
+ return $this->wcj_price_shortcode( $the_result , $atts );
192
+ }
193
+
194
+ /**
195
+ * wcj_order_total_discount.
196
+ */
197
+ function wcj_order_total_discount( $atts ) {
198
+ return $this->wcj_price_shortcode( $this->the_order->get_total_discount( $atts['excl_tax'] ) , $atts );
199
+ }
200
+
201
+ /**
202
+ * wcj_order_shipping_tax.
203
+ */
204
+ function wcj_order_shipping_tax( $atts ) {
205
+ return $this->wcj_price_shortcode( $this->the_order->get_shipping_tax(), $atts );
206
+ }
207
+
208
+ /**
209
+ * wcj_order_total_tax_percent.
210
+ */
211
+ function wcj_order_total_tax_percent( $atts ) {
212
+
213
+ $order_total_excl_tax = $this->the_order->get_total() - $this->the_order->get_total_tax();
214
+ $order_total_tax = $this->the_order->get_total_tax();
215
+ $order_total_tax_percent = ( 0 == $order_total_excl_tax ) ? 0 : $order_total_tax / $order_total_excl_tax * 100;
216
+
217
+ $order_total_tax_percent = apply_filters( 'wcj_order_total_tax_percent', $order_total_tax_percent, $this->the_order );
218
+
219
+ return $order_total_tax_percent;
220
+ //return $this->wcj_price_shortcode( $order_total_tax_percent, $atts );;
221
+ }
222
+
223
+ /**
224
+ * wcj_order_total_tax.
225
+ */
226
+ function wcj_order_total_tax( $atts ) {
227
+ $order_total_tax = $this->the_order->get_total_tax();
228
+ $order_total_tax = apply_filters( 'wcj_order_total_tax', $order_total_tax, $this->the_order );
229
+ return $this->wcj_price_shortcode( $order_total_tax, $atts );
230
+ //return wcj_price( $order_total_tax, $this->the_order->get_order_currency(), $atts['hide_currency'] );
231
+ }
232
+
233
+ /**
234
+ * wcj_order_subtotal.
235
+ */
236
+ function wcj_order_subtotal( $atts ) {
237
+ return $this->wcj_price_shortcode( $this->the_order->get_subtotal(), $atts );
238
+ }
239
+
240
+ /**
241
+ * wcj_order_total_excl_tax.
242
+ */
243
+ function wcj_order_total_excl_tax( $atts ) {
244
+ $order_total = $this->the_order->get_total() - $this->the_order->get_total_tax();
245
+ $order_total = apply_filters( 'wcj_order_total_excl_tax', $order_total, $this->the_order );
246
+ return $this->wcj_price_shortcode( $order_total, $atts );
247
+ }
248
+
249
+ /**
250
+ * wcj_order_currency.
251
+ */
252
+ function wcj_order_currency( $atts ) {
253
+ return $this->the_order->get_order_currency();
254
+ }
255
+
256
+ /**
257
+ * wcj_order_total.
258
+ */
259
+ function wcj_order_total( $atts ) {
260
+ $order_total = ( true === $atts['excl_tax'] ) ? $this->the_order->get_total() - $this->the_order->get_total_tax() : $this->the_order->get_total();
261
+ return $this->wcj_price_shortcode( $order_total, $atts );
262
+ }
263
+
264
+ /**
265
+ * wcj_order_total_in_words.
266
+ */
267
+ function wcj_order_total_in_words( $atts ) {
268
+ $order_total = ( true === $atts['excl_tax'] ) ? $this->the_order->get_total() - $this->the_order->get_total_tax() : $this->the_order->get_total();
269
+ $order_total_dollars = intval( $order_total );
270
+ $order_total_cents = ( $order_total - intval( $order_total ) ) * 100;
271
+
272
+ $the_number_in_words = '%s %s';
273
+ if ( 0 != $order_total_cents ) $the_number_in_words .= ', %s %s.';
274
+ else $the_number_in_words .= '.';
275
+ $dollars = 'Dollars';//$this->the_order->get_order_currency();
276
+ $cents = 'Cents';
277
+ return sprintf( $the_number_in_words,
278
+ ucfirst( convert_number_to_words( $order_total_dollars ) ),
279
+ $dollars,
280
+ ucfirst( convert_number_to_words( $order_total_cents ) ),
281
+ $cents );
282
+ }
283
+ }
284
+
285
+ endif;
286
+
287
+ return new WCJ_Orders_Shortcodes();
includes/shortcodes/class-wcj-products-shortcodes.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Products Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack Products Shortcodes class.
6
+ *
7
+ * @class WCJ_Products_Shortcodes
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Products_Shortcodes' ) ) :
16
+
17
+ class WCJ_Products_Shortcodes extends WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ $this->the_shortcodes = array(
25
+ 'wcj_product_image',
26
+ 'wcj_product_price',
27
+ );
28
+
29
+ $this->the_atts = array(
30
+ 'product_id' => 0,
31
+ 'image_size' => 'shop_thumbnail',
32
+ 'multiply_by' => '',
33
+ );
34
+
35
+ parent::__construct();
36
+ }
37
+
38
+ /**
39
+ * init_atts.
40
+ */
41
+ function init_atts( $atts ) {
42
+
43
+ // Atts
44
+ $atts['product_id'] = ( 0 == $atts['product_id'] ) ? get_the_ID() : $atts['product_id'];
45
+ if ( 0 == $atts['product_id'] ) return false;
46
+ if ( 'product' !== get_post_type( $atts['product_id'] ) ) return false;
47
+
48
+ // Class properties
49
+ $this->the_product = wc_get_product( $atts['product_id'] );
50
+ if ( ! $this->the_product ) return false;
51
+
52
+ return $atts;
53
+ }
54
+
55
+ /**
56
+ * wcj_product_price.
57
+ */
58
+ function wcj_product_price( $atts ) {
59
+ return ( '' !== $atts['multiply_by'] && is_numeric( $atts['multiply_by'] ) ) ? $this->the_product->get_price() * $atts['multiply_by'] : $this->the_product->get_price();
60
+ }
61
+
62
+ /**
63
+ * wcj_product_image.
64
+ */
65
+ function wcj_product_image( $atts ) {
66
+ return $this->the_product->get_image( $atts['image_size'] );
67
+ }
68
+ }
69
+
70
+ endif;
71
+
72
+ return new WCJ_Products_Shortcodes();
73
+
includes/shortcodes/class-wcj-shortcodes.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WooCommerce Jetpack Shortcodes
4
+ *
5
+ * The WooCommerce Jetpack Shortcodes class.
6
+ *
7
+ * @class WCJ_Shortcodes
8
+ * @version 1.0.0
9
+ * @category Class
10
+ * @author Algoritmika Ltd.
11
+ */
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ if ( ! class_exists( 'WCJ_Shortcodes' ) ) :
16
+
17
+ class WCJ_Shortcodes {
18
+
19
+ /**
20
+ * Constructor.
21
+ */
22
+ public function __construct() {
23
+
24
+ foreach( $this->the_shortcodes as $the_shortcode ) {
25
+ add_shortcode( $the_shortcode, array( $this, 'wcj_shortcode' ) );
26
+ }
27
+
28
+ add_filter( 'wcj_shortcodes_list', array( $this, 'add_shortcodes_to_the_list' ) );
29
+ }
30
+
31
+ /**
32
+ * add_extra_atts.
33
+ */
34
+ function add_extra_atts( $atts ) {
35
+ $final_atts = array_merge( $this->the_atts, $atts );
36
+ return $final_atts;
37
+ }
38
+
39
+ /**
40
+ * init_atts.
41
+ */
42
+ function init_atts( $atts ) {
43
+ return $atts;
44
+ }
45
+
46
+ /**
47
+ * add_shortcodes_to_the_list.
48
+ */
49
+ function add_shortcodes_to_the_list( $shortcodes_list ) {
50
+ foreach( $this->the_shortcodes as $the_shortcode ) {
51
+ $shortcodes_list[] = $the_shortcode;
52
+ }
53
+ return $shortcodes_list;
54
+ }
55
+
56
+ /**
57
+ * wcj_shortcode.
58
+ */
59
+ function wcj_shortcode( $atts, $content, $shortcode ) {
60
+
61
+ // Init
62
+ if ( empty( $atts ) ) $atts = array();
63
+ $global_defaults = array(
64
+ 'before' => '',
65
+ 'after' => '',
66
+ 'visibility' => '',
67
+ );
68
+ $atts = array_merge( $global_defaults, $atts );
69
+
70
+ // Check if privileges are ok
71
+ if ( 'admin' === $atts['visibility'] && ! is_super_admin() ) return '';
72
+
73
+ // Add child class specific atts
74
+ $atts = $this->add_extra_atts( $atts );
75
+
76
+ // Check for required atts
77
+ if ( false === ( $atts = $this->init_atts( $atts ) ) ) return '';
78
+
79
+ // Run the shortcode function
80
+ $shortcode_function = $shortcode;
81
+ if ( '' !== ( $result = $this->$shortcode_function( $atts, $content ) ) )
82
+ return $atts['before'] . $result . $atts['after'];
83
+ return '';
84
+ }
85
+ }
86
+
87
+ endif;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://algoritmika.com/donate/
4
  Tags: woocommerce,woocommerce jetpack,custom price labels,call for price,currency symbol,remove sorting,remove old product slugs,add to cart text,order number,sequential order numbering,email pdf invoice,pdf invoice,pdf invoices,already in cart,empty cart,redirect to checkout,minimum order amount,customize checkout fields,checkout fields,email,customize product tabs,product tabs,related products number,empty cart,redirect add to cart,redirect to checkout,product already in cart,custom payment gateway,payment gateway icon,auto-complete all orders,custom order statuses,custom order status,remove text from price,custom css,hide categories count,hide subcategories count,hide category count,hide subcategory count,display total sales,custom product tabs,remove product tab,payment gateway fee,
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: 2.0.13
8
  License: GNU General Public License v3.0
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -18,7 +18,9 @@ WooCommerce Jetpack is a WordPress plugin that supercharges your site with aweso
18
  * Custom Price Labels - Create any custom price label for any product.
19
  * Call for Price - Create any custom price label, like *Call for price*, for all products with empty price.
20
  * Currencies - Add all world currencies, change currency symbol.
21
- * PDF Invoices - Add PDF invoices for store owners and for customers. Automatically email PDF invoices to customers (and limit attaching invoice to selected payment gateways only).
 
 
22
  * Orders - Sequential order numbering, custom order number prefix, date prefix, suffix and number width. Set minimum order amount.
23
  * More Sorting Options - Add more sorting options or remove sorting at all (including WooCommerce default).
24
  * Payment Gateways - Change icons (images) for all default (COD - Cash on Delivery, Cheque, BACS, Mijireh Checkout, PayPal) WooCommerce payment gateways.
@@ -28,13 +30,13 @@ WooCommerce Jetpack is a WordPress plugin that supercharges your site with aweso
28
  * Shipping - Hide shipping when free is available.
29
  * Emails - Add another email recipient(s) to all WooCommerce emails.
30
  * Product Listings - Change display options for shop and category pages: show/hide categories count, exclude categories, show/hide empty categories.
31
- * Product Info - Add more info to product on category or single pages. Change related products number.
32
  * Product Tabs - Add custom product tabs - globally, per category or per product. Customize or completely remove WooCommerce default product tabs.
33
  * Cart - Add "Empty Cart" button to cart page, automatically add product to cart on visit.
34
  * Add to Cart - Change text for add to cart buttons for each product type, on per category or per product basis. Display "Product already in cart" instead of "Add to cart" button. Redirect add to cart button to any url (e.g. checkout page).
35
  * Old Slugs - Remove old product slugs.
36
  * Bulk Price Converter tool.
37
- * Prices and Currencies by Country.
38
  * Bulk SKUs generator tool.
39
  * Different Currency for External Products.
40
  * Another custom CSS tool, if you need one.
@@ -68,8 +70,37 @@ To unlock all WooCommerce Jetpack features, please install additional <a href="h
68
 
69
  == Changelog ==
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  = 2.0.13 - 12/02/2015 =
72
- * Fix - ORDERS - Quick fix for WooCommerce v.2.3 compatibility.
73
 
74
  = 2.0.12 - 14/01/2015 =
75
  * Dev - **Reports** - WooJetpack Orders Reports: More Ranges.
@@ -211,7 +242,7 @@ To unlock all WooCommerce Jetpack features, please install additional <a href="h
211
  %stock_availability% (by https://wordpress.org/support/topic/custom-tabs-1),
212
  %time_since_last_sale%, %weight%, %list_attributes% etc.
213
  For full list of short codes, please visit http://woojetpack.com/features/product-info/
214
- * Feature Upgraded - Product Listings - Option to change default WooCommece behavior on displaying all products if none categories are dispalyed.
215
  Now it's possible to disable displaying the products. Suggested by Xavier.
216
  * Feature Upgraded - PDF Invoices - Order date and time added. Suggested by https://wordpress.org/support/topic/order-time
217
 
4
  Tags: woocommerce,woocommerce jetpack,custom price labels,call for price,currency symbol,remove sorting,remove old product slugs,add to cart text,order number,sequential order numbering,email pdf invoice,pdf invoice,pdf invoices,already in cart,empty cart,redirect to checkout,minimum order amount,customize checkout fields,checkout fields,email,customize product tabs,product tabs,related products number,empty cart,redirect add to cart,redirect to checkout,product already in cart,custom payment gateway,payment gateway icon,auto-complete all orders,custom order statuses,custom order status,remove text from price,custom css,hide categories count,hide subcategories count,hide category count,hide subcategory count,display total sales,custom product tabs,remove product tab,payment gateway fee,
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 2.1.1
8
  License: GNU General Public License v3.0
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
18
  * Custom Price Labels - Create any custom price label for any product.
19
  * Call for Price - Create any custom price label, like *Call for price*, for all products with empty price.
20
  * Currencies - Add all world currencies, change currency symbol.
21
+ * PDF Invoicing and Packing Slips - Add PDF invoices for store owners and for customers. Automatically email PDF invoices to customers (and limit attaching invoice to selected payment gateways only).
22
+ Module includes proforma invoices, proforma slips, with separate numbering for each document type.
23
+ Extended templates (and shortcodes), styling, page, header and footer, filename, emailing etc. customization options.
24
  * Orders - Sequential order numbering, custom order number prefix, date prefix, suffix and number width. Set minimum order amount.
25
  * More Sorting Options - Add more sorting options or remove sorting at all (including WooCommerce default).
26
  * Payment Gateways - Change icons (images) for all default (COD - Cash on Delivery, Cheque, BACS, Mijireh Checkout, PayPal) WooCommerce payment gateways.
30
  * Shipping - Hide shipping when free is available.
31
  * Emails - Add another email recipient(s) to all WooCommerce emails.
32
  * Product Listings - Change display options for shop and category pages: show/hide categories count, exclude categories, show/hide empty categories.
33
+ * Product Info - Add more info to product on category or single pages. Change related products number, select to relate by tag and/or by category.
34
  * Product Tabs - Add custom product tabs - globally, per category or per product. Customize or completely remove WooCommerce default product tabs.
35
  * Cart - Add "Empty Cart" button to cart page, automatically add product to cart on visit.
36
  * Add to Cart - Change text for add to cart buttons for each product type, on per category or per product basis. Display "Product already in cart" instead of "Add to cart" button. Redirect add to cart button to any url (e.g. checkout page).
37
  * Old Slugs - Remove old product slugs.
38
  * Bulk Price Converter tool.
39
+ * Prices and Currencies by Country - Change product’s price and currency by customer’s country - globally or per product. Customer’s country is detected automatically by IP. Automatic currency exchange rates updates.
40
  * Bulk SKUs generator tool.
41
  * Different Currency for External Products.
42
  * Another custom CSS tool, if you need one.
70
 
71
  == Changelog ==
72
 
73
+ = 2.1.1 - 18/02/2015 =
74
+ * Orders Shortcodes - Shortcodes compatibility with PDF Invoices v1 module.
75
+ * Orders Shortcodes - Added `hide_if_zero` checking for `_order_item_total_` shortcodes.
76
+
77
+ = 2.1.0 - 17/02/2015 =
78
+ * Dev - **PDF Invoicing and Packing Slips** - Module added.
79
+ Module includes proforma invoices, proforma slips, with separate numbering (and invoices renumerate tool) for each document type.
80
+ Extended templates (and shortcodes), styling, page, header and footer, filename, emailing etc. customization options.
81
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Prices and currencies by country *per product* functionality added.
82
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Major code refactoring.
83
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Admin debugging functionality added.
84
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Empty price functionality added.
85
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Automatic currency exchange rates (i.e. wp cron job) updates, added.
86
+ * Dev - CURRENCIES - **Prices and Currencies by Country** - Internal DB since WooCommerce 2.3, added.
87
+ * Dev - PRODUCTS - **Product Info** - Option to list product IDs to exclude from product info, added.
88
+ * Dev - PRODUCTS - **Product Info** - Option to change single product's thumbnails columns number, added.
89
+ * Dev - PRODUCTS - **Product Input Fields** - Hiding placeholder on focus, added.
90
+ * Dev - PRODUCTS - **Product Input Fields** - Global and local modules merged into single module.
91
+ * Dev - PRICE LABELS - **Call for Price** - Added `do_shortcode` on all empty price outputs.
92
+ * Dev - CHECKOUT - **Payment Gateways** - Added `do_shortcode` in payment gateway's "thank you" page and email instructions.
93
+ * Dev - MISC. - **General** - *Admin Tools* (logging) added.
94
+ * Dev - PRODUCTS - **Related Products** - Moved to new module. *Relate by tag and/or category* options (idea by Alexys) added.
95
+ * Fix - ORDERS - "Extended fix" in `add_custom_order_statuses_to_reports()` for WooCommerce v.2.3 compatibility.
96
+ * Fix - ORDERS - **Order Numbers** - Now generating number when creating order from admin backend.
97
+ * Fix - **PDF Invoices** - Bug in `generate_pdf()` (`order_id` not defined when first checking), fixed.
98
+ * Fix - **PDF Invoices** - `maybe_unserialize` instead of `serialize` in `add_custom_checkout_fields_to_pdf()`.
99
+ * Fix - PRODUCTS - **SKU** - Fix in *Autogenerate SKUs* tool: now SKUs are properly generated for larger (e.g. more that two thousand) quantity of products.
100
+ * Fix - CURRENCIES - "Undefined index: KIP" notice bug fixed.
101
+
102
  = 2.0.13 - 12/02/2015 =
103
+ * Fix - ORDERS - Quick fix in `add_custom_order_statuses_to_reports()` for WooCommerce v.2.3 compatibility.
104
 
105
  = 2.0.12 - 14/01/2015 =
106
  * Dev - **Reports** - WooJetpack Orders Reports: More Ranges.
242
  %stock_availability% (by https://wordpress.org/support/topic/custom-tabs-1),
243
  %time_since_last_sale%, %weight%, %list_attributes% etc.
244
  For full list of short codes, please visit http://woojetpack.com/features/product-info/
245
+ * Feature Upgraded - Product Listings - Option to change default WooCommerce behavior on displaying all products if none categories are dispalyed.
246
  Now it's possible to disable displaying the products. Suggested by Xavier.
247
  * Feature Upgraded - PDF Invoices - Order date and time added. Suggested by https://wordpress.org/support/topic/order-time
248
 
woocommerce-jetpack.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WooCommerce Jetpack
4
  Plugin URI: http://woojetpack.com
5
  Description: Supercharge your WooCommerce site with these awesome powerful features.
6
- Version: 2.0.13
7
  Author: Algoritmika Ltd
8
  Author URI: http://www.algoritmika.com
9
  Copyright: © 2015 Algoritmika Ltd.
@@ -39,8 +39,8 @@ final class WC_Jetpack {
39
  * @see WCJ()
40
  * @return WC_Jetpack - Main instance
41
  */
42
- public static function instance() {
43
- if ( is_null( self::$_instance ) )
44
  self::$_instance = new self();
45
  return self::$_instance;
46
  }
@@ -57,43 +57,56 @@ final class WC_Jetpack {
57
  *
58
  public function __wakeup() {
59
  _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce' ), '3.9.1' );
60
- }
61
 
62
  /**
63
  * WC_Jetpack Constructor.
64
  * @access public
65
- */
66
- public function __construct() {
67
-
68
  // Include required files
69
  $this->includes();
70
-
71
  // HOOKS
72
  //register_activation_hook( __FILE__, array( $this, 'install' ) );
73
  //add_action( 'admin_init', array( $this, 'install' ) );
74
  add_action( 'init', array( $this, 'init' ), 0 );
75
-
76
- //add_filter( 'wcj_get_option_filter', array( $this, 'wcj_get_option' ), 100 );
77
-
78
- // Settings
79
- if ( is_admin() ) {
80
  add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_wcj_settings_tab' ) );
81
- add_filter( 'get_wc_jetpack_plus_message', array( $this, 'get_wcj_plus_message' ), 100, 2 );
82
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
83
  add_action( 'admin_menu', array( $this, 'jetpack_menu' ), 100 );
 
84
  }
85
-
86
  // Loaded action
87
  do_action( 'wcj_loaded' );
88
  }
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  /**
91
  * Add menu item
92
  */
93
  public function jetpack_menu() {
94
- add_submenu_page( 'woocommerce', __( 'WooCommerce Jetpack', 'woocommerce' ), __( 'Jetpack Settings', 'woocommerce' ) , 'manage_woocommerce', 'admin.php?page=wc-settings&tab=jetpack' );
95
- }
96
-
97
  /**
98
  * Show action links on the plugin screen
99
  *
@@ -106,103 +119,163 @@ final class WC_Jetpack {
106
  '<a href="' . esc_url( apply_filters( 'woocommerce_docs_url', 'http://woojetpack.com/', 'woocommerce' ) ) . '">' . __( 'Docs', 'woocommerce' ) . '</a>',
107
  '<a href="' . esc_url( apply_filters( 'woocommerce_support_url', 'http://woojetpack.com/plus/' ) ) . '">' . __( 'Unlock all', 'woocommerce' ) . '</a>',
108
  ), $links );
109
- }
110
-
111
  /**
112
  * get_wcj_plus_message.
113
  */
114
  public function get_wcj_plus_message( $value, $message_type ) {
115
-
116
  switch ( $message_type ) {
117
-
118
  case 'global':
119
  return '<div class="updated">
120
  <p class="main"><strong>' . __( 'Install WooCommerce Jetpack Plus to unlock all features', 'woocommerce-jetpack' ) . '</strong></p>
121
- <span>' . sprintf( __('Some settings fields are locked and you will need %s to modify all locked fields.', 'woocommerce-jetpack'), '<a href="http://woojetpack.com/plus/">WooCommerce Jetpack Plus</a>' ) . '</span>
122
  <p><a href="http://woojetpack.com/plus/" target="_blank" class="button button-primary">' . __( 'Buy now', 'woocommerce-jetpack' ) . '</a> <a href="http://woojetpack.com" target="_blank" class="button">'. sprintf( __( 'Visit %s', 'woocommerce-jetpack' ), 'WooJetpack.com' ) . '</a></p>
123
  </div>';
124
-
125
  case 'desc':
126
  return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change value.', 'woocommerce-jetpack' );
127
-
128
  case 'desc_below':
129
- return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change values below.', 'woocommerce-jetpack' );
130
-
131
  case 'desc_above':
132
- return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change values above.', 'woocommerce-jetpack' );
133
-
134
  case 'desc_no_link':
135
  return __( 'Get WooCommerce Jetpack Plus to change value.', 'woocommerce-jetpack' );
136
 
137
  case 'readonly':
138
  return array( 'readonly' => 'readonly' );
139
-
140
  case 'disabled':
141
  return array( 'disabled' => 'disabled' );
142
-
143
  case 'readonly_string':
144
  return 'readonly';
145
-
146
  case 'disabled_string':
147
  return 'disabled';
148
  }
149
-
150
  return $value;
151
  }
152
-
153
  /**
154
  * Include required core files used in admin and on the frontend.
155
  */
156
  private function includes() {
157
-
 
 
 
 
 
 
 
 
158
  include_once( 'includes/admin/tools/class-wcj-tools.php' );
159
- //include_once( 'includes/class-wcj-shortcodes.php' );
160
-
161
- include_once( 'includes/abstracts/class-wcj-product-input-fields.php' );
162
-
163
- $settings = array();
164
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  $settings[] = include_once( 'includes/class-wcj-price-labels.php' );
166
- $settings[] = include_once( 'includes/class-wcj-call-for-price.php' );
167
-
168
  $settings[] = include_once( 'includes/class-wcj-product-listings.php' );
169
  $settings[] = include_once( 'includes/class-wcj-sorting.php' );
170
  $settings[] = include_once( 'includes/class-wcj-product-info.php' );
 
171
  $settings[] = include_once( 'includes/class-wcj-sku.php' );
172
  $settings[] = include_once( 'includes/class-wcj-product-tabs.php' );
173
- $settings[] = include_once( 'includes/class-wcj-product-input-fields-global.php' );
174
- $settings[] = include_once( 'includes/class-wcj-product-input-fields-per-product.php' );
 
175
  $settings[] = include_once( 'includes/class-wcj-product-bulk-price-converter.php' );
176
-
177
  $settings[] = include_once( 'includes/class-wcj-cart.php' );
178
  $settings[] = include_once( 'includes/class-wcj-add-to-cart.php' );
179
  $settings[] = include_once( 'includes/class-wcj-add-to-cart-per-category.php' );
180
  $settings[] = include_once( 'includes/class-wcj-add-to-cart-per-product.php' );
181
-
182
  $settings[] = include_once( 'includes/class-wcj-checkout.php' );
183
  $settings[] = include_once( 'includes/class-wcj-checkout-custom-fields.php' );
184
  $settings[] = include_once( 'includes/class-wcj-payment-gateways.php' );
185
-
186
  $settings[] = include_once( 'includes/class-wcj-shipping.php' );
187
  $settings[] = include_once( 'includes/class-wcj-shipping-calculator.php' );
188
-
189
  $settings[] = include_once( 'includes/class-wcj-orders.php' );
190
  $settings[] = include_once( 'includes/class-wcj-order-numbers.php' );
191
-
192
- $settings[] = include_once( 'includes/class-wcj-pdf-invoices.php' );
193
-
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  $settings[] = include_once( 'includes/class-wcj-emails.php' );
195
-
196
  $settings[] = include_once( 'includes/class-wcj-currencies.php' );
197
  $settings[] = include_once( 'includes/class-wcj-currency-external-products.php' );
198
  $settings[] = include_once( 'includes/class-wcj-price-by-country.php' );
199
-
200
  $settings[] = include_once( 'includes/class-wcj-general.php' );
201
- $settings[] = include_once( 'includes/class-wcj-old-slugs.php' );
202
  $settings[] = include_once( 'includes/class-wcj-reports.php' );
203
-
 
204
  //include_once( 'includes/class-wcj-shortcodes.php' );
205
-
206
  // Add options
207
  if ( is_admin() ) {
208
  foreach ( $settings as $section ) {
@@ -212,15 +285,15 @@ final class WC_Jetpack {
212
  add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
213
  }
214
  }
215
- }
216
  }
217
  }
218
 
219
  /**
220
  * Add Jetpack settings tab to WooCommerce settings.
221
- */
222
- public function add_wcj_settings_tab( $settings ) {
223
- $settings[] = include( 'includes/admin/settings/class-wc-settings-jetpack.php' );
224
  return $settings;
225
  }
226
 
@@ -229,12 +302,30 @@ final class WC_Jetpack {
229
  */
230
  public function init() {
231
  // Before init action
232
- do_action( 'before_wcj_init' );
233
  // Set up localisation
234
- load_plugin_textdomain( 'woocommerce-jetpack', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
235
  // Init action
236
  do_action( 'wcj_init' );
237
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
239
 
240
  endif;
3
  Plugin Name: WooCommerce Jetpack
4
  Plugin URI: http://woojetpack.com
5
  Description: Supercharge your WooCommerce site with these awesome powerful features.
6
+ Version: 2.1.1
7
  Author: Algoritmika Ltd
8
  Author URI: http://www.algoritmika.com
9
  Copyright: © 2015 Algoritmika Ltd.
39
  * @see WCJ()
40
  * @return WC_Jetpack - Main instance
41
  */
42
+ public static function instance() {
43
+ if ( is_null( self::$_instance ) )
44
  self::$_instance = new self();
45
  return self::$_instance;
46
  }
57
  *
58
  public function __wakeup() {
59
  _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce' ), '3.9.1' );
60
+ }
61
 
62
  /**
63
  * WC_Jetpack Constructor.
64
  * @access public
65
+ */
66
+ public function __construct() {
67
+
68
  // Include required files
69
  $this->includes();
70
+
71
  // HOOKS
72
  //register_activation_hook( __FILE__, array( $this, 'install' ) );
73
  //add_action( 'admin_init', array( $this, 'install' ) );
74
  add_action( 'init', array( $this, 'init' ), 0 );
75
+
76
+ // Settings
77
+ if ( is_admin() ) {
 
 
78
  add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_wcj_settings_tab' ) );
79
+ add_filter( 'get_wc_jetpack_plus_message', array( $this, 'get_wcj_plus_message' ), 100, 2 );
80
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
81
  add_action( 'admin_menu', array( $this, 'jetpack_menu' ), 100 );
82
+ //add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 2 );
83
  }
84
+
85
  // Loaded action
86
  do_action( 'wcj_loaded' );
87
  }
88
 
89
+ /**
90
+ * admin_footer_text
91
+ *
92
+ public function admin_footer_text( $footer_text ) {
93
+
94
+ if ( isset( $_GET['page'] ) ) {
95
+ if ( 'wcj-tools' === $_GET['page'] || ( 'wc-settings' === $_GET['page'] && isset( $_GET['tab'] ) && 'jetpack' === $_GET['tab'] ) ) {
96
+ return sprintf( __( 'If you like <strong>WooCommerce Jetpack</strong> please leave us a <a href="%1$s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating on <a href="%1$s" target="_blank">WordPress.org</a>. We will be grateful for any help!', 'woocommerce-jetpack' ), 'https://wordpress.org/support/view/plugin-reviews/woocommerce-jetpack?filter=5#postform' );
97
+ }
98
+ }
99
+
100
+ return $footer_text;
101
+ }
102
+
103
  /**
104
  * Add menu item
105
  */
106
  public function jetpack_menu() {
107
+ add_submenu_page( 'woocommerce', __( 'WooCommerce Jetpack', 'woocommerce' ), __( 'Jetpack Settings', 'woocommerce' ) , 'manage_woocommerce', 'admin.php?page=wc-settings&tab=jetpack' );
108
+ }
109
+
110
  /**
111
  * Show action links on the plugin screen
112
  *
119
  '<a href="' . esc_url( apply_filters( 'woocommerce_docs_url', 'http://woojetpack.com/', 'woocommerce' ) ) . '">' . __( 'Docs', 'woocommerce' ) . '</a>',
120
  '<a href="' . esc_url( apply_filters( 'woocommerce_support_url', 'http://woojetpack.com/plus/' ) ) . '">' . __( 'Unlock all', 'woocommerce' ) . '</a>',
121
  ), $links );
122
+ }
123
+
124
  /**
125
  * get_wcj_plus_message.
126
  */
127
  public function get_wcj_plus_message( $value, $message_type ) {
128
+
129
  switch ( $message_type ) {
130
+
131
  case 'global':
132
  return '<div class="updated">
133
  <p class="main"><strong>' . __( 'Install WooCommerce Jetpack Plus to unlock all features', 'woocommerce-jetpack' ) . '</strong></p>
134
+ <span>' . sprintf( __('Some settings fields are locked and you will need %s to modify all locked fields.', 'woocommerce-jetpack'), '<a href="http://woojetpack.com/plus/">WooCommerce Jetpack Plus</a>' ) . '</span>
135
  <p><a href="http://woojetpack.com/plus/" target="_blank" class="button button-primary">' . __( 'Buy now', 'woocommerce-jetpack' ) . '</a> <a href="http://woojetpack.com" target="_blank" class="button">'. sprintf( __( 'Visit %s', 'woocommerce-jetpack' ), 'WooJetpack.com' ) . '</a></p>
136
  </div>';
137
+
138
  case 'desc':
139
  return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change value.', 'woocommerce-jetpack' );
140
+
141
  case 'desc_below':
142
+ return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change values below.', 'woocommerce-jetpack' );
143
+
144
  case 'desc_above':
145
+ return __( 'Get <a href="http://woojetpack.com/plus/" target="_blank">WooCommerce Jetpack Plus</a> to change values above.', 'woocommerce-jetpack' );
146
+
147
  case 'desc_no_link':
148
  return __( 'Get WooCommerce Jetpack Plus to change value.', 'woocommerce-jetpack' );
149
 
150
  case 'readonly':
151
  return array( 'readonly' => 'readonly' );
152
+
153
  case 'disabled':
154
  return array( 'disabled' => 'disabled' );
155
+
156
  case 'readonly_string':
157
  return 'readonly';
158
+
159
  case 'disabled_string':
160
  return 'disabled';
161
  }
162
+
163
  return $value;
164
  }
165
+
166
  /**
167
  * Include required core files used in admin and on the frontend.
168
  */
169
  private function includes() {
170
+
171
+ // Functions
172
+ $this->include_functions();
173
+
174
+ // Classes
175
+ include_once( 'includes/classes/class-wcj-invoice.php' );
176
+ include_once( 'includes/classes/class-wcj-pdf-invoice.php' );
177
+
178
+ // Tools
179
  include_once( 'includes/admin/tools/class-wcj-tools.php' );
180
+
181
+ // Shortcodes
182
+ $this->include_shortcodes();
183
+
184
+ // Abstracts
185
+ //include_once( 'includes/abstracts/class-wcj-product-input-fields.php' );
186
+
187
+ // Modules and Submodules
188
+ $this->include_modules();
189
+ }
190
+
191
+ /**
192
+ * include_functions.
193
+ */
194
+ private function include_functions() {
195
+ // Functions
196
+ include_once( 'includes/functions/wcj-debug-functions.php' );
197
+ include_once( 'includes/functions/wcj-functions.php' );
198
+ include_once( 'includes/functions/wcj-html-functions.php' );
199
+ include_once( 'includes/functions/wcj-country-functions.php' );
200
+ include_once( 'includes/functions/wcj-invoicing-functions.php' );
201
+ }
202
+
203
+ /**
204
+ * include_shortcodes.
205
+ */
206
+ private function include_shortcodes() {
207
+ // Shortcodes
208
+ include_once( 'includes/shortcodes/class-wcj-shortcodes.php' );
209
+ include_once( 'includes/shortcodes/class-wcj-general-shortcodes.php' );
210
+ include_once( 'includes/shortcodes/class-wcj-invoices-shortcodes.php' );
211
+ include_once( 'includes/shortcodes/class-wcj-orders-shortcodes.php' );
212
+ include_once( 'includes/shortcodes/class-wcj-order-items-shortcodes.php' );
213
+ include_once( 'includes/shortcodes/class-wcj-products-shortcodes.php' );
214
+ }
215
+
216
+ /**
217
+ * Include modules and submodules
218
+ */
219
+ private function include_modules() {
220
+ $settings = array();
221
+
222
  $settings[] = include_once( 'includes/class-wcj-price-labels.php' );
223
+ $settings[] = include_once( 'includes/class-wcj-call-for-price.php' );
224
+
225
  $settings[] = include_once( 'includes/class-wcj-product-listings.php' );
226
  $settings[] = include_once( 'includes/class-wcj-sorting.php' );
227
  $settings[] = include_once( 'includes/class-wcj-product-info.php' );
228
+ $settings[] = include_once( 'includes/class-wcj-related-products.php' );
229
  $settings[] = include_once( 'includes/class-wcj-sku.php' );
230
  $settings[] = include_once( 'includes/class-wcj-product-tabs.php' );
231
+ $settings[] = include_once( 'includes/class-wcj-product-input-fields.php' );
232
+ //$settings[] = include_once( 'includes/class-wcj-product-input-fields-global.php' );
233
+ //$settings[] = include_once( 'includes/class-wcj-product-input-fields-per-product.php' );
234
  $settings[] = include_once( 'includes/class-wcj-product-bulk-price-converter.php' );
235
+
236
  $settings[] = include_once( 'includes/class-wcj-cart.php' );
237
  $settings[] = include_once( 'includes/class-wcj-add-to-cart.php' );
238
  $settings[] = include_once( 'includes/class-wcj-add-to-cart-per-category.php' );
239
  $settings[] = include_once( 'includes/class-wcj-add-to-cart-per-product.php' );
240
+
241
  $settings[] = include_once( 'includes/class-wcj-checkout.php' );
242
  $settings[] = include_once( 'includes/class-wcj-checkout-custom-fields.php' );
243
  $settings[] = include_once( 'includes/class-wcj-payment-gateways.php' );
244
+
245
  $settings[] = include_once( 'includes/class-wcj-shipping.php' );
246
  $settings[] = include_once( 'includes/class-wcj-shipping-calculator.php' );
247
+
248
  $settings[] = include_once( 'includes/class-wcj-orders.php' );
249
  $settings[] = include_once( 'includes/class-wcj-order-numbers.php' );
250
+
251
+ $settings[] = include_once( 'includes/class-wcj-pdf-invoices.php' );
252
+
253
+ $settings[] = include_once( 'includes/class-wcj-pdf-invoicing.php' );
254
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-numbering.php' );
255
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-templates.php' );
256
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-styling.php' );
257
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-header.php' );
258
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-footer.php' );
259
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-page.php' );
260
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-emails.php' );
261
+ $settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-display.php' );
262
+ //$settings[] = include_once( 'includes/pdf-invoices/settings/class-wcj-pdf-invoicing-general.php' );
263
+
264
+ //$settings[] = include_once( 'includes/pdf-invoices/class-wcj-pdf-invoices-by-settings.php' );
265
+
266
  $settings[] = include_once( 'includes/class-wcj-emails.php' );
267
+
268
  $settings[] = include_once( 'includes/class-wcj-currencies.php' );
269
  $settings[] = include_once( 'includes/class-wcj-currency-external-products.php' );
270
  $settings[] = include_once( 'includes/class-wcj-price-by-country.php' );
271
+
272
  $settings[] = include_once( 'includes/class-wcj-general.php' );
273
+ $settings[] = include_once( 'includes/class-wcj-old-slugs.php' );
274
  $settings[] = include_once( 'includes/class-wcj-reports.php' );
275
+ $settings[] = include_once( 'includes/class-wcj-admin-tools.php' );
276
+
277
  //include_once( 'includes/class-wcj-shortcodes.php' );
278
+
279
  // Add options
280
  if ( is_admin() ) {
281
  foreach ( $settings as $section ) {
285
  add_option( $value['id'], $value['default'], '', ( $autoload ? 'yes' : 'no' ) );
286
  }
287
  }
288
+ }
289
  }
290
  }
291
 
292
  /**
293
  * Add Jetpack settings tab to WooCommerce settings.
294
+ */
295
+ public function add_wcj_settings_tab( $settings ) {
296
+ $settings[] = include( 'includes/admin/settings/class-wc-settings-jetpack.php' );
297
  return $settings;
298
  }
299
 
302
  */
303
  public function init() {
304
  // Before init action
305
+ do_action( 'before_wcj_init' );
306
  // Set up localisation
307
+ load_plugin_textdomain( 'woocommerce-jetpack', false, dirname( plugin_basename( __FILE__ ) ) . '/langs/' );
308
  // Init action
309
  do_action( 'wcj_init' );
310
  }
311
+
312
+ /**
313
+ * Get the plugin url.
314
+ *
315
+ * @return string
316
+ */
317
+ public function plugin_url() {
318
+ return untrailingslashit( plugin_dir_url( __FILE__ ) );
319
+ }
320
+
321
+ /**
322
+ * Get the plugin path.
323
+ *
324
+ * @return string
325
+ */
326
+ public function plugin_path() {
327
+ return untrailingslashit( plugin_dir_path( __FILE__ ) );
328
+ }
329
  }
330
 
331
  endif;