├── .gitignore
├── LICENSE
├── README.md
├── faktury-online
└── index.php
├── ga-enhanced-ecommerce-order
├── README.md
└── ga-enhanced-ecommerce-order.php
├── ikros_order
├── README
└── ikros_order.php
├── import-tradegecko-stock
├── README.md
├── config.php
└── import-stock.php
├── import
├── virtuemart-attributes.php
└── virtuemart-products.php
├── mu-plugins
├── README.md
├── error-reporting.php
└── smtp.php
├── sync-woocommerce-stock
├── README.md
└── sync-woocommerce-stock.php
├── vubpay
├── README.txt
├── admin
│ ├── class-vubpay-admin.php
│ └── views
│ │ ├── generate_button.php
│ │ ├── index.php
│ │ └── settings.php
├── class-vubpay.php
├── inc
│ └── index.php
├── index.php
├── languages
│ ├── index.php
│ └── vubpay.pot
├── uninstall.php
└── vubpay.php
├── woocommerce-api-test
├── README.md
├── class-wc-api-client.php
└── index.php
├── woocommerce-attribute-import
├── README
└── woocommerce-attribute-import.php
├── woocommerce-custom-order
└── woocommerce-custom-order.php
├── woocommerce-email-attachment
├── README.md
├── admin
│ ├── assets
│ │ └── js
│ │ │ └── admin.js
│ ├── class-woocommerce-email-attachment-admin.php
│ └── views
│ │ └── admin.php
├── index.php
├── phpcs.xml
├── public
│ └── class-woocommerce-email-attachment.php
├── screenshot.png
├── uninstall.php
└── woocommerce-email-attachment.php
├── woocommerce-import-categories
├── index.php
└── test.csv
├── woocommerce-import-products-from-xml
├── README.md
└── index.php
├── woocommerce-migrate-products
├── .gitignore
├── README.md
├── composer.json
├── screenshot.jpg
├── wc-api-settings.png
└── woocommerce-migrate-products.php
├── woocommerce-no-cod-for-virtual
└── woocommerce-no-cod-for-virtual.php
├── woocommerce-optional-advance-pay
├── OptionalAdvancePay.php
├── README.md
└── woocommerce-optional-advance-pay.php
└── woocommerce-upsells-after-addtocart
├── README.md
├── index.php
└── screenshot.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | .htaccess
2 | wp-content/uploads/
3 | wp-content/blogs.dir/
4 | wp-content/upgrade/
5 | wp-content/backup-db/
6 | wp-content/advanced-cache.php
7 | wp-content/wp-cache-config.php
8 | sitemap.xml
9 | *.log
10 | wp-content/cache/
11 | wp-content/backups/
12 | sitemap.xml.gz
13 | wp-config.php
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | WordPress plugins, workarounds and code snippets
2 | =========
3 |
4 | Code that I sometimes need to re-use.
5 |
--------------------------------------------------------------------------------
/faktury-online/index.php:
--------------------------------------------------------------------------------
1 | https://www.faktury-online.com/faktury
5 | * Version: 1.0.0
6 | * Author: Michal Zuber
7 | * Author URI: http://www.nevilleweb.sk.
8 | */
9 | if (!defined('ABSPATH')) {
10 | exit; // Exit if accessed directly
11 | }
12 |
13 | class FakturyOnlineSendOrder
14 | {
15 | const API_URL = 'https://www.faktury-online.com/api/nf';
16 | const API_EMAIL = 'info@example.com';
17 | const API_TOKEN = 'API_KEY';
18 | const API_FIRM_ID = 0;
19 | const IS_TEST = 0; // 0 for prod, 1 for test
20 | const CURRENCY = 'EUR';
21 | const VAT_RATE = 20;
22 |
23 | /**
24 | * Init API email and token.
25 | */
26 | public function __construct()
27 | {
28 | add_action('woocommerce_checkout_order_processed', array($this, 'sendOrder'), 10, 2);
29 | }
30 |
31 | /**
32 | * Upload order
33 | * https://www.faktury-online.com/faktury-online-api/manual.
34 | *
35 | * @param int $orderId Order ID
36 | * @param array $customerData Customer data
37 | *
38 | * @return bool
39 | **/
40 | public function sendOrder($orderId, $customerData)
41 | {
42 | $data = $this->_prepateData($orderId, $customerData);
43 | $url = sprintf(
44 | '%s?data=%s',
45 | self::API_URL,
46 | urlencode($data)
47 | );
48 | $output = file_get_contents($url);
49 | $result = json_decode($output, true);
50 | $wcOrder = new WC_Order($orderId);
51 |
52 | if ($result['status'] == 1) {
53 | $wcOrder->add_order_note(
54 | sprintf(
55 | 'Sent to %s',
56 | 'https://www.faktury-online.com/faktury/detail?f=',
57 | $result['code'],
58 | 'https://www.faktury-online.com/faktury'
59 | ),
60 | false,
61 | true
62 | );
63 |
64 | return true;
65 | }
66 |
67 | $wcOrder->add_order_note(
68 | sprintf(
69 | 'Send to https://www.faktury-online.com/faktury failed: %s',
70 | $result['status']
71 | ),
72 | false,
73 | true
74 | );
75 |
76 | return false;
77 | }
78 |
79 | /**
80 | * Prepare data into JSON format.
81 | *
82 | * @param int $orderId Order ID
83 | * @param array $customer Customer data
84 | *
85 | * @return string
86 | **/
87 | private function _prepateData($orderId, $customer)
88 | {
89 | $data = array(
90 | 'test' => self::IS_TEST,
91 | 'key' => self::API_TOKEN,
92 | 'email' => self::API_EMAIL,
93 | 'd' => array('d_id' => self::API_FIRM_ID),
94 | );
95 |
96 | $data['o'] = array(
97 | 'o_name' => "{$customer['billing_first_name']} {$customer['billing_last_name']}",
98 | 'o_street' => $customer['billing_address_1'],
99 | 'o_city' => $customer['billing_city'],
100 | 'o_zip' => $customer['billing_postcode'],
101 | 'o_state' => $customer['billing_country'],
102 | 'o_email' => $customer['billing_email'],
103 | 'closingText' => $customer['order_comments'],
104 | );
105 |
106 | switch ($customer['payment_method']) {
107 | case 'bacs':
108 | $paymentType = 'prevod';
109 | break;
110 | default:
111 | $paymentType = 'dobierka';
112 | }
113 |
114 | $data['f'] = array(
115 | 'f_vs' => $orderId,
116 | 'f_ks' => '0308',
117 | 'f_date_issue' => date('Y-m-d'),
118 | 'f_date_delivery' => date('Y-m-d'),
119 | 'f_date_due' => date('Y-m-d', strtotime('+2 weeks')),
120 | 'f_payment' => $paymentType,
121 | 'f_proforma' => 0,
122 | 'f_currency' => self::CURRENCY,
123 | );
124 |
125 | foreach (WC()->cart->cart_contents as $item) {
126 | $data['p'][] = array(
127 | 'p_text' => __($item['data']->post->post_title),
128 | 'p_quantity' => $item['quantity'],
129 | 'p_unit' => 'ks',
130 | 'p_vat' => self::VAT_RATE,
131 | 'p_price' => $item['line_total'],
132 | );
133 | }
134 |
135 | return json_encode($data);
136 | }
137 | }
138 |
139 | new FakturyOnlineSendOrder();
140 |
--------------------------------------------------------------------------------
/ga-enhanced-ecommerce-order/README.md:
--------------------------------------------------------------------------------
1 | Google Analytics WooCommerce order tracking via Enhanced Ecommerce
2 | =========
3 |
4 | The plugin only sends order data from the thank you page of WooCommerce.
5 |
6 |
--------------------------------------------------------------------------------
/ga-enhanced-ecommerce-order/ga-enhanced-ecommerce-order.php:
--------------------------------------------------------------------------------
1 | $order_id ) {
34 | return;
35 | }
36 |
37 | $this->order_id = $order_id;
38 | $this->order = new WC_Order( $order_id );
39 |
40 | $this->setProducts();
41 | }
42 |
43 | public function outputJavascript()
44 | {
45 |
46 | echo sprintf('',
54 | $this->getTransactionJs(),
55 | $this->getProductJs()
56 | );
57 | }
58 |
59 | private function getProductJs() {
60 | $jsProducts = '';
61 | foreach ($this->products as $product) {
62 | $jsProducts .= "
63 | ga('ecommerce:addItem', {
64 | 'id': '$this->order_id',
65 | 'name': '{$product['name']}',
66 | 'sku': '{$product['sku']}',
67 | 'price': '{$product['price']}',
68 | 'quantity': '{$product['quantity']}'
69 | });
70 | ";
71 | }
72 |
73 | return $jsProducts;
74 | }
75 |
76 | private function getTransactionJs() {
77 | return "
78 | ga('ecommerce:addTransaction', {
79 | 'id': '{$this->order_id}',
80 | 'revenue': '".$this->order->get_total()."',
81 | 'shipping': '".$this->order->get_total_shipping()."',
82 | });
83 | ";
84 | }
85 |
86 | private function setProducts() {
87 | foreach ( $this->order->get_items() as $item ) {
88 | if (empty($item['name'])) {
89 | continue;
90 | }
91 |
92 | $this->products[] = array(
93 | 'sku' => $item['product_id'],
94 | 'name' => $item['name'],
95 | 'price' => $item['line_total'],
96 | 'quantity' => $item['qty'],
97 | );
98 | }
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/ikros_order/README:
--------------------------------------------------------------------------------
1 | Just a fast dirty wordpress plugin to test WooCommerce order upload to iKros.sk
2 |
--------------------------------------------------------------------------------
/ikros_order/ikros_order.php:
--------------------------------------------------------------------------------
1 | api_email = 'IKROS_EMAIL';
23 | $this->api_token = 'IKROS_TOKEN';
24 | }
25 |
26 | /**
27 | * Upload order data to ikros.sk
28 | *
29 | * @return bool
30 | **/
31 | public function upload_to_ikros($order_id, $customerdata)
32 | {
33 | /**
34 | * From exapmle at
35 | * http://docs.ikros.apiary.io/#reference/podporovane-webove-sluzby/objednavky/priklad-objednavky-kod-a-online-demo
36 | **/
37 | $ch = curl_init();
38 |
39 | curl_setopt($ch, CURLOPT_URL, "https://app.ikros.sk/public/api/v1/incomingorders/");
40 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
41 | curl_setopt($ch, CURLOPT_HEADER, FALSE);
42 |
43 | curl_setopt($ch, CURLOPT_POST, TRUE);
44 | curl_setopt($ch, CURLOPT_POSTFIELDS, $this->prepateData($order_id, $customerdata));
45 |
46 | curl_setopt($ch, CURLOPT_HTTPHEADER, array(
47 | "Content-Type: application/json",
48 | "X-ESHOP-TOKEN: {$this->api_token}",
49 | "X-ESHOP-EMAIL: {$this->api_email}"
50 | ));
51 |
52 | $response = curl_exec($ch);
53 | curl_close($ch);
54 | }
55 |
56 | /**
57 | * Prepare data into JSON format
58 | *
59 | * @return string
60 | **/
61 | private function prepateData($order_id, $customer)
62 | {
63 | switch ($customer['payment_method']) {
64 | default:
65 | $paymentType = 'bankový prevod';
66 | }
67 |
68 | switch ($customer['shipping_method'][0]) {
69 | default:
70 | $deliveryType = 'dobierka';
71 | }
72 |
73 | $data = array(
74 | 'documentNumber' => "$order_id",
75 | 'createDate' => date('c'),
76 | 'completionDate' => date('c'),
77 | 'clientName' => $customer['billing_company'],
78 | 'clientContact' => "{$customer['billing_first_name']} {$customer['billing_last_name']}",
79 | 'clientStreet' => $customer['billing_address_1'],
80 | 'clientPostCode' => $customer['billing_postcode'],
81 | 'clientTown' => $customer['billing_city'],
82 | 'clientCountry' => $customer['billing_country'],
83 | // 'clientRegistrationId' => $customer['registration_id'],
84 | // 'clientTaxId' => $customer['tax_id'],
85 | // 'clientVatId' => $customer['vat_id'],
86 | // 'clientInternalId' => 0,
87 | 'variableSymbol' => $order_id,
88 | 'openingText' => '',
89 | 'closingText' => $customer['order_comments'],
90 | 'senderName' => 'SENDER_NAME',
91 | 'senderRegistrationId' => 123456,
92 | 'senderRegistrationCourt' => 'Zapísaný v živnostenskom registri OÚ KN, č. 123-12345',
93 | 'senderVatId' => '',
94 | 'senderTaxId' => 123456,
95 | 'senderStreet' => 'STREET',
96 | 'senderPostCode' => 99999,
97 | 'senderTown' => 'CITY',
98 | 'senderRegion' => '',
99 | 'senderCountry' => 'Slovensko',
100 | 'senderBankAccount' => '',
101 | 'senderBankIban' => '',
102 | 'senderBankSwift' => '',
103 | 'paymentType' => $paymentType,
104 | 'deliveryType' => $deliveryType,
105 | 'senderContactName' => 'CONTACTNAME',
106 | 'senderPhone' => '0912 123 123',
107 | 'senderEmail' => ' info@example.com',
108 | 'senderWeb' => 'http://www.example.com/',
109 | 'clientPostalName' => @$customer['shipping_company'],
110 | 'clientPostalContact' => @$customer['shipping_first_name'].' '.@$customer['shipping_last_name'],
111 | 'clientPostalStreet' => @$customer['shipping_address_1'],
112 | 'clientPostalPostCode' => @$customer['shipping_postcode'],
113 | 'clientPostalTown' => @$customer['shipping_city'],
114 | 'clientPostalCountry' => @$customer['shipping_country'],
115 | 'clientHasDifferentPostalAddress' => $customer['ship_to_different_address'],
116 | 'currency' => 'EUR',
117 | 'exchangeRate' => 1,
118 | 'senderIsVatPayer' => 0,
119 | );
120 |
121 | foreach (WC()->cart->cart_contents as $item) {
122 | $data['items'][] = array(
123 | 'name' => $item['data']->post->post_title,
124 | 'description' => '',
125 | 'count' => $item['quantity'],
126 | 'measureType' => 'ks',
127 | 'total' => $item['line_total'],
128 | 'vat' => 20,
129 | 'hasDiscount' => 0,
130 | 'discountName' => '',
131 | 'discountPercent' => 0,
132 | 'discountTotal' => 0,
133 | 'productCode' => $item['product_id'],
134 | 'typeId' => 1, // product
135 | 'warehouseCode' => '',
136 | 'warehouseName' => '',
137 | 'foreignName' => '',
138 | 'customText' => '',
139 | 'ean' => '',
140 | 'jkpov' => '',
141 | 'plu' => 0,
142 | 'numberingSequenceCode' => '',
143 | );
144 | }
145 |
146 | return sprintf("[%s]", json_encode($data) );
147 | }
148 | }
149 |
150 |
--------------------------------------------------------------------------------
/import-tradegecko-stock/README.md:
--------------------------------------------------------------------------------
1 | ## Not a plugin
2 |
3 | Suitable for executing via browser or via wget cron
4 |
5 | ```
6 | http://example.com/import-tradegecko-stock/import-stock.php?all
7 | ```
8 |
9 | Import x days backwards with `days` param
10 | ```
11 | http://example.com/import-tradegecko-stock/import-stock.php?days=3
12 | ```
13 |
14 | Disable verbosity with `quiet` param
15 | ```
16 | http://example.com/import-tradegecko-stock/import-stock.php?days=3&quiet=1
17 | ```
18 |
--------------------------------------------------------------------------------
/import-tradegecko-stock/config.php:
--------------------------------------------------------------------------------
1 | wpdb = $wpdb;
21 | $this->logFile = __DIR__ . '/log/' . str_replace( '.php', '.log', basename( __FILE__ ) );
22 |
23 | $this->log( sprintf(
24 | 'Start %s from %s',
25 | date( 'c' ),
26 | $_SERVER['REMOTE_ADDR']
27 | ) );
28 |
29 | $this->importStock();
30 |
31 | $this->log( sprintf(
32 | 'Finish %s from %s',
33 | date( 'c' ),
34 | $_SERVER['REMOTE_ADDR']
35 | ) );
36 |
37 | if ( ! isset( $_GET['quiet'] ) ) {
38 | printf( "Log at %s ", $this->logFile );
39 | }
40 | }
41 |
42 | private function log( $data ) {
43 | if ( ! is_dir( __DIR__ . '/log' ) ) {
44 | mkdir( __DIR__ . '/log' );
45 | }
46 |
47 | // Monthly rotation
48 | if ( ! isset( $this->logPurged )
49 | && is_file( $this->logFile ) && date( 'm', filemtime( $this->logFile ) ) != date( 'm' )
50 | ) {
51 | $this->logPurged = true;
52 | unlink( $this->logFile );
53 | }
54 |
55 | file_put_contents( $this->logFile, $data . PHP_EOL, FILE_APPEND );
56 | }
57 |
58 | private function importStock() {
59 | $processed = 0;
60 | $paging = 1;
61 | $items = $this->getItemsFromTradeGecko( '/products', $paging ++ );
62 | while ( $items->meta->total != $processed ) {
63 | foreach ( $items->products as $product ) {
64 | $processed ++;
65 | $productId = $this->wpdb->get_results(
66 | $this->wpdb->prepare(
67 | "SELECT ID FROM {$this->wpdb->posts} WHERE post_title = %s AND post_type = 'product'",
68 | $product->name
69 | )
70 | );
71 | $productId = reset( $productId );
72 |
73 | if ( empty( $productId ) ) {
74 | continue;
75 | }
76 |
77 | if ( update_post_meta( $productId, '_stock', $product->quantity ) ) {
78 | $this->log( sprintf( 'Product %d (%s) to %d', $productId, get_permalink( $productId ), $product->quantity ) );
79 | }
80 | }
81 |
82 | $items = $this->getItemsFromTradeGecko( '/products', $paging ++ );
83 | }
84 |
85 | $processed = 0;
86 | $paging = 1;
87 | $items = $this->getItemsFromTradeGecko( '/variants', $paging ++ );
88 | while ( $items->meta->total != $processed ) {
89 | foreach ( $items->variants as $product ) {
90 | $processed ++;
91 | $post = $this->wpdb->get_results(
92 | $this->wpdb->prepare(
93 | "SELECT post_id, post_parent
94 | FROM {$this->wpdb->postmeta} pm
95 | LEFT JOIN {$this->wpdb->posts} p ON pm.post_id = p.ID
96 | WHERE meta_key = '_sku' AND meta_value = %s",
97 | $product->sku
98 | )
99 | );
100 | $post = reset( $post );
101 |
102 | if ( empty( $post->post_id ) ) {
103 | continue;
104 | }
105 |
106 | if ( update_post_meta( $post->post_id, '_stock', $product->available_stock ) ) {
107 | $this->log( sprintf(
108 | 'Variant %d (%s) to %d',
109 | $post->post_id,
110 | get_permalink( $post->post_parent !== 0 ? $post->post_parent : $post->post_id ),
111 | $product->available_stock
112 | ) );
113 | }
114 | }
115 |
116 | $items = $this->getItemsFromTradeGecko( '/variants', $paging ++ );
117 | }
118 | }
119 |
120 | private function getItemsFromTradeGecko( $path, $page = 1 ) {
121 | $url = sprintf(
122 | '%s%s?page=%d',
123 | TG_API_URL,
124 | $path,
125 | $page
126 | );
127 | if ( ! isset( $_GET['all'] ) ) {
128 | $days = $_GET['days'] ?? 1;
129 | $url .= sprintf( '&updated_at_min=%s', date( 'c', strtotime( "-$days days" ) ) );
130 | }
131 | if ( ! isset( $_GET['quiet'] ) ) {
132 | echo "$url ";
133 | }
134 |
135 | $ch = curl_init( $url );
136 | curl_setopt( $ch, CURLOPT_HTTPHEADER, [
137 | 'Content-Type: application/json',
138 | 'Authorization: Bearer ' . TG_PRIVILIGED_CODE,
139 | ] );
140 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
141 | curl_setopt( $ch, CURLOPT_HEADER, 1 );
142 | $response = curl_exec( $ch );
143 | if ( curl_errno( $ch ) ) {
144 | echo curl_error( $ch );
145 | }
146 | curl_close( $ch );
147 | list( $header, $body ) = explode( "\r\n\r\n", $response, 2 );
148 |
149 | $header = explode( "\n", $header );
150 | foreach ( $header as $row ) {
151 | if ( strpos( $row, 'X-Rate-Limit-Remaining' ) !== false ) {
152 | $error = sprintf(
153 | "Rate limit hit. Try after %s",
154 | date( 'H:i:s', time() + preg_replace( '/[^0-9]/', '', $row ) )
155 | );
156 | $this->log( $error );
157 | echo "$error ";
158 | exit;
159 | }
160 | }
161 |
162 | return json_decode( $body );
163 | }
164 | }
165 |
166 | return new ImportStock();
167 |
--------------------------------------------------------------------------------
/import/virtuemart-attributes.php:
--------------------------------------------------------------------------------
1 | wpdb = $wpdb;
27 | $this->import_product_attrib();
28 | }
29 |
30 | /**
31 | * Import product attributes
32 | *
33 | * @param void
34 | *
35 | * @return string
36 | **/
37 | public function import_product_attrib() {
38 | $prefix = self::$db_prefix;
39 | $virtuemart = new wpdb( self::$db_user, self::$db_pass, self::$db_name, self::$db_host );
40 |
41 | $offset = 0;
42 | $limit = 200;
43 | $imported = 0;
44 | $date_format = 'Y-m-d H:i:s';
45 | $started = date( $date_format );
46 | echo 'Started @ ' . $started . ' ';
47 | wp_ob_end_flush_all();
48 | flush();
49 |
50 | do {
51 | $products = [];
52 | $results = $virtuemart->get_results( "SELECT product_id FROM {$prefix}vm_product LIMIT {$offset}, {$limit}", 'ARRAY_A' );
53 | if ( empty( $results ) ) {
54 | continue;
55 | }
56 | foreach ( $results as $product ) {
57 | $products[ $product['product_id'] ] = $product['product_id'];
58 | }
59 | $in_products = implode( ',', $products );
60 | $sql = "SELECT product_sku, sezona as sezona, rychlostnindex as rychlostnyindex, sirka, vyska_profil as vyska, priemer_rafika as radius, fuel_saving as usporapaliva, wet, noise, mf_name as vyrobca
61 | FROM {$prefix}vm_product p
62 | LEFT JOIN {$prefix}vm_product_type_1 t ON p.product_id = t.product_id
63 | LEFT JOIN {$prefix}vm_product_mf_xref mf ON p.product_id = mf.product_id
64 | LEFT JOIN {$prefix}vm_manufacturer m ON m.manufacturer_id = mf.manufacturer_id
65 | WHERE p.product_id IN ({$in_products})
66 | ";
67 | $products = $virtuemart->get_results( $sql, 'ARRAY_A' );
68 |
69 | $attributes = [];
70 | foreach ( $products as $vm_attributes ) {
71 | $sql = "SELECT post_id FROM {$this->wpdb->postmeta} WHERE meta_key = '_sku' AND meta_value = %s";
72 | $post_id = $this->wpdb->get_var( $this->wpdb->prepare( $sql, $vm_attributes['product_sku'] ) );
73 | if ( empty( $post_id ) ) {
74 | continue;
75 | }
76 |
77 | // Unset key which won't be attribute
78 | unset( $vm_attributes['product_sku'] );
79 |
80 | $position = 0;
81 | foreach ( $vm_attributes as $meta_key => $meta_value ) {
82 | $meta_key = 'pa_' . $meta_key;
83 | $meta_value = trim( $meta_value );
84 |
85 | // Update post terms
86 | wp_set_object_terms( $post_id, $meta_value, $meta_key );
87 |
88 | // Prepare attributes
89 | // Src: /wp-content/plugins/woocommerce/includes/class-wc-ajax.php method save_attributes()
90 | $attributes[ $meta_key ] = [
91 | 'name' => $meta_key,
92 | 'value' => '',
93 | 'position' => $position ++,
94 | 'is_variation' => 0,
95 | 'is_visible' => 1,
96 | 'is_taxonomy' => 1,
97 | ];
98 | }
99 |
100 | update_post_meta( $post_id, '_product_attributes', $attributes );
101 |
102 | $imported ++;
103 | }
104 |
105 | $offset += $limit;
106 | printf( "Offset %d @ %s ", $offset, date( $date_format ) );
107 | wp_ob_end_flush_all();
108 | flush();
109 | } while ( ! empty( $products ) );
110 |
111 | $virtuemart->close();
112 |
113 | echo 'Imported: ' . $imported . ' products
114 | Finished @ ' . date( $date_format ) . ' ';
115 | }
116 | }
117 |
118 | return new ImportAttributesFromVirtuemart( $wpdb );
119 |
--------------------------------------------------------------------------------
/import/virtuemart-products.php:
--------------------------------------------------------------------------------
1 | query( 'SET NAMES utf8' );
15 | $execStart = time();
16 | $importCount = 0;
17 |
18 | echo date( 'H:i:s d.m.Y', $execStart ) . ' ';
19 |
20 | $sql = "SELECT p.product_id, product_sku, product_s_desc, product_desc, product_name, product_in_stock, product_full_image, product_price, cat.category_name
21 | FROM jos_vm_product p
22 | LEFT JOIN jos_vm_product_price pr ON p.product_id=pr.product_id
23 | LEFT JOIN jos_vm_product_category_xref pcref ON p.product_id=pcref.product_id
24 | LEFT JOIN jos_vm_category cat ON pcref.category_id=cat.category_id
25 | WHERE product_publish = 'Y'
26 | ";
27 | $res = $mysqli->query( $sql );
28 | while ( $row = $res->fetch_assoc() ) {
29 | if ( time() >= $execStart + 550 ) {
30 | echo 'Time limit reached ';
31 | return;
32 | }
33 |
34 | if ( empty( $row['category_name'] ) ) {
35 | echo "Empty category {$row['product_name']} ";
36 | continue;
37 | }
38 |
39 | if ( getProduct( $row['product_sku'] ) ) {
40 | continue;
41 | }
42 |
43 | $product = [
44 | 'post_author' => 3,
45 | 'post_title' => $row['product_name'],
46 | 'post_excerpt' => $row['product_s_desc'],
47 | 'post_content' => $row['product_desc'],
48 | 'post_status' => 'publish',
49 | 'post_type' => 'product',
50 | ];
51 | $product_id = wp_insert_post( $product );
52 |
53 | if ( 1 > $product_id ) {
54 | echo "Import of {$row['product_sku']} failed ";
55 | continue;
56 | }
57 |
58 | add_post_meta( $product_id, '_sku', $row['product_sku'] );
59 | add_post_meta( $product_id, '_price', $row['product_price'] );
60 | add_post_meta( $product_id, '_regular_price', $row['product_price'] );
61 | add_post_meta( $product_id, '_visibility', 'visible', true );
62 | add_post_meta( $product_id, '_downloadable', 'no' );
63 | add_post_meta( $product_id, '_virtual', 'no' );
64 | add_post_meta( $product_id, '_stock_status', 'instock' );
65 | add_post_meta( $product_id, '_manage_stock', 'yes' );
66 | add_post_meta( $product_id, '_stock', $row['product_in_stock'] );
67 |
68 | $category = wp_insert_term( $row['category_name'], 'product_cat' );
69 | if ( isset( $category->error_data['term_exists'] ) ) {
70 | $category_id = $category->error_data['term_exists'];
71 | } else {
72 | $category_id = $category['term_id'];
73 | }
74 |
75 | wp_set_object_terms( $product_id, [ $category_id ], 'product_cat' );
76 |
77 | $img_src = 'http://localhost/components/com_virtuemart/shop_image/product/' . $row['product_full_image'];
78 | saveImage( $product_id, $img_src, true );
79 |
80 | $importCount += 1;
81 | }
82 |
83 | echo "Imported $importCount ";
84 | echo date( 'Y-m-d H:i:s' );
85 |
86 | function getProduct( $sku ) {
87 | global $wpdb;
88 |
89 | $sql = 'SELECT post_id FROM ' . $wpdb->postmeta . "
90 | WHERE meta_key = '_sku' AND meta_value = '$sku' LIMIT 1";
91 | $product = $wpdb->get_results( $sql, ARRAY_A );
92 |
93 | return isset( $product[0]['post_id'] ) ? $product[0]['post_id'] : 0;
94 | }
95 |
96 | function saveImage( $product_id, $src, $main = false ) {
97 | if ( empty( $src ) ) {
98 | return;
99 | }
100 |
101 | $http_head = get_headers( $src );
102 | if ( stripos( $http_head[0], '200' ) === false ) {
103 | return;
104 | }
105 |
106 | $image_data = file_get_contents( $src );
107 | if ( empty( $image_data ) ) {
108 | return;
109 | }
110 |
111 | $upload_dir = wp_upload_dir();
112 | $filename = basename( $src );
113 | if ( wp_mkdir_p( $upload_dir['path'] . '/products' ) ) {
114 | $file = $upload_dir['path'] . '/products/' . $filename;
115 | }
116 | file_put_contents( $file, $image_data );
117 |
118 | $wp_filetype = wp_check_filetype( $filename, null );
119 | $attachment = [
120 | 'post_mime_type' => $wp_filetype['type'],
121 | 'post_title' => sanitize_file_name( $filename ),
122 | 'post_content' => '',
123 | 'post_status' => 'inherit',
124 | ];
125 | $attach_id = wp_insert_attachment( $attachment, $file, $product_id );
126 | $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
127 | wp_update_attachment_metadata( $attach_id, $attach_data );
128 |
129 | if ( $main ) {
130 | set_post_thumbnail( $product_id, $attach_id );
131 | }
132 |
133 | return $attach_id;
134 | }
135 |
--------------------------------------------------------------------------------
/mu-plugins/README.md:
--------------------------------------------------------------------------------
1 | # Helper mu-plugins
2 | For some frequently used modifications in projects.
3 |
4 | Helpful, fast and dirty :)
5 |
--------------------------------------------------------------------------------
/mu-plugins/error-reporting.php:
--------------------------------------------------------------------------------
1 | IsSMTP();
10 | $phpmailer->Host = 'smtp.example.sk';
11 | $phpmailer->SMTPDebug = 0;
12 | $phpmailer->SMTPAuth = true;
13 | $phpmailer->SMTPSecure = 'ssl';
14 | $phpmailer->Port = 465;
15 | $phpmailer->Username = 'php@example.sk';
16 | $phpmailer->Password = 'PassWordHere';
17 |
18 | return $phpmailer;
19 | }
20 |
--------------------------------------------------------------------------------
/sync-woocommerce-stock/README.md:
--------------------------------------------------------------------------------
1 |
2 | Sync WooCommerce products stock count on another WooCommerce site.
3 | For example to sync stock from example.sk into example.cz
4 |
5 | The script is designed to be called via Cron for specific intervals.
6 |
7 | To execute just call/visit
8 | http://example.sk/sync-woocommerce-stock/sync-woocommerce-stock.php
9 |
--------------------------------------------------------------------------------
/sync-woocommerce-stock/sync-woocommerce-stock.php:
--------------------------------------------------------------------------------
1 | query( 'SET NAMES utf8' );
17 |
18 | $sk_products = array();
19 | $q = "SELECT ID FROM {$table_prefix}posts WHERE post_type IN ('product', 'product_variation')";
20 | $q = $mysqli->query($q);
21 | while ( $post = $q->fetch_assoc() ) {
22 | $meta = array();
23 | $metaq = "SELECT * FROM {$table_prefix}postmeta WHERE post_id = {$post['ID']} AND meta_key IN ('_sku', '_stock')";
24 | $metaq = $mysqli->query($metaq);
25 | while ( $postmeta = $metaq->fetch_assoc() ) {
26 | $meta[$postmeta['meta_key']] = $postmeta['meta_value'];
27 | }
28 | $sk_products[$post['ID']] = $meta;
29 | }
30 | $mysqli->close();
31 |
32 | /**
33 | * Update stock on CZ
34 | **/
35 | $updated = 0;
36 | $table_prefix = 'wp_';
37 | if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('localhost'))) {
38 | $mysqli = new mysqli('localhost', 'root', '', 'cz_db_name');
39 | }
40 | else {
41 | $mysqli = new mysqli('localhost', 'root', 'pass', 'cz_db_name');
42 | }
43 | $mysqli->query( 'SET NAMES utf8' );
44 | foreach ($sk_products as $product) {
45 | if (empty($product['_stock'])) {
46 | continue;
47 | }
48 | if (empty($product['_sku'])) {
49 | continue;
50 | }
51 | $q = "SELECT ID FROM {$table_prefix}posts p
52 | LEFT JOIN {$table_prefix}postmeta pm ON p.ID = pm.post_id
53 | WHERE meta_key = '_sku' AND meta_value = '{$product['_sku']}' LIMIT 1";
54 | $post = $mysqli->query($q)->fetch_assoc();
55 |
56 | $q = "UPDATE {$table_prefix}postmeta SET meta_value = '{$product['_stock']}' WHERE meta_key = '_stock' AND post_id = '{$post['ID']}' LIMIT 1";
57 | $mysqli->query($q);
58 |
59 | $updated++;
60 | }
61 | $mysqli->close();
62 |
63 | echo "Updated: $updated items";
64 |
--------------------------------------------------------------------------------
/vubpay/README.txt:
--------------------------------------------------------------------------------
1 | === VUB eCard Payments ===
2 | Contributors: (this should be a list of wordpress.org userids)
3 | Tags: payment
4 | Requires at least: 3.9
5 | Tested up to: 3.9
6 | License: GPLv2 or later
7 | License URI: http://www.gnu.org/licenses/gpl-2.0.html
8 |
9 | Create, process and manage VUB eCard payments
10 |
11 | == Description ==
12 |
13 | Create, process and manage VUB eCard payments for http://polymer.sav.sk
14 |
15 | == Installation ==
16 |
17 | = Using FTP =
18 |
19 | 1. Download `vubpay.zip`
20 | 2. Extract the `vubpay` directory to your computer
21 | 3. Upload the `vubpay` directory to the `/wp-content/plugins/` directory
22 | 4. Activate the plugin in the Plugin dashboard
23 |
24 |
--------------------------------------------------------------------------------
/vubpay/admin/class-vubpay-admin.php:
--------------------------------------------------------------------------------
1 |
5 | * @license GPL-2.0+
6 | * @link http://nevilleweb.sk
7 | * @copyright 2014 Michal Zuber
8 | */
9 |
10 | /**
11 | * Plugin class. This class should ideally be used to work with the
12 | * administrative side of the WordPress site.
13 | *
14 | */
15 | if ( ! class_exists( 'Vubpay_Admin' ) ) :
16 |
17 | class Vubpay_Admin {
18 |
19 | /**
20 | * Instance of this class.
21 | *
22 | * @since 1.0.0
23 | *
24 | * @var object
25 | */
26 | protected static $instance = null;
27 |
28 | /**
29 | * Slug of the plugin screen.
30 | *
31 | * @since 1.0.0
32 | *
33 | * @var string
34 | */
35 | protected $plugin_screen_hook_suffix = null;
36 |
37 | /**
38 | * Initialize the plugin by loading admin scripts & styles and adding a
39 | * settings page and menu.
40 | *
41 | * @since 1.0.0
42 | */
43 | private function __construct() {
44 |
45 | $plugin = Vubpay::get_instance();
46 | $this->plugin_slug = $plugin->get_plugin_slug();
47 |
48 | add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
49 |
50 | // Add a plugin page action link pointing to the settings page.
51 | $plugin_basename = plugin_basename( plugin_dir_path( realpath( dirname( __FILE__ ) ) ) . $this->plugin_slug . '.php' );
52 | add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
53 |
54 | // Change listing
55 | add_filter( 'manage_'.$this->plugin_slug.'_posts_columns', array( $this, 'listing_head' ));
56 | add_action( 'manage_'.$this->plugin_slug.'_posts_custom_column', array( $this, 'listing_content' ), 10, 2 );
57 |
58 | }
59 |
60 | /**
61 | * Return an instance of this class.
62 | *
63 | * @since 1.0.0
64 | *
65 | * @return object A single instance of this class.
66 | */
67 | public static function get_instance() {
68 |
69 | // If the single instance hasn't been set, set it now.
70 | if ( null == self::$instance ) {
71 | self::$instance = new self;
72 | }
73 |
74 | return self::$instance;
75 | }
76 |
77 | /**
78 | * Change listing table header columns
79 | *
80 | * @param array $defaults
81 | *
82 | * @return array
83 | **/
84 | function listing_head( $defaults ) {
85 |
86 | $defaults = array(
87 | 'cb' => '',
88 | 'title' => __( 'Title', $this->plugin_slug),
89 | 'status' => __( 'Status', $this->plugin_slug),
90 | 'amount' => __( 'Amount', $this->plugin_slug),
91 | 'author' => __( 'Author', $this->plugin_slug),
92 | 'date' => __( 'Date', $this->plugin_slug),
93 | );
94 |
95 | return $defaults;
96 | }
97 |
98 | /**
99 | * Change listing table content columns
100 | *
101 | * @param string $column_name
102 | * @param integer $post_id
103 | *
104 | * @return array
105 | **/
106 | function listing_content( $column_name, $post_id ) {
107 |
108 | switch ( $column_name ) {
109 | case 'status':
110 | $terms = wp_get_object_terms( $post_id, 'status' );
111 | echo $terms[0]->name;
112 | break;
113 |
114 | case 'amount':
115 | echo get_post_meta( $post_id, 'amount', true );
116 | break;
117 |
118 | }
119 |
120 | }
121 |
122 | /**
123 | * Register the administration menu for this plugin into the WordPress Dashboard menu.
124 | *
125 | * @since 1.0.0
126 | */
127 | public function add_plugin_admin_menu() {
128 |
129 | /*
130 | * Add a settings page for this plugin to the custom post type menu.
131 | *
132 | * NOTE: Alternative menu locations are available via WordPress administration menu functions.
133 | *
134 | * Administration Menus: http://codex.wordpress.org/Administration_Menus
135 | *
136 | * For reference: http://codex.wordpress.org/Roles_and_Capabilities
137 | */
138 | $this->plugin_screen_hook_suffix = add_submenu_page(
139 | "edit.php?post_type=$this->plugin_slug",
140 | __( 'VÚB eCard payments settings', $this->plugin_slug ),
141 | __( 'Settings', $this->plugin_slug ),
142 | 'manage_options',
143 | "settings",
144 | array( $this, 'display_plugin_settings' )
145 | );
146 |
147 | add_submenu_page(
148 | "edit.php?post_type=$this->plugin_slug",
149 | __( 'Generate VÚB eCard payment button', $this->plugin_slug ),
150 | __( 'Generate button', $this->plugin_slug ),
151 | 'manage_options',
152 | "generate_button",
153 | array( $this, 'display_generate_button_subpage' )
154 | );
155 |
156 | add_action( 'admin_menu', array( $this, 'remove_add_submenu' ), 999 );
157 | add_action( 'admin_head', array( $this, 'remove_add_new_btn' ), 999 );
158 |
159 | }
160 |
161 | /**
162 | * Remove Add new menu link from admin
163 | *
164 | * @since 1.0.0
165 | */
166 | public function remove_add_submenu() {
167 | remove_submenu_page( "edit.php?post_type=$this->plugin_slug", "post-new.php?post_type=$this->plugin_slug" );
168 | }
169 |
170 | /**
171 | * Remove Add new button link from All payments admin page
172 | *
173 | * @since 1.0.0
174 | */
175 | public function remove_add_new_btn() {
176 | if ( $this->plugin_slug == get_post_type() ) {
177 | echo '';
182 | }
183 | }
184 |
185 | /**
186 | * Render the settings page for this plugin.
187 | *
188 | * @since 1.0.0
189 | */
190 | public function display_plugin_settings() {
191 |
192 | if ( isset( $_POST['submit'] ) ) {
193 |
194 | if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], $this->plugin_slug . '-options' ) )
195 | die( __( '