├── .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( __( '

Action failed. Please go back and retry.

', $this->plugin_slug ) ); 196 | 197 | $whitelist_options = array( 198 | 'client_id', 199 | 'store_key', 200 | 'gateway_url', 201 | 'ok_url', 202 | 'fail_url', 203 | ); 204 | 205 | foreach ( $whitelist_options as $option ) { 206 | $option = "{$this->plugin_slug}_" . trim( $option ); 207 | $value = null; 208 | if ( isset( $_POST[ $option ] ) ) 209 | $value = wp_unslash( trim( $_POST[ $option ] ) ); 210 | 211 | update_option( $option, $value ); 212 | } 213 | 214 | /** 215 | * Handle settings errors and return to options page 216 | */ 217 | // If no settings errors were registered add a general 'updated' message. 218 | if ( !count( get_settings_errors() ) ) 219 | add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); 220 | set_transient('settings_errors', get_settings_errors(), 30); 221 | 222 | /** 223 | * Redirect back to the settings page that was submitted 224 | */ 225 | $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); 226 | die( __( '

Settings successfully updated.

', $this->plugin_slug ) ); 227 | } 228 | 229 | include_once( 'views/settings.php' ); 230 | } 231 | 232 | /** 233 | * Add settings action link to the plugins page. 234 | * 235 | * @since 1.0.0 236 | */ 237 | public function add_action_links( $links ) { 238 | 239 | return array_merge( 240 | array( 241 | 'settings' => 'plugin_slug&page=settings" ) . '">' . __( 'Settings', $this->plugin_slug ) . '' 242 | ), 243 | $links 244 | ); 245 | 246 | } 247 | 248 | /** 249 | * Render the generate button subpage 250 | * 251 | * @since 1.0.0 252 | */ 253 | public function display_generate_button_subpage() { 254 | 255 | $html_btn = $this->create_html_button(); 256 | if ( isset( $_POST['submit'] ) ) { 257 | 258 | if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], $this->plugin_slug . '-options' ) ) 259 | die( __( '

Action failed. Please go back and retry.

', $this->plugin_slug ) ); 260 | 261 | $html_btn = $this->create_html_button(); 262 | 263 | } 264 | 265 | include_once( 'views/generate_button.php' ); 266 | } 267 | 268 | /** 269 | * Create HTML payment button 270 | * 271 | */ 272 | public function create_html_button() { 273 | 274 | $currency = ! empty( $_POST['btn_currency'] ) ? intval( $_POST['btn_currency'] ) : ''; 275 | $amount = ! empty( $_POST['btn_amount'] ) ? intval( $_POST['btn_amount'] ) : ''; 276 | $lang = ! empty( $_POST['btn_lang'] ) ? esc_html( $_POST['btn_lang'] ) : ''; 277 | $description = ! empty( $_POST['btn_description'] ) ? esc_html( $_POST['btn_description'] ) : ''; 278 | $btn_text = ! empty( $_POST['btn_text'] ) ? esc_html( $_POST['btn_text'] ) : ''; 279 | 280 | $input_data = array( 281 | 'amount' => $amount, 282 | 'currency' => $currency, 283 | 'description' => $description, 284 | 'lang' => $lang, 285 | ); 286 | 287 | $inputs = array(); 288 | foreach ($input_data as $k => $v) { 289 | $inputs[] = "\t".'<input type="hidden" name="'.$k.'" value="'.esc_attr( $v ).'" />'; 290 | } 291 | 292 | return ' 293 | <form name="btn-vubecard" id="btn-vubecard" class="btn-vubecard" action="'.site_url().'/?action=request" method="post"> 294 | ' . implode("\n", $inputs) . ' 295 | '."\t".'<button type="submit">' . $btn_text . '</button> 296 | </form>'; 297 | 298 | } 299 | 300 | } 301 | 302 | endif; 303 | 304 | -------------------------------------------------------------------------------- /vubpay/admin/views/generate_button.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link http://nevilleweb.sk 9 | * @copyright 2014 Michal Zuber 10 | */ 11 | 12 | $btn_lang_arr = array( 13 | 'en' => __( 'English', $this->plugin_slug ), 14 | 'hu' => __( 'Magyar', $this->plugin_slug ), 15 | 'sk' => __( 'Slovenčina', $this->plugin_slug ), 16 | 'cz' => __( 'Čeština', $this->plugin_slug ), 17 | ); 18 | $btn_lang_opts = ''; 19 | foreach ( $btn_lang_arr as $id => $title ) { 20 | $selected = isset($_POST['btn_lang']) && $_POST['btn_lang'] == $id ? ' selected="selected"' : ''; 21 | $btn_lang_opts .= ''; 22 | } 23 | 24 | $btn_currency_arr = array( 25 | 978 => 'EUR', 26 | 203 => 'CZK', 27 | 348 => 'HUF', 28 | 985 => 'PLN', 29 | ); 30 | $btn_currency_opts = ''; 31 | foreach ( $btn_currency_arr as $id => $title ) { 32 | $selected = isset($_POST['btn_currency']) && $_POST['btn_currency'] == $id ? ' selected="selected"' : ''; 33 | $btn_currency_opts .= ''; 34 | } 35 | ?> 36 | 37 |
38 | 39 |

40 |
plugin_slug}&page=generate_button" ); ?>" method="post"> 41 | plugin_slug ); ?> 42 | 43 | 44 | 45 | 46 | 47 | 53 | 54 | 55 | 56 | 59 | 60 | 61 | 62 | 68 | 69 | 70 | 71 | 74 | 75 | 76 | 77 | 80 | 81 | 82 |
48 | 52 |
57 | 58 |
63 | 67 |
72 | 73 |
78 | 79 |
83 | 84 |

85 |
86 | 87 |

plugin_slug ); ?>

88 |
89 | 
90 | 	
91 |
92 | 93 | -------------------------------------------------------------------------------- /vubpay/admin/views/index.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link http://nevilleweb.sk 9 | * @copyright 2014 Michal Zuber 10 | */ 11 | ?> 12 | 13 |
14 | 15 |

16 |
plugin_slug}&page=settings" ); ?>" method="post"> 17 | plugin_slug ); ?> 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 48 | 49 | 50 | 51 | 56 | 57 | 58 |
23 | 24 |

plugin_slug ); ?>

25 |
30 | 31 |

https://testsecurepay.intesasanpaolocard.com/vub/report/admin.3D.securityKey?opr=key or for production at https://vub.eway2pay.com/vub/report/user.login', $this->plugin_slug ); ?>

32 |
37 | 38 |

https://vub.eway2pay.com/fim/est3dgate', $this->plugin_slug ); ?>

39 |
44 | 45 | 46 |

plugin_slug ); ?>

47 |
52 | 53 | 54 |

plugin_slug ); ?>

55 |
59 |

60 |
61 |
62 | 63 | -------------------------------------------------------------------------------- /vubpay/class-vubpay.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 | * public-facing side of the WordPress site. 13 | * 14 | */ 15 | if ( ! class_exists( 'Vubpay' ) ) : 16 | 17 | class Vubpay { 18 | 19 | /** 20 | * Plugin version, used for cache-busting of style and script file references. 21 | * 22 | * @since 1.0.0 23 | * 24 | * @var string 25 | */ 26 | const VERSION = '1.0.0'; 27 | 28 | /** 29 | * 30 | * Unique identifier for your plugin. 31 | * 32 | * 33 | * The variable name is used as the text domain when internationalizing strings 34 | * of text. Its value should match the Text Domain file header in the main 35 | * plugin file. 36 | * 37 | * @since 1.0.0 38 | * 39 | * @var string 40 | */ 41 | protected $plugin_slug = 'vubpay'; 42 | 43 | /** 44 | * Instance of this class. 45 | * 46 | * @since 1.0.0 47 | * 48 | * @var object 49 | */ 50 | protected static $instance = null; 51 | 52 | /** 53 | * Initialize the plugin by setting localization and loading public scripts 54 | * and styles. 55 | * 56 | * @since 1.0.0 57 | */ 58 | private function __construct() { 59 | 60 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 61 | add_action( 'init', array( $this, 'reg_cpt' ) ); 62 | 63 | if ( ! empty( $_GET['action'] ) && ! empty( $_POST['amount'] ) ) 64 | add_filter( 'the_content', array( $this, 'process_request' ) ); 65 | if ( ! empty( $_POST['Response'] ) && ! empty( $_POST['merchantID'] ) ) 66 | add_filter( 'the_content', array( $this, 'process_response' ) ); 67 | 68 | } 69 | 70 | /** 71 | * Return the plugin slug. 72 | * 73 | * @since 1.0.0 74 | * 75 | * @return Plugin slug variable. 76 | */ 77 | public function get_plugin_slug() { 78 | return $this->plugin_slug; 79 | } 80 | 81 | /** 82 | * Return an instance of this class. 83 | * 84 | * @since 1.0.0 85 | * 86 | * @return object A single instance of this class. 87 | */ 88 | public static function get_instance() { 89 | 90 | // If the single instance hasn't been set, set it now. 91 | if ( null == self::$instance ) { 92 | self::$instance = new self; 93 | } 94 | 95 | return self::$instance; 96 | } 97 | 98 | /** 99 | * Register custom post type and taxonomy 100 | * 101 | * @return void 102 | */ 103 | public function reg_cpt() { 104 | 105 | $labels = array( 106 | 'name' => _x( 'VÚB eCard Payments', 'post type general name', $this->plugin_slug ), 107 | 'singular_name' => _x( 'VÚB eCard Payment', 'post type singular name', $this->plugin_slug ), 108 | 'menu_name' => _x( 'VÚB eCard Payments', 'admin menu', $this->plugin_slug ), 109 | 'name_admin_bar' => _x( 'VÚB eCard Payment', 'add new on admin bar', $this->plugin_slug ), 110 | 'add_new' => _x( 'Add New', 'payment', $this->plugin_slug ), 111 | 'add_new_item' => __( 'Add New Payment', $this->plugin_slug ), 112 | 'new_item' => __( 'New Payment', $this->plugin_slug ), 113 | 'edit_item' => __( 'Edit Payment', $this->plugin_slug ), 114 | 'view_item' => __( 'View Payment', $this->plugin_slug ), 115 | 'all_items' => __( 'All Payments', $this->plugin_slug ), 116 | 'search_items' => __( 'Search Payments', $this->plugin_slug ), 117 | 'parent_item_colon' => __( 'Parent Payments:', $this->plugin_slug ), 118 | 'not_found' => __( 'No payments found.', $this->plugin_slug ), 119 | 'not_found_in_trash' => __( 'No payments found in Trash.', $this->plugin_slug ) 120 | ); 121 | 122 | $args = array( 123 | 'labels' => $labels, 124 | 'public' => true, 125 | 'publicly_queryable' => true, 126 | 'show_ui' => true, 127 | 'show_in_menu' => true, 128 | 'query_var' => true, 129 | 'rewrite' => array( 'slug' => $this->plugin_slug ), 130 | 'capability_type' => 'post', 131 | 'capabilities' => array( 'create_posts' => false ), 132 | 'map_meta_cap' => false, // Disable Edit/Delete 133 | 'has_archive' => true, 134 | 'hierarchical' => false, 135 | 'menu_position' => null, 136 | 'supports' => array( 'title', 'editor', 'author', 'excerpt', 'comments' ) 137 | ); 138 | register_post_type( $this->plugin_slug, $args ); 139 | 140 | $labels = array( 141 | 'name' => _x( 'Statuses', 'taxonomy general name' ), 142 | 'singular_name' => _x( 'Status', 'taxonomy singular name' ), 143 | 'search_items' => __( 'Search Statuses' ), 144 | 'popular_items' => __( 'Popular Statuses' ), 145 | 'all_items' => __( 'All Statuses' ), 146 | 'parent_item' => null, 147 | 'parent_item_colon' => null, 148 | 'edit_item' => __( 'Edit Status' ), 149 | 'update_item' => __( 'Update Status' ), 150 | 'add_new_item' => __( 'Add New Status' ), 151 | 'new_item_name' => __( 'New Status Name' ), 152 | 'separate_items_with_commas' => __( 'Separate writers with commas' ), 153 | 'add_or_remove_items' => __( 'Add or remove writers' ), 154 | 'choose_from_most_used' => __( 'Choose from the most used writers' ), 155 | 'not_found' => __( 'No writers found.' ), 156 | 'menu_name' => __( 'Statuses' ), 157 | ); 158 | 159 | $args = array( 160 | 'hierarchical' => false, 161 | 'labels' => $labels, 162 | 'show_ui' => true, 163 | 'show_admin_column' => false, 164 | 'update_count_callback' => '_update_post_term_count', 165 | 'query_var' => true, 166 | 'rewrite' => array( 'slug' => 'status' ), 167 | ); 168 | register_taxonomy( 'status', $this->plugin_slug, $args ); 169 | 170 | $statuses = array( 171 | 'pending' => 'Pending payments status', 172 | 'failed' => 'Failed payments status', 173 | 'aborted' => 'Aborted payments status', 174 | 'success' => 'Successful payments status', 175 | ); 176 | foreach ( $statuses as $status => $description ) { 177 | wp_insert_term( 178 | ucfirst( $status ), 179 | 'status', 180 | array( 181 | 'description'=> $description, 182 | 'slug' => $status, 183 | ) 184 | ); 185 | } 186 | 187 | } 188 | 189 | /** 190 | * Fired when the plugin is activated. 191 | * 192 | * @since 1.0.0 193 | * 194 | * @param boolean $network_wide True if WPMU superadmin uses 195 | * "Network Activate" action, false if 196 | * WPMU is disabled or plugin is 197 | * activated on an individual blog. 198 | */ 199 | public static function activate( $network_wide ) { 200 | 201 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { 202 | 203 | if ( $network_wide ) { 204 | 205 | // Get all blog ids 206 | $blog_ids = self::get_blog_ids(); 207 | 208 | foreach ( $blog_ids as $blog_id ) { 209 | 210 | switch_to_blog( $blog_id ); 211 | self::single_activate(); 212 | } 213 | 214 | restore_current_blog(); 215 | 216 | } else { 217 | self::single_activate(); 218 | } 219 | 220 | } else { 221 | self::single_activate(); 222 | } 223 | 224 | } 225 | 226 | /** 227 | * Fired when the plugin is deactivated. 228 | * 229 | * @since 1.0.0 230 | * 231 | * @param boolean $network_wide True if WPMU superadmin uses 232 | * "Network Deactivate" action, false if 233 | * WPMU is disabled or plugin is 234 | * deactivated on an individual blog. 235 | */ 236 | public static function deactivate( $network_wide ) { 237 | 238 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { 239 | 240 | if ( $network_wide ) { 241 | 242 | // Get all blog ids 243 | $blog_ids = self::get_blog_ids(); 244 | 245 | foreach ( $blog_ids as $blog_id ) { 246 | 247 | switch_to_blog( $blog_id ); 248 | self::single_deactivate(); 249 | 250 | } 251 | 252 | restore_current_blog(); 253 | 254 | } else { 255 | self::single_deactivate(); 256 | } 257 | 258 | } else { 259 | self::single_deactivate(); 260 | } 261 | 262 | } 263 | 264 | /** 265 | * Get all blog ids of blogs in the current network that are: 266 | * - not archived 267 | * - not spam 268 | * - not deleted 269 | * 270 | * @since 1.0.0 271 | * 272 | * @return array|false The blog ids, false if no matches. 273 | */ 274 | private static function get_blog_ids() { 275 | 276 | global $wpdb; 277 | 278 | // get an array of blog ids 279 | $sql = "SELECT blog_id FROM $wpdb->blogs 280 | WHERE archived = '0' AND spam = '0' 281 | AND deleted = '0'"; 282 | 283 | return $wpdb->get_col( $sql ); 284 | 285 | } 286 | 287 | /** 288 | * Fired for each blog when the plugin is activated. 289 | * 290 | * @since 1.0.0 291 | */ 292 | private static function single_activate() { 293 | // Define activation functionality here 294 | } 295 | 296 | /** 297 | * Fired for each blog when the plugin is deactivated. 298 | * 299 | * @since 1.0.0 300 | */ 301 | private static function single_deactivate() { 302 | // Define deactivation functionality here 303 | } 304 | 305 | /** 306 | * Load the plugin text domain for translation. 307 | * 308 | * @since 1.0.0 309 | */ 310 | public function load_plugin_textdomain() { 311 | 312 | $domain = $this->plugin_slug; 313 | $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 314 | 315 | load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); 316 | load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' ); 317 | 318 | } 319 | 320 | /** 321 | * Process request from POST 322 | * 323 | * @since 1.0.0 324 | */ 325 | public function process_request() { 326 | 327 | $currencies = array( 328 | 978 => 'EUR', 203 => 'CZK', 329 | 348 => 'HUF', 985 => 'PLN', 330 | ); 331 | 332 | $valid_lang = array( 'en', 'hu', 'sk', 'cz' ); 333 | 334 | $lang = in_array( $_POST['lang'], $valid_lang ) ? esc_html( $_POST['lang'] ) : 'en'; 335 | $currency = in_array( $_POST['currency'], array_keys( $currencies ) ) ? intval( $_POST['currency'] ) : 978; 336 | $amount = ! empty( $_POST['amount'] ) ? intval( $_POST['amount'] ) : ''; 337 | $description = ! empty( $_POST['description'] ) ? esc_html( $_POST['description'] ) : ''; 338 | 339 | $server_data = $request_data = ''; 340 | foreach ( $_SERVER as $key => $value ) 341 | $server_data .= "$key: $value\n"; 342 | foreach ( $_REQUEST as $key => $value ) 343 | $request_data .= "$key: $value\n"; 344 | 345 | // Save payment request 346 | $post = array( 347 | 'post_title' => __( 'Payment ', $this->plugin_slug ), 348 | 'post_content' => "REQUEST DATA\n$request_data\n-----\n\n$server_data\n-----\n", 349 | 'post_type' => $this->plugin_slug, 350 | 'post_status' => 'publish', 351 | 'tax_input' => array( 'status' => 'pending' ), 352 | ); 353 | 354 | $order_id = wp_insert_post( $post ); 355 | 356 | if ( 1 > $order_id ) 357 | wp_die( __( "Couldn't save payment. Please, try again.", $this->plugin_slug ) ); 358 | 359 | add_post_meta( $order_id, 'amount', $amount, true ); 360 | 361 | $rnd = uniqid(); 362 | $trantype = 'Auth'; 363 | $client_id = get_option( $this->plugin_slug . '_client_id'); 364 | $ok_url = site_url() . get_option( $this->plugin_slug . '_ok_url'); 365 | $fail_url = site_url() . get_option( $this->plugin_slug . '_fail_url'); 366 | $hash = implode('', array( 367 | $client_id, 368 | $order_id, 369 | $amount, 370 | $ok_url, 371 | $fail_url, 372 | $trantype, 373 | $rnd, 374 | get_option( $this->plugin_slug . '_store_key' ), 375 | )); 376 | $hash = base64_encode(pack('H*', sha1($hash))); 377 | 378 | $data = array( 379 | 'clientid' => $client_id, 380 | 'storetype' => '3d_pay_hosting', 381 | 'trantype' => $trantype, 382 | 'amount' => $amount, 383 | 'currency' => $currency, 384 | 'oid' => $order_id, 385 | 'encoding' => 'utf-8', 386 | 'okUrl' => $ok_url, 387 | 'failUrl' => $fail_url, 388 | 'lang' => $lang, 389 | 'rnd' => $rnd, 390 | 'hash' => $hash, 391 | 'description' => $description, 392 | ); 393 | 394 | $inputs = array(); 395 | foreach ($data as $k => $v) { 396 | $inputs[] = ""; 397 | } 398 | 399 | return ' 400 |
401 |

' . __( 'In case that you were not redirected, please click the "Continue to the payment gateway" button.', $this->plugin_slug ) . '

402 |
403 | ' . implode("\n", $inputs) . ' 404 | 405 |
406 |
407 | '; 408 | 409 | } 410 | 411 | public function process_response() { 412 | 413 | $order_id = intval( $_REQUEST['oid'] ); 414 | $client_id = get_option( $this->plugin_slug . '_client_id'); 415 | 416 | // Check response hash 417 | $hash = implode('', array( 418 | $client_id, 419 | $order_id, 420 | $_POST['AuthCode'], 421 | $_POST['ProcReturnCode'], 422 | $_POST['Response'], 423 | $_POST['mdStatus'], 424 | $_POST['cavv'], 425 | $_POST['eci'], 426 | $_POST['md'], 427 | $_POST['rnd'], 428 | get_option( $this->plugin_slug . '_store_key' ), 429 | )); 430 | $hash = base64_encode(pack('H*', sha1($hash))); 431 | 432 | if ( $hash != $_POST['HASH'] ) 433 | return '

Wrong hash.

'; 434 | 435 | $server_data = $request_data = ''; 436 | foreach ( $_SERVER as $key => $value ) 437 | $server_data .= "$key: $value\n"; 438 | foreach ( $_REQUEST as $key => $value ) 439 | $request_data .= "$key: $value\n"; 440 | 441 | switch ( strtolower( $_REQUEST['Response'] ) ) { 442 | case 'approved': 443 | $msg = __( '

Payment successful. Thank you. Have a nice day.

', $this->plugin_slug ); 444 | $status = 'success'; 445 | break; 446 | 447 | case 'declined': 448 | $msg = '

Payment was declined. ' . sanitize_text_field( $_POST['ErrMsg'] ) . '

'; 449 | $status = 'aborted'; 450 | break; 451 | 452 | case 'error': 453 | $msg = '

Payment error. ' . sanitize_text_field( $_POST['ErrMsg'] ) . '

'; 454 | $status = 'failed'; 455 | break; 456 | 457 | default: 458 | $msg = __( '

Payment failed. Unknown response from bank gateway.

', $this->plugin_slug ); 459 | $status = 'failed'; 460 | } 461 | 462 | // Save response 463 | $post = array( 464 | 'ID' => $order_id, 465 | 'post_title' => __( 'Payment ', $this->plugin_slug ) . $order_id, 466 | 'post_content' => get_post( $order_id )->post_content . "-----\nRESPONSE DATA\n$request_data\n-----\n\n$server_data", 467 | 'post_password' => sanitize_text_field( $_POST['HASH'] ), 468 | 'tax_input' => array( 'status' => $status ), 469 | ); 470 | 471 | wp_update_post( $post ); 472 | 473 | return $msg; 474 | 475 | } 476 | 477 | } 478 | 479 | endif; 480 | 481 | -------------------------------------------------------------------------------- /vubpay/inc/index.php: -------------------------------------------------------------------------------- 1 | \n" 10 | "Language-Team: LANGUAGE \n" 11 | "MIME-Version: 1.0\n" 12 | "Content-Type: text/plain; charset=UTF-8\n" 13 | "Content-Transfer-Encoding: 8bit\n" 14 | "X-Generator: Poedit 1.5.7\n" 15 | "X-Poedit-KeywordsList: __;_e;_n;_x;esc_html_e;esc_html__;esc_attr_e;" 16 | "esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2\n" 17 | "X-Poedit-Basepath: ../\n" 18 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 19 | "X-Poedit-SearchPath-0: .\n" 20 | 21 | #: class-plugin-name-admin.php:170 22 | msgid "Page Title" 23 | msgstr "" 24 | 25 | #: class-plugin-name-admin.php:171 26 | msgid "Menu Text" 27 | msgstr "" 28 | 29 | #: class-plugin-name-admin.php:197 30 | msgid "Settings" 31 | msgstr "" 32 | -------------------------------------------------------------------------------- /vubpay/uninstall.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link http://nevilleweb.sk 9 | * @copyright 2014 Michal Zuber 10 | */ 11 | 12 | // If uninstall not called from WordPress, then exit 13 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 14 | exit; 15 | } 16 | 17 | global $wpdb; 18 | 19 | if ( is_multisite() ) { 20 | 21 | $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A ); 22 | /* @TODO: delete all transient, options and files you may have added 23 | delete_transient( 'TRANSIENT_NAME' ); 24 | delete_option('OPTION_NAME'); 25 | //info: remove custom file directory for main site 26 | $upload_dir = wp_upload_dir(); 27 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 28 | if (is_dir($directory)) { 29 | foreach(glob($directory.'*.*') as $v){ 30 | unlink($v); 31 | } 32 | rmdir($directory); 33 | } 34 | */ 35 | if ( $blogs ) { 36 | 37 | foreach ( $blogs as $blog ) { 38 | switch_to_blog( $blog['blog_id'] ); 39 | /* @TODO: delete all transient, options and files you may have added 40 | delete_transient( 'TRANSIENT_NAME' ); 41 | delete_option('OPTION_NAME'); 42 | //info: remove custom file directory for main site 43 | $upload_dir = wp_upload_dir(); 44 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 45 | if (is_dir($directory)) { 46 | foreach(glob($directory.'*.*') as $v){ 47 | unlink($v); 48 | } 49 | rmdir($directory); 50 | } 51 | //info: remove and optimize tables 52 | $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`"); 53 | $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`"); 54 | */ 55 | restore_current_blog(); 56 | } 57 | } 58 | 59 | } else { 60 | /* @TODO: delete all transient, options and files you may have added 61 | delete_transient( 'TRANSIENT_NAME' ); 62 | delete_option('OPTION_NAME'); 63 | //info: remove custom file directory for main site 64 | $upload_dir = wp_upload_dir(); 65 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 66 | if (is_dir($directory)) { 67 | foreach(glob($directory.'*.*') as $v){ 68 | unlink($v); 69 | } 70 | rmdir($directory); 71 | } 72 | //info: remove and optimize tables 73 | $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`"); 74 | $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`"); 75 | */ 76 | } 77 | 78 | -------------------------------------------------------------------------------- /vubpay/vubpay.php: -------------------------------------------------------------------------------- 1 | 10 | * @license GPL-2.0+ 11 | * @link http://nevilleweb.sk 12 | * @copyright 2014 Michal Zuber 13 | * 14 | * @wordpress-plugin 15 | * Plugin Name: VUB eCard Payments 16 | * Plugin URI: http://nevilleweb.sk 17 | * Description: Create, process and manage VUB eCard payments 18 | * Version: 1.0.0 19 | * Author: Michal Zuber 20 | * Author URI: http://nevilleweb.sk 21 | * Text Domain: vubpay 22 | * License: GPL-2.0+ 23 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 24 | * Domain Path: /languages 25 | */ 26 | 27 | // If this file is called directly, abort. 28 | if ( ! defined( 'WPINC' ) ) die; 29 | 30 | require_once( plugin_dir_path( __FILE__ ) . 'class-vubpay.php' ); 31 | 32 | /* 33 | * Register hooks that are fired when the plugin is activated or deactivated. 34 | * When the plugin is deleted, the uninstall.php file is loaded. 35 | * 36 | */ 37 | register_activation_hook( __FILE__, array( 'Vubpay', 'activate' ) ); 38 | register_deactivation_hook( __FILE__, array( 'Vubpay', 'deactivate' ) ); 39 | 40 | add_action( 'plugins_loaded', array( 'Vubpay', 'get_instance' ) ); 41 | 42 | /*----------------------------------------------------------------------------* 43 | * Dashboard and Administrative Functionality 44 | *----------------------------------------------------------------------------*/ 45 | 46 | if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { 47 | 48 | require_once( plugin_dir_path( __FILE__ ) . 'admin/class-vubpay-admin.php' ); 49 | add_action( 'plugins_loaded', array( 'Vubpay_Admin', 'get_instance' ) ); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /woocommerce-api-test/README.md: -------------------------------------------------------------------------------- 1 | 2 | Modified code of Gerhard Potgieter 3 | 4 | Original code from 5 | https://github.com/helpforfitness/WooCommerce-REST-API-Client-Library-v2 6 | -------------------------------------------------------------------------------- /woocommerce-api-test/class-wc-api-client.php: -------------------------------------------------------------------------------- 1 | _api_url = ( rtrim($store_url,'/' ) . '/' ) . self::API_ENDPOINT; 64 | $this->set_consumer_key( $consumer_key ); 65 | $this->set_consumer_secret( $consumer_secret ); 66 | $this->set_is_ssl( $is_ssl ); 67 | } else if ( ! isset( $consumer_key ) && ! isset( $consumer_secret ) ) { 68 | throw new Exception( 'Error: __construct() - Consumer Key / Consumer Secret missing.' ); 69 | } else { 70 | throw new Exception( 'Error: __construct() - Store URL missing.' ); 71 | } 72 | } 73 | 74 | /** 75 | * Get API Index 76 | * @return mixed|json string 77 | */ 78 | public function get_index() { 79 | return $this->_make_api_call( '' ); 80 | } 81 | 82 | /** 83 | * Get all orders 84 | * @param array $params 85 | * @return mixed|jason string 86 | */ 87 | public function get_orders( $params = array() ) { 88 | return $this->_make_api_call( 'orders', $params ); 89 | } 90 | 91 | /** 92 | * Get a single order 93 | * @param integer $order_id 94 | * @return mixed|json string 95 | */ 96 | public function get_order( $order_id ) { 97 | return $this->_make_api_call( 'orders/' . $order_id , array('filter[meta]' => 'true')); 98 | } 99 | 100 | /** 101 | * Get the total order count 102 | * @return mixed|json string 103 | */ 104 | public function get_orders_count() { 105 | return $this->_make_api_call( 'orders/count' ); 106 | } 107 | 108 | /** 109 | * Get orders notes for an order 110 | * @param integer $order_id 111 | * @return mixed|json string 112 | */ 113 | public function get_order_notes( $order_id ) { 114 | return $this->_make_api_call( 'orders/' . $order_id . '/notes' ); 115 | } 116 | 117 | /** 118 | * Update the order, currently only status update suported by API 119 | * @param integer $order_id 120 | * @param array $data 121 | * @return mixed|json string 122 | */ 123 | public function update_order( $order_id, $data = array() ) { 124 | return $this->_make_api_call( 'orders/' . $order_id, $data, 'POST' ); 125 | } 126 | 127 | /** 128 | * Delete the order, not suported in WC 2.1, scheduled for 2.2 129 | * @param integer $order_id 130 | * @return mixed|json string 131 | */ 132 | public function delete_order( $order_id ) { 133 | return $this->_make_api_call( 'orders/' . $order_id, $data = array(), 'DELETE' ); 134 | } 135 | 136 | /** 137 | * Get all coupons 138 | * @param array $params 139 | * @return mixed|json string 140 | */ 141 | public function get_coupons( $params = array() ) { 142 | return $this->_make_api_call( 'coupons', $params ); 143 | } 144 | 145 | /** 146 | * Get a single coupon 147 | * @param integer $coupon_id 148 | * @return mixed|json string 149 | */ 150 | public function get_coupon( $coupon_id ) { 151 | return $this->_make_api_call( 'coupons/' . $coupon_id ); 152 | } 153 | 154 | /** 155 | * Get the total coupon count 156 | * @return mixed|json string 157 | */ 158 | public function get_coupons_count() { 159 | return $this->_make_api_call( 'coupons/count' ); 160 | } 161 | 162 | /** 163 | * Get a coupon by the coupon code 164 | * @param string $coupon_code 165 | * @return mixed|json string 166 | */ 167 | public function get_coupon_by_code( $coupon_code ) { 168 | return $this->_make_api_call( 'coupons/code/' . rawurlencode( rawurldecode( $coupon_code ) ) ); 169 | } 170 | 171 | /** 172 | * Get all customers 173 | * @param array $params 174 | * @return mixed|json string 175 | */ 176 | public function get_customers( $params = array() ) { 177 | return $this->_make_api_call( 'customers', $params ); 178 | } 179 | 180 | /** 181 | * Get a single customer 182 | * @param integer $customer_id 183 | * @return mixed|json string 184 | */ 185 | public function get_customer( $customer_id ) { 186 | return $this->_make_api_call( 'customers/' . $customer_id, array('filter[meta]' => 'true') ); 187 | } 188 | 189 | /** 190 | * Get a single customer by email 191 | * @param string $email 192 | * @return mixed|json string 193 | */ 194 | public function get_customer_by_email( $email ) { 195 | return $this->_make_api_call( 'customers/email/' . $email ); 196 | } 197 | 198 | /** 199 | * Get the total customer count 200 | * @return mixed|json string 201 | */ 202 | public function get_customers_count() { 203 | return $this->_make_api_call( 'customers/count' ); 204 | } 205 | 206 | /** 207 | * Get the customer's orders 208 | * @param integer $customer_id 209 | * @return mixed|json string 210 | */ 211 | public function get_customer_orders( $customer_id ) { 212 | return $this->_make_api_call( 'customers/' . $customer_id . '/orders' ); 213 | } 214 | 215 | /** 216 | * Get all the products 217 | * @param array $params 218 | * @return mixed|json string 219 | */ 220 | public function get_products( $params = array() ) { 221 | return $this->_make_api_call( 'products', $params ); 222 | } 223 | 224 | /** 225 | * Get a single product 226 | * @param integer $product_id 227 | * @return mixed|json string 228 | */ 229 | public function get_product( $product_id ) { 230 | return $this->_make_api_call( 'products/' . $product_id ); 231 | } 232 | 233 | /** 234 | * Get the total product count 235 | * @return mixed|json string 236 | */ 237 | public function get_products_count() { 238 | return $this->_make_api_call( 'products/count' ); 239 | } 240 | 241 | /** 242 | * Get reviews for a product 243 | * @param integer $product_id 244 | * @return mixed|json string 245 | */ 246 | public function get_product_reviews( $product_id ) { 247 | return $this->_make_api_call( 'products/' . $product_id . '/reviews' ); 248 | } 249 | 250 | /** 251 | * Get reports 252 | * @param array $params 253 | * @return mixed|json string 254 | */ 255 | public function get_reports( $params = array() ) { 256 | return $this->_make_api_call( 'reports', $params ); 257 | } 258 | 259 | /** 260 | * Get the sales report 261 | * @param array $params 262 | * @return mixed|json string 263 | */ 264 | public function get_sales_report( $params = array() ) { 265 | return $this->_make_api_call( 'reports/sales', $params ); 266 | } 267 | 268 | /** 269 | * Get the top sellers report 270 | * @param array $params 271 | * @return mixed|json string 272 | */ 273 | public function get_top_sellers_report( $params = array() ) { 274 | return $this->_make_api_call( 'reports/sales/top_sellers', $params ); 275 | } 276 | 277 | /** 278 | * Run a custom endpoint call, for when you extended the API with your own endpoints 279 | * @param string $endpoint 280 | * @param array $params 281 | * @param string $method 282 | * @return mixed|json string 283 | */ 284 | public function make_custom_endpoint_call( $endpoint, $params = array(), $method = 'GET' ) { 285 | return $this->_make_api_call( $endpoint, $params, $method ); 286 | } 287 | 288 | /** 289 | * Set the consumer key 290 | * @param string $consumer_key 291 | */ 292 | public function set_consumer_key( $consumer_key ) { 293 | $this->_consumer_key = $consumer_key; 294 | } 295 | 296 | /** 297 | * Set the consumer secret 298 | * @param string $consumer_secret 299 | */ 300 | public function set_consumer_secret( $consumer_secret ) { 301 | $this->_consumer_secret = $consumer_secret; 302 | } 303 | 304 | /** 305 | * Set SSL variable 306 | * @param boolean $is_ssl 307 | */ 308 | public function set_is_ssl( $is_ssl ) { 309 | if ( $is_ssl == '' ) { 310 | if ( strtolower( substr( $this->_api_url, 0, 5 ) ) == 'https' ) { 311 | $this->_is_ssl = true; 312 | } else $this->_is_ssl = false; 313 | } else $this->_is_ssl = $is_ssl; 314 | } 315 | 316 | /** 317 | * Set the return data as object 318 | * @param boolean $is_object 319 | */ 320 | public function set_return_as_object( $is_object = true ) { 321 | $this->_return_as_object = $is_object; 322 | } 323 | 324 | /** 325 | * Make the call to the API 326 | * @param string $endpoint 327 | * @param array $params 328 | * @param string $method 329 | * @return mixed|json string 330 | */ 331 | public function _make_api_call( $endpoint, $params = array(), $method = 'GET', $data = array() ) { 332 | $ch = curl_init(); 333 | 334 | // Check if we must use Basic Auth or 1 legged oAuth, if SSL we use basic, if not we use OAuth 1.0a one-legged 335 | if ( $this->_is_ssl ) { 336 | curl_setopt( $ch, CURLOPT_USERPWD, $this->_consumer_key . ":" . $this->_consumer_secret ); 337 | } else { 338 | $params['oauth_consumer_key'] = $this->_consumer_key; 339 | $params['oauth_timestamp'] = time(); 340 | $params['oauth_nonce'] = sha1( microtime() ); 341 | $params['oauth_signature_method'] = 'HMAC-' . self::HASH_ALGORITHM; 342 | $params['oauth_signature'] = $this->generate_oauth_signature( $params, $method, $endpoint ); 343 | } 344 | 345 | if ( isset( $params ) && is_array( $params ) ) { 346 | $paramString = '?' . http_build_query( $params ); 347 | } else { 348 | $paramString = null; 349 | } 350 | 351 | // Set up the enpoint URL 352 | curl_setopt( $ch, CURLOPT_URL, $this->_api_url . $endpoint . $paramString ); 353 | curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 354 | curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); 355 | curl_setopt( $ch, CURLOPT_TIMEOUT, 30 ); 356 | curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 357 | 358 | if ( 'POST' === $method ) { 359 | curl_setopt( $ch, CURLOPT_POST, true ); 360 | curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $params ) ); 361 | } else if ( 'PUT' === $method ) { 362 | curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT' ); 363 | curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $data ) ); 364 | } else if ( 'DELETE' === $method ) { 365 | curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'DELETE' ); 366 | } 367 | 368 | $return = curl_exec( $ch ); 369 | 370 | $code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); 371 | 372 | if ( $this->_return_as_object ) { 373 | $return = json_decode( $return ); 374 | } 375 | 376 | if ( empty( $return ) ) { 377 | $return = '{"errors":[{"code":"' . $code . '","message":"cURL HTTP error ' . $code . '"}]}'; 378 | $return = json_decode( $return ); 379 | } 380 | return $return; 381 | } 382 | 383 | /** 384 | * Generate oAuth signature 385 | * @param array $params 386 | * @param string $http_method 387 | * @param string $endpoint 388 | * @return string 389 | */ 390 | public function generate_oauth_signature( $params, $http_method, $endpoint ) { 391 | $base_request_uri = rawurlencode( $this->_api_url . $endpoint ); 392 | 393 | // normalize parameter key/values and sort them 394 | $params = $this->normalize_parameters( $params ); 395 | uksort( $params, 'strcmp' ); 396 | 397 | // form query string 398 | $query_params = array(); 399 | foreach ( $params as $param_key => $param_value ) { 400 | $query_params[] = $param_key . '%3D' . $param_value; // join with equals sign 401 | } 402 | 403 | $query_string = implode( '%26', $query_params ); // join with ampersand 404 | 405 | // form string to sign (first key) 406 | $string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string; 407 | 408 | return base64_encode( hash_hmac( self::HASH_ALGORITHM, $string_to_sign, $this->_consumer_secret, true ) ); 409 | } 410 | 411 | /** 412 | * Normalize each parameter by assuming each parameter may have already been 413 | * encoded, so attempt to decode, and then re-encode according to RFC 3986 414 | * 415 | * Note both the key and value is normalized so a filter param like: 416 | * 417 | * 'filter[period]' => 'week' 418 | * 419 | * is encoded to: 420 | * 421 | * 'filter%5Bperiod%5D' => 'week' 422 | * 423 | * This conforms to the OAuth 1.0a spec which indicates the entire query string 424 | * should be URL encoded 425 | * 426 | * @since 0.3.1 427 | * @see rawurlencode() 428 | * @param array $parameters un-normalized pararmeters 429 | * @return array normalized parameters 430 | */ 431 | private function normalize_parameters( $parameters ) { 432 | 433 | $normalized_parameters = array(); 434 | 435 | foreach ( $parameters as $key => $value ) { 436 | 437 | // percent symbols (%) must be double-encoded 438 | $key = str_replace( '%', '%25', rawurlencode( rawurldecode( $key ) ) ); 439 | $value = str_replace( '%', '%25', rawurlencode( rawurldecode( $value ) ) ); 440 | 441 | $normalized_parameters[ $key ] = $value; 442 | } 443 | 444 | return $normalized_parameters; 445 | } 446 | 447 | } 448 | -------------------------------------------------------------------------------- /woocommerce-api-test/index.php: -------------------------------------------------------------------------------- 1 | get_index(); 14 | 15 | // Get all orders 16 | // $response = $wc_api->get_orders( array( 'status' => 'completed' ) ); 17 | 18 | // Get a single order by id 19 | // $response = $wc_api->get_order( 166 ); 20 | 21 | // Get orders count 22 | // $response = $wc_api->get_orders_count(); 23 | 24 | // Get order notes for a specific order 25 | // $response = $wc_api->get_order_notes( 166 ); 26 | 27 | // Update order status 28 | // $response = $wc_api->update_order( 166, $data = array( 'status' => 'failed' ) ); 29 | 30 | // Get all coupons 31 | // $response = $wc_api->get_coupons(); 32 | 33 | // Get coupon by id 34 | // $response = $wc_api->get_coupon( 173 ); 35 | 36 | // Get coupon by code 37 | // $response = $wc_api->get_coupon_by_code( 'test coupon' ); 38 | 39 | // Get coupons count 40 | // $response = $wc_api->get_coupons_count(); 41 | 42 | // Get customers 43 | // $response = $wc_api->get_customers(); 44 | 45 | // Get customer by id 46 | // $response = $wc_api->get_customer( 2 ); 47 | 48 | // Get customer count 49 | // $response = $wc_api->get_customers_count(); 50 | 51 | // Get customer orders 52 | // $response = $wc_api->get_customer_orders( 2 ); 53 | 54 | // Get all products 55 | // $response = $wc_api->get_products(); 56 | 57 | // Get a single product by id 58 | // $response = $wc_api->get_product( 167 ); 59 | 60 | // Get products count 61 | // $response = $wc_api->get_products_count(); 62 | 63 | // Get product reviews 64 | // $response = $wc_api->get_product_reviews( 167 ); 65 | 66 | // Get reports 67 | // $response = $wc_api->get_reports(); 68 | 69 | // Get sales report 70 | // $response = $wc_api->get_sales_report(); 71 | 72 | // Get top sellers report 73 | // $response = $wc_api->get_top_sellers_report(); 74 | 75 | // Update product 76 | $product_id = 7022; 77 | $data = array( 78 | 'product' => array( 79 | 'title' => 'API test', 80 | ), 81 | ); 82 | // $response = $wc_api->_make_api_call( 'products/'.$product_id, array(), 'PUT', $data ); 83 | 84 | echo "
"; print_r($response); echo "
"; 85 | -------------------------------------------------------------------------------- /woocommerce-attribute-import/README: -------------------------------------------------------------------------------- 1 | 2 | There's no export, it directly connect to the Virtuemart database. 3 | 4 | You gonna need to change the credentials on line 46: 5 | $db_host = 'VIRTUEMART_HOST'; 6 | $db_user = 'VIRTUEMART_USER'; 7 | $db_pass = 'VIRTUEMART_PASS'; 8 | $db_name = 'VIRTUEMART_NAME'; 9 | $db_prefix = 'VIRTUEMART_PREFIX'; 10 | -------------------------------------------------------------------------------- /woocommerce-attribute-import/woocommerce-attribute-import.php: -------------------------------------------------------------------------------- 1 | 70 |
71 |

Import WooCommerce product attributes from VirtueMart

72 |

Product count: count ?> pcs

73 |
    74 |
  1. 75 |
    76 | 77 | 78 |

    79 |
    80 |
  2. 81 |
82 |
83 | get_results( $q, 'ARRAY_A' ); 112 | 113 | $imported = 0; 114 | $started = date('Y-m-d H:i:s'); 115 | 116 | $attributes = array(); 117 | foreach ($products as $vm_attributes) { 118 | 119 | // Get product ID by sku 120 | $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sku' AND meta_value = %s"; 121 | $post_id = $wpdb->get_var( $wpdb->prepare( $q, $vm_attributes['product_sku'] ) ); 122 | 123 | // Unset key which won't be attribute 124 | unset( $vm_attributes['product_sku'] ); 125 | 126 | $position = 0; 127 | foreach ($vm_attributes as $meta_key => $meta_value) { 128 | 129 | $meta_key = 'pa_' . $meta_key; 130 | $meta_value = trim( $meta_value ); 131 | 132 | $term = term_exists( $meta_value, $meta_key ); 133 | if ( $term === 0 && $term === null ) { 134 | $term = wp_insert_term( $meta_value, $meta_key ); 135 | } 136 | 137 | // Update post terms 138 | wp_set_object_terms( $post_id, $meta_value, $meta_key ); 139 | 140 | // Prepare attributes 141 | // Src: /wp-content/plugins/woocommerce/includes/class-wc-ajax.php method save_attributes() 142 | $attributes[ $meta_key ] = array( 143 | 'name' => $meta_key, 144 | 'value' => '', 145 | 'position' => $position++, 146 | 'is_variation' => 0, 147 | 'is_visible' => 1, 148 | 'is_taxonomy' => 1, 149 | ); 150 | 151 | if ( $imported % 100 == 0 ) 152 | echo "Imported $imported"; 153 | } 154 | 155 | update_post_meta( $post_id, '_product_attributes', $attributes ); 156 | 157 | $imported++; 158 | } 159 | 160 | echo ' 161 |
162 |

Import WooCommerce product attributes from VirtueMart

163 |

Started @ ' . $started . '

164 |

Imported: ' . $imported . ' products

165 |

Finished @ ' . date('Y-m-d H:i:s') . '

166 |
'; 167 | 168 | } 169 | 170 | } 171 | 172 | -------------------------------------------------------------------------------- /woocommerce-custom-order/woocommerce-custom-order.php: -------------------------------------------------------------------------------- 1 | '; 20 | $form .= ''; 21 | $products = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_type = 'product' AND post_status = 'publish'", ARRAY_A); 22 | foreach ($products as $product) { 23 | $meta = get_post_meta($product['ID']); 24 | $form .= ' 25 | 29 | 30 | 33 | '; 34 | } 35 | $form .= '
26 |

'.$product['post_title'].'

27 | '.$product['post_content'].' 28 |
'.$meta['_regular_price'][0].' 31 | 32 |
'; 36 | $form .= ''; 37 | 38 | $form .= '
39 |

Fakturačná adresa

40 |
41 |
42 | 45 |
46 |
47 | 48 |
49 |
50 | 53 |
54 |
55 | 56 |
57 |
58 |
59 |
60 | 63 |
64 |
65 | 66 |
67 |
68 | 71 |
72 |
73 | 74 |
75 |
76 |
77 |
78 | 81 |
82 |
83 | 84 |
85 |
86 | 89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 | 97 |
98 |
99 | 100 |
101 |
102 | 103 |
104 |
105 | 106 |
107 |
108 |

Dodacia adresa

109 |

110 | 114 |

115 |
116 |
117 |
118 | 119 |
120 |
121 | 122 |
123 |
124 | 125 |
126 |
127 | 128 |
129 |
130 |
131 |
132 | 133 |
134 |
135 | 136 |
137 |
138 | 139 |
140 |
141 | 142 |
143 |
144 |
145 |
146 | 147 |
148 |
149 | 150 |
151 |
152 |
153 | 154 |
155 |

Spôsob platby

156 |

157 | 161 | 165 |

166 |
167 | 168 |
169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 |
Súčet0.00
178 |
179 | 180 |

Spolu: 0.00

181 |

182 | 186 |

187 | 188 |
'; 189 | 190 | $form .= ''; 191 | 192 | return $form; 193 | } 194 | 195 | add_action('template_redirect', 'custom_save_order'); 196 | function custom_save_order() 197 | { 198 | global $wpdb; 199 | 200 | if (!is_single() && !is_page()) { 201 | return; 202 | } 203 | 204 | if (empty($_POST)) { 205 | return; 206 | } 207 | 208 | $order_id = wp_insert_post(array( 209 | 'post_title' => 'Order – '.date('d.m.Y H:i'), 210 | 'post_status' => 'wc-pending', 211 | 'comment_status' => 'closed', 212 | 'post_type' => 'shop_order', 213 | )); 214 | 215 | if (1 > $order_id) { 216 | return; 217 | } 218 | 219 | $total = 0; 220 | foreach ($_POST['quantity'] as $product_id => $qnt) { 221 | if (1 > $qnt) { 222 | continue; 223 | } 224 | $wc_product = wc_get_product($product_id); 225 | $subtotal = $qnt * $wc_product->get_price(); 226 | $total += $subtotal; 227 | 228 | $wpdb->insert( 229 | $wpdb->prefix.'woocommerce_order_items', 230 | array( 231 | 'order_item_name' => $wc_product->get_title(), 232 | 'order_item_type' => 'line_item', 233 | 'order_id' => $order_id, 234 | ), 235 | array( 236 | '%s', '%s', '%d', 237 | ) 238 | ); 239 | $order_item_id = $wpdb->insert_id; 240 | 241 | wc_add_order_item_meta($order_item_id, '_product_id', $product_id); 242 | wc_add_order_item_meta($order_item_id, '_qty', $qnt); 243 | wc_add_order_item_meta($order_item_id, '_product_id', $product_id); 244 | wc_add_order_item_meta($order_item_id, '_line_subtotal', $subtotal); 245 | wc_add_order_item_meta($order_item_id, '_line_subtotal_tax', 0); 246 | wc_add_order_item_meta($order_item_id, '_line_total', $subtotal); 247 | wc_add_order_item_meta($order_item_id, '_line_tax', 0); 248 | } 249 | 250 | add_post_meta($order_id, '_billing_first_name', $_POST['first_name']); 251 | add_post_meta($order_id, '_billing_last_name', $_POST['last_name']); 252 | add_post_meta($order_id, '_billing_address_1', $_POST['street']); 253 | add_post_meta($order_id, '_billing_city', $_POST['city']); 254 | add_post_meta($order_id, '_billing_postcode', $_POST['zip']); 255 | add_post_meta($order_id, '_billing_email', $_POST['email']); 256 | add_post_meta($order_id, '_billing_phone', $_POST['phone']); 257 | add_post_meta($order_id, '_shipping_first_name', $_POST['ship_first_name']); 258 | add_post_meta($order_id, '_shipping_last_name', $_POST['ship_last_name']); 259 | add_post_meta($order_id, '_shipping_address_1', $_POST['ship_street']); 260 | add_post_meta($order_id, '_shipping_city', $_POST['ship_city']); 261 | add_post_meta($order_id, '_shipping_postcode', $_POST['ship_zip']); 262 | add_post_meta($order_id, '_order_total', $total); 263 | add_post_meta($order_id, '_order_tax', $total / 1.2); 264 | add_post_meta($order_id, '_order_currency', 'EUR'); 265 | add_post_meta($order_id, '_customer_user', 0); 266 | add_post_meta($order_id, '_order_shipping', 0); 267 | add_post_meta($order_id, '_order_shipping_tax', 0); 268 | add_post_meta($order_id, '_cart_discount', 0); 269 | add_post_meta($order_id, '_cart_discount_tax', 0); 270 | add_post_meta($order_id, '_payment_method', $_POST['payment']); 271 | 272 | $comment_post_ID = $order_id; 273 | $comment_content = $_POST['note']; 274 | $comment_agent = 'WooCommerce'; 275 | $comment_type = 'order_note'; 276 | $comment_parent = 0; 277 | $comment_approved = 1; 278 | $commentdata = apply_filters( 279 | 'woocommerce_new_order_note_data', 280 | compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_agent', 'comment_type', 'comment_parent', 'comment_approved'), 281 | array('order_id' => $order_id, 'is_customer_note' => 1) 282 | ); 283 | 284 | $comment_id = wp_insert_comment($commentdata); 285 | 286 | $mailer = WC()->mailer(); 287 | $mails = $mailer->get_emails(); 288 | if (!empty($mails)) { 289 | foreach ($mails as $mail) { 290 | if ($mail->id == 'customer_processing_order') { 291 | $mail->trigger($order_id); 292 | } 293 | } 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/README.md: -------------------------------------------------------------------------------- 1 | === Woocommerce Email Attachment === 2 | Contributors: michalzuber 3 | Tags: woocommerce, email, attachment 4 | Tested up to: 4.8 5 | Stable tag: 1.0.0 6 | License: GPLv2 or later 7 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 | 9 | Adds 2 attachments to processing email. 10 | 11 | == Description == 12 | 13 | Due law change http://blog.riesenia.com/fotak-na-dovolenku-zadarmo-alebo-nove-pravidla-pre-e-shopy/ 14 | it is needed to send 2 forms with the order: 15 | * http://www.nakupujbezpecne.sk/docs/form/odstupenie%20od%20zmluvy.pdf 16 | * http://www.nakupujbezpecne.sk/docs/form/reklamacia.pdf 17 | 18 | Law info available at http://nakupujbezpecne.sk/docs/zakony/102_2014.pdf 19 | 20 | ![WooCommerce Email Attachment](./screenshot.png "WooCommerce Email Attachment") 21 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/admin/assets/js/admin.js: -------------------------------------------------------------------------------- 1 | 2 | jQuery( document ).ready(function( $ ) { 3 | 4 | $( document ).on( 'click', '.insert-media', function( event ) { 5 | var dst = $( '#' + $( this ).data( 'editor' ) ); 6 | 7 | wp.media.editor.send.attachment = function( props, attachment ) { 8 | dst.val( attachment.url.replace( site.url, '') ); 9 | } 10 | }); 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/admin/class-woocommerce-email-attachment-admin.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 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 | * If you're interested in introducing public-facing 15 | * functionality, then refer to `class-plugin-name.php` 16 | * 17 | * @package Woocommerce_Email_Attachment_Admin 18 | * @author Michal Zuber 19 | */ 20 | class Woocommerce_Email_Attachment_Admin { 21 | 22 | /** 23 | * Instance of this class. 24 | * 25 | * @since 1.0.0 26 | * 27 | * @var object 28 | */ 29 | protected static $instance = null; 30 | 31 | /** 32 | * Slug of the plugin screen. 33 | * 34 | * @since 1.0.0 35 | * 36 | * @var string 37 | */ 38 | protected $screen_hook_suffix = null; 39 | 40 | /** 41 | * Initialize the plugin by loading admin scripts & styles and adding a 42 | * settings page and menu. 43 | * 44 | * @since 1.0.0 45 | */ 46 | private function __construct() { 47 | 48 | $plugin = Woocommerce_Email_Attachment::get_instance(); 49 | $this->plugin_slug = $plugin->get_plugin_slug(); 50 | 51 | add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ), 60 ); 52 | 53 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); 54 | 55 | // Add an action link pointing to the options page. 56 | $plugin_basename = plugin_basename( plugin_dir_path( realpath( dirname( __FILE__ ) ) ) . $this->plugin_slug . '.php' ); 57 | add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) ); 58 | 59 | } 60 | 61 | /** 62 | * Return an instance of this class. 63 | * 64 | * @since 1.0.0 65 | * 66 | * @return object A single instance of this class. 67 | */ 68 | public static function get_instance() { 69 | 70 | // If the single instance hasn't been set, set it now. 71 | if ( null == self::$instance ) { 72 | self::$instance = new self; 73 | } 74 | 75 | return self::$instance; 76 | } 77 | 78 | /** 79 | * Register and enqueue admin-specific style sheet. 80 | * 81 | * @since 1.0.0 82 | * 83 | * @return null Return early if no settings page is registered. 84 | */ 85 | public function enqueue_admin_styles() { 86 | 87 | if ( ! isset( $this->screen_hook_suffix ) ) { 88 | return; 89 | } 90 | 91 | $screen = get_current_screen(); 92 | if ( $this->screen_hook_suffix == $screen->id ) { 93 | wp_enqueue_style( $this->plugin_slug .'-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), Woocommerce_Email_Attachment::VERSION ); 94 | } 95 | 96 | } 97 | 98 | /** 99 | * Register and enqueue admin-specific JavaScript. 100 | * 101 | * @since 1.0.0 102 | * 103 | * @return null Return early if no settings page is registered. 104 | */ 105 | public function enqueue_admin_scripts() { 106 | 107 | if ( ! isset( $this->screen_hook_suffix ) ) { 108 | return; 109 | } 110 | 111 | wp_enqueue_media(); 112 | 113 | $screen = get_current_screen(); 114 | if ( $this->screen_hook_suffix == $screen->id ) { 115 | wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery' ), Woocommerce_Email_Attachment::VERSION ); 116 | 117 | $site = array( 118 | 'url' => get_site_url() . '/wp-content', 119 | ); 120 | wp_localize_script( $this->plugin_slug . '-admin-script', 'site', $site ); 121 | } 122 | 123 | } 124 | 125 | /** 126 | * Register the administration menu for this plugin into the WordPress Dashboard menu. 127 | * 128 | * @since 1.0.0 129 | */ 130 | public function add_plugin_admin_menu() { 131 | 132 | /* 133 | * Add a settings page for this plugin to the Settings menu. 134 | * 135 | */ 136 | $this->screen_hook_suffix = add_submenu_page( 137 | 'woocommerce', 138 | __( 'Woocommerce Email Attachment', $this->plugin_slug ), 139 | __( 'Email Attachment', $this->plugin_slug ), 140 | 'upload_files', 141 | $this->plugin_slug, 142 | array( $this, 'display_plugin_admin_page' ) 143 | ); 144 | 145 | } 146 | 147 | /** 148 | * Render the settings page for this plugin. 149 | * 150 | * @since 1.0.0 151 | */ 152 | public function display_plugin_admin_page() { 153 | if ( isset( $_POST['processing_order_attachment'] ) ) { 154 | $this->save_attachments(); 155 | } 156 | 157 | $processing_order_attachments = get_option( '_wc_processing_order_email_attachments' ); 158 | 159 | include_once( 'views/admin.php' ); 160 | } 161 | 162 | private function save_attachments() { 163 | 164 | if ( ! isset( $_POST['_wpnonce'] ) ) 165 | return; 166 | 167 | if ( ! wp_verify_nonce( $_POST['_wpnonce'], $this->plugin_slug . '-admin' ) ) 168 | return; 169 | 170 | $attachments = array(); 171 | foreach ( $_POST['processing_order_attachment'] as $attachment ) { 172 | if ( is_file( WP_CONTENT_DIR . $attachment ) ) { 173 | $attachments[] = $attachment; 174 | } 175 | } 176 | 177 | update_option( '_wc_processing_order_email_attachments', $attachments ); 178 | 179 | } 180 | 181 | /** 182 | * Add settings action link to the plugins page. 183 | * 184 | * @since 1.0.0 185 | */ 186 | public function add_action_links( $links ) { 187 | 188 | return array_merge( 189 | array( 190 | 'settings' => '' . __( 'Settings', $this->plugin_slug ) . '' 191 | ), 192 | $links 193 | ); 194 | 195 | } 196 | 197 | } 198 | 199 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/admin/views/admin.php: -------------------------------------------------------------------------------- 1 | 10 | * @license GPL-2.0+ 11 | */ 12 | ?> 13 | 14 |
15 | 16 |

17 | 18 |

plugin_slug ); ?>

19 |
plugin_slug}" ); ?>" method="post"> 20 | plugin_slug . '-admin' ); ?> 21 | 22 | 23 | 24 | 25 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 40 | 41 |
26 | 27 | 29 | 30 | 31 |
  38 | 39 |
42 |
43 | 44 |
45 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | A custom set of rules to check for a WPized WordPress project 4 | 5 | 6 | 7 | 8 | /docroot/wp-admin/* 9 | /docroot/wp-includes/* 10 | /docroot/wp-*.php 11 | /docroot/index.php 12 | /docroot/xmlrpc.php 13 | /docroot/wp-content/plugins/* 14 | 15 | 16 | /vendor/* 17 | 18 | 19 | /node_modules/* 20 | 21 | 22 | *.min.js 23 | 24 | 25 | 26 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 53 | 57 | 58 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/public/class-woocommerce-email-attachment.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | */ 9 | 10 | /** 11 | * Plugin class. This class should ideally be used to work with the 12 | * public-facing side of the WordPress site. 13 | * 14 | * @package Woocommerce_Email_Attachment 15 | * @author Michal Zuber 16 | */ 17 | class Woocommerce_Email_Attachment { 18 | 19 | /** 20 | * Plugin version, used for cache-busting of style and script file references. 21 | * 22 | * @since 1.0.0 23 | * 24 | * @var string 25 | */ 26 | const VERSION = '1.0.0'; 27 | 28 | /** 29 | * Unique identifier for your plugin. 30 | * 31 | * 32 | * The variable name is used as the text domain when internationalizing strings 33 | * of text. Its value should match the Text Domain file header in the main 34 | * plugin file. 35 | * 36 | * @since 1.0.0 37 | * 38 | * @var string 39 | */ 40 | protected $plugin_slug = 'woocommerce-email-attachment'; 41 | 42 | /** 43 | * Instance of this class. 44 | * 45 | * @since 1.0.0 46 | * 47 | * @var object 48 | */ 49 | protected static $instance = null; 50 | 51 | /** 52 | * Initialize the plugin by setting localization and loading public scripts 53 | * and styles. 54 | * 55 | * @since 1.0.0 56 | */ 57 | private function __construct() { 58 | 59 | // Load plugin text domain 60 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 61 | 62 | // Activate plugin when new blog is added 63 | add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) ); 64 | 65 | add_filter( 'woocommerce_email_attachments', array( $this, 'add_attachment' ), 10, 2 ); 66 | 67 | } 68 | 69 | /** 70 | * Return the plugin slug. 71 | * 72 | * @since 1.0.0 73 | * 74 | * @return Plugin slug variable. 75 | */ 76 | public function get_plugin_slug() { 77 | return $this->plugin_slug; 78 | } 79 | 80 | /** 81 | * Return an instance of this class. 82 | * 83 | * @since 1.0.0 84 | * 85 | * @return object A single instance of this class. 86 | */ 87 | public static function get_instance() { 88 | 89 | // If the single instance hasn't been set, set it now. 90 | if ( null == self::$instance ) { 91 | self::$instance = new self; 92 | } 93 | 94 | return self::$instance; 95 | } 96 | 97 | /** 98 | * Fired when the plugin is activated. 99 | * 100 | * @since 1.0.0 101 | * 102 | * @param boolean $network_wide True if WPMU superadmin uses 103 | * "Network Activate" action, false if 104 | * WPMU is disabled or plugin is 105 | * activated on an individual blog. 106 | */ 107 | public static function activate( $network_wide ) { 108 | 109 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { 110 | 111 | if ( $network_wide ) { 112 | 113 | // Get all blog ids 114 | $blog_ids = self::get_blog_ids(); 115 | 116 | foreach ( $blog_ids as $blog_id ) { 117 | 118 | switch_to_blog( $blog_id ); 119 | self::single_activate(); 120 | 121 | restore_current_blog(); 122 | } 123 | 124 | } else { 125 | self::single_activate(); 126 | } 127 | 128 | } else { 129 | self::single_activate(); 130 | } 131 | 132 | } 133 | 134 | /** 135 | * Fired when the plugin is deactivated. 136 | * 137 | * @since 1.0.0 138 | * 139 | * @param boolean $network_wide True if WPMU superadmin uses 140 | * "Network Deactivate" action, false if 141 | * WPMU is disabled or plugin is 142 | * deactivated on an individual blog. 143 | */ 144 | public static function deactivate( $network_wide ) { 145 | 146 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { 147 | 148 | if ( $network_wide ) { 149 | 150 | // Get all blog ids 151 | $blog_ids = self::get_blog_ids(); 152 | 153 | foreach ( $blog_ids as $blog_id ) { 154 | 155 | switch_to_blog( $blog_id ); 156 | self::single_deactivate(); 157 | 158 | restore_current_blog(); 159 | 160 | } 161 | 162 | } else { 163 | self::single_deactivate(); 164 | } 165 | 166 | } else { 167 | self::single_deactivate(); 168 | } 169 | 170 | } 171 | 172 | /** 173 | * Fired when a new site is activated with a WPMU environment. 174 | * 175 | * @since 1.0.0 176 | * 177 | * @param int $blog_id ID of the new blog. 178 | */ 179 | public function activate_new_site( $blog_id ) { 180 | 181 | if ( 1 !== did_action( 'wpmu_new_blog' ) ) { 182 | return; 183 | } 184 | 185 | switch_to_blog( $blog_id ); 186 | self::single_activate(); 187 | restore_current_blog(); 188 | 189 | } 190 | 191 | /** 192 | * Get all blog ids of blogs in the current network that are: 193 | * - not archived 194 | * - not spam 195 | * - not deleted 196 | * 197 | * @since 1.0.0 198 | * 199 | * @return array|false The blog ids, false if no matches. 200 | */ 201 | private static function get_blog_ids() { 202 | 203 | global $wpdb; 204 | 205 | // get an array of blog ids 206 | $sql = "SELECT blog_id FROM $wpdb->blogs 207 | WHERE archived = '0' AND spam = '0' 208 | AND deleted = '0'"; 209 | 210 | return $wpdb->get_col( $sql ); 211 | 212 | } 213 | 214 | /** 215 | * Fired for each blog when the plugin is activated. 216 | * 217 | * @since 1.0.0 218 | */ 219 | private static function single_activate() { 220 | 221 | } 222 | 223 | /** 224 | * Fired for each blog when the plugin is deactivated. 225 | * 226 | * @since 1.0.0 227 | */ 228 | private static function single_deactivate() { 229 | 230 | } 231 | 232 | /** 233 | * Load the plugin text domain for translation. 234 | * 235 | * @since 1.0.0 236 | */ 237 | public function load_plugin_textdomain() { 238 | 239 | $domain = $this->plugin_slug; 240 | $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 241 | 242 | load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); 243 | load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' ); 244 | 245 | } 246 | 247 | /** 248 | * Add attachment media files to phpmailer 249 | * 250 | * @since 1.0.0 251 | * 252 | * @param array $attachments 253 | * @param string $email_method_id 254 | * @return array 255 | */ 256 | public function add_attachment( $attachments, $email_method_id ) { 257 | 258 | if ( in_array($email_method_id, array( 'customer_processing_order', 'customer_on_hold_order' ) ) ) { 259 | foreach ( get_option( '_wc_processing_order_email_attachments' ) as $attachment ) { 260 | $attachments[] = WP_CONTENT_DIR . $attachment; 261 | } 262 | } 263 | 264 | return $attachments; 265 | 266 | } 267 | 268 | } 269 | 270 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelz/wordpress-related/293ee96b9af7be98fe284f9cd1e4abc380182eba/woocommerce-email-attachment/screenshot.png -------------------------------------------------------------------------------- /woocommerce-email-attachment/uninstall.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | */ 9 | 10 | // If uninstall not called from WordPress, then exit 11 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 12 | exit; 13 | } 14 | 15 | global $wpdb; 16 | 17 | if ( is_multisite() ) { 18 | 19 | $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A ); 20 | /* @TODO: delete all transient, options and files you may have added 21 | delete_transient( 'TRANSIENT_NAME' ); 22 | delete_option('OPTION_NAME'); 23 | //info: remove custom file directory for main site 24 | $upload_dir = wp_upload_dir(); 25 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 26 | if (is_dir($directory)) { 27 | foreach(glob($directory.'*.*') as $v){ 28 | unlink($v); 29 | } 30 | rmdir($directory); 31 | } 32 | */ 33 | if ( $blogs ) { 34 | 35 | foreach ( $blogs as $blog ) { 36 | switch_to_blog( $blog['blog_id'] ); 37 | /* @TODO: delete all transient, options and files you may have added 38 | delete_transient( 'TRANSIENT_NAME' ); 39 | delete_option('OPTION_NAME'); 40 | //info: remove custom file directory for main site 41 | $upload_dir = wp_upload_dir(); 42 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 43 | if (is_dir($directory)) { 44 | foreach(glob($directory.'*.*') as $v){ 45 | unlink($v); 46 | } 47 | rmdir($directory); 48 | } 49 | //info: remove and optimize tables 50 | $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`"); 51 | $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`"); 52 | */ 53 | restore_current_blog(); 54 | } 55 | } 56 | 57 | } else { 58 | /* @TODO: delete all transient, options and files you may have added 59 | delete_transient( 'TRANSIENT_NAME' ); 60 | delete_option('OPTION_NAME'); 61 | //info: remove custom file directory for main site 62 | $upload_dir = wp_upload_dir(); 63 | $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR; 64 | if (is_dir($directory)) { 65 | foreach(glob($directory.'*.*') as $v){ 66 | unlink($v); 67 | } 68 | rmdir($directory); 69 | } 70 | //info: remove and optimize tables 71 | $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`"); 72 | $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`"); 73 | */ 74 | } 75 | 76 | -------------------------------------------------------------------------------- /woocommerce-email-attachment/woocommerce-email-attachment.php: -------------------------------------------------------------------------------- 1 | 10 | * @license GPL-2.0+ 11 | * 12 | * @wordpress-plugin 13 | * Plugin Name: Woocommerce Email Attachment 14 | * Plugin URI: http://www.nevilleweb.sk/ 15 | * Description: Add attachment to woocommerce email 16 | * Version: 1.0.0 17 | * Author: Michal Zuber 18 | * Author URI: http://www.nevilleweb.sk/ 19 | * Text Domain: woocommerce-email-attachment-locale 20 | * License: GPL-2.0+ 21 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 22 | * Domain Path: /languages 23 | * WordPress-Plugin-Boilerplate: v2.6.1 24 | */ 25 | 26 | // If this file is called directly, abort. 27 | if ( ! defined( 'WPINC' ) ) { 28 | die; 29 | } 30 | 31 | /*----------------------------------------------------------------------------* 32 | * Public-Facing Functionality 33 | *----------------------------------------------------------------------------*/ 34 | 35 | require_once( plugin_dir_path( __FILE__ ) . 'public/class-woocommerce-email-attachment.php' ); 36 | 37 | /* 38 | * Register hooks that are fired when the plugin is activated or deactivated. 39 | * When the plugin is deleted, the uninstall.php file is loaded. 40 | */ 41 | register_activation_hook( __FILE__, array( 'Woocommerce_Email_Attachment', 'activate' ) ); 42 | register_deactivation_hook( __FILE__, array( 'Woocommerce_Email_Attachment', 'deactivate' ) ); 43 | 44 | add_action( 'plugins_loaded', array( 'Woocommerce_Email_Attachment', 'get_instance' ) ); 45 | 46 | /*----------------------------------------------------------------------------* 47 | * Dashboard and Administrative Functionality 48 | *----------------------------------------------------------------------------*/ 49 | 50 | /* 51 | * If you want to include Ajax within the dashboard, change the following 52 | * conditional to: 53 | * 54 | * if ( is_admin() ) { 55 | * ... 56 | * } 57 | * 58 | * The code below is intended to to give the lightest footprint possible. 59 | */ 60 | if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { 61 | 62 | require_once( plugin_dir_path( __FILE__ ) . 'admin/class-woocommerce-email-attachment-admin.php' ); 63 | add_action( 'plugins_loaded', array( 'Woocommerce_Email_Attachment_Admin', 'get_instance' ) ); 64 | 65 | } 66 | 67 | -------------------------------------------------------------------------------- /woocommerce-import-categories/index.php: -------------------------------------------------------------------------------- 1 | term_id)) { 20 | $category = wp_insert_term($data[0], 'product_cat'); 21 | $parent = $category['term_id']; 22 | } 23 | 24 | // Insert subcategory 25 | $slug = sanitize_title($data[1]); 26 | if (!empty($slug) && $parent > 0) { 27 | $category = wp_insert_term($data[1], 'product_cat', ['parent' => $parent]); 28 | } 29 | 30 | $item_count++; 31 | } 32 | fclose($handle); 33 | } 34 | 35 | echo $execStart.'
'; 36 | echo "Imported $item_count
"; 37 | echo date('Y-m-d H:i:s'); 38 | -------------------------------------------------------------------------------- /woocommerce-import-categories/test.csv: -------------------------------------------------------------------------------- 1 | Category1; 2 | ;Subcategory11 3 | ;Subcategory12 4 | Category2; 5 | ;Subcategory21 6 | ;Subcategory22 7 | Category3; 8 | ;Subcategory31 9 | ;Subcategory32 10 | ;Subcategory33 11 | -------------------------------------------------------------------------------- /woocommerce-import-products-from-xml/README.md: -------------------------------------------------------------------------------- 1 | Simple script to import products into WooCommerce from XML 2 | ========= 3 | 4 | NOT A PLUGIN. 5 | Suitable for running as cron job via URL. 6 | -------------------------------------------------------------------------------- /woocommerce-import-products-from-xml/index.php: -------------------------------------------------------------------------------- 1 | import(); 11 | 12 | class ImportXml 13 | { 14 | const UPLOAD_DIR = ABSPATH.'/wp-content/uploads'; 15 | const XML_URL = 'http://www.example.sk/najnakup_xml.php?token=b354c24c9dd736ed1450b283bc682e7a'; 16 | const XML_PATH = self::UPLOAD_DIR.'/example.xml'; 17 | 18 | private $item_count; 19 | private $start; 20 | private $wpdb; 21 | 22 | public function __construct($wpdb) 23 | { 24 | if (!is_dir(self::UPLOAD_DIR)) { 25 | mkdir(self::UPLOAD_DIR); 26 | } 27 | 28 | $this->start = time(); 29 | $this->wpdb = $wpdb; 30 | 31 | $this->xml = simplexml_load_string($this->getXml(), 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE); 32 | } 33 | 34 | public function import() 35 | { 36 | foreach ($this->xml as $item) { 37 | $this->insertProduct($item); 38 | ++$this->item_count; 39 | } 40 | 41 | return sprintf('Start: %s
Items: %s
End: %s', $this->start, $this->item_count, time()); 42 | } 43 | 44 | private function getXml() 45 | { 46 | $this->updateXml(); 47 | 48 | $xml = file_get_contents(self::XML_PATH); 49 | if (empty($xml)) { 50 | throw new Exception('Empty XML'); 51 | } 52 | 53 | return $xml; 54 | } 55 | 56 | private function updateXml() 57 | { 58 | if (filemtime(self::XML_PATH) < strtotime('-1 hour')) { 59 | file_put_contents(self::XML_PATH, file_get_contents(self::XML_URL)); 60 | } 61 | } 62 | 63 | private function addProductToCategory($productId, $category) 64 | { 65 | if (empty($category)) { 66 | return; 67 | } 68 | 69 | $slug = sanitize_title($category); 70 | $category_term = get_term_by('slug', $slug, 'product_cat'); 71 | if (empty($category_term->term_id)) { 72 | $category_term = wp_insert_term($category, 'product_cat'); 73 | } 74 | if (!empty($category_term->term_id)) { 75 | wp_set_object_terms($productId, $category_term->term_id, 'product_cat'); 76 | } 77 | } 78 | 79 | private function getProductId($productId) 80 | { 81 | $sql = 'SELECT post_id FROM '.$this->wpdb->postmeta." 82 | WHERE meta_key = '_exampleid' AND meta_value = $productId LIMIT 1"; 83 | $product = $this->wpdb->get_results($sql, ARRAY_A); 84 | 85 | return isset($product[0]['post_id']) ? $product[0]['post_id'] : 0; 86 | } 87 | 88 | private function insertProduct($item) 89 | { 90 | $productId = $this->getProductId($item->ITEM_ID); 91 | if ($productId) { 92 | $this->updateProduct($productId, $item); 93 | 94 | return; 95 | } 96 | 97 | $product = array( 98 | 'post_title' => $item->NAME, 99 | 'post_content' => $item->DESCRIPTION, 100 | 'post_status' => 'publish', 101 | 'post_type' => 'product', 102 | ); 103 | $productId = wp_insert_post($product); 104 | 105 | add_post_meta($productId, '_visibility', 'visible', true); 106 | add_post_meta($productId, '_regular_price', (float) $item->PRICE); 107 | add_post_meta($productId, '_price', (float) $item->PRICE); 108 | 109 | $this->insertImage($productId, $item); 110 | $this->addProductToCategory($productId, $item->CATEGORY); 111 | $this->updateProductMeta($productId, $item); 112 | } 113 | 114 | private function updateProduct($productId, $item) 115 | { 116 | $product = array( 117 | 'ID' => $productId, 118 | 'post_title' => $item->NAME, 119 | 'post_content' => $item->DESCRIPTION, 120 | ); 121 | wp_update_post($product); 122 | 123 | $this->updateProductMeta($productId, $item); 124 | } 125 | 126 | private function updateProductMeta($productId, $item) 127 | { 128 | update_post_meta($productId, '_exampleid', (int) $item->ITEM_ID); 129 | update_post_meta($productId, '_sku', (string) $item->CODE); 130 | update_post_meta($productId, '_downloadable', 'no'); 131 | update_post_meta($productId, '_virtual', 'no'); 132 | update_post_meta($productId, '_stock_status', 'instock'); 133 | update_post_meta($productId, '_manage_stock', 'no'); 134 | } 135 | 136 | private function insertImage($productId, $item) 137 | { 138 | $img_url = (string) $item->IMAGE_URL; 139 | if ($productId > 0 && !empty($img_url)) { 140 | $http_head = get_headers($img_url); 141 | if (stripos($http_head[0], '200')) { 142 | $photo_url = $img_url; 143 | } 144 | 145 | if (!empty($photo_url)) { 146 | $image_data = file_get_contents($photo_url); 147 | if (!empty($image_data)) { 148 | $upload_dir = wp_upload_dir(); 149 | $filename = basename($photo_url); 150 | $file = $upload_dir['basedir'].'/'.$filename; 151 | if (wp_mkdir_p($upload_dir['path'])) { 152 | $file = $upload_dir['path'].'/'.$filename; 153 | } 154 | file_put_contents($file, $image_data); 155 | 156 | $wp_filetype = wp_check_filetype($filename, null); 157 | $attachment = array( 158 | 'post_mime_type' => $wp_filetype['type'], 159 | 'post_title' => sanitize_file_name($filename), 160 | 'post_content' => '', 161 | 'post_status' => 'inherit', 162 | ); 163 | $attach_id = wp_insert_attachment($attachment, $file, $productId); 164 | $attach_data = wp_generate_attachment_metadata($attach_id, $file); 165 | wp_update_attachment_metadata($attach_id, $attach_data); 166 | 167 | set_post_thumbnail($productId, $attach_id); 168 | } 169 | } 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /woocommerce-migrate-products/.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.diff 3 | *.err 4 | *.orig 5 | *.log 6 | *.rej 7 | *.swo 8 | *.swp 9 | *.vi 10 | *~ 11 | *.sass-cache 12 | ._.* 13 | 14 | sitemap.xml 15 | sitemap.xml.gz 16 | tags 17 | .DS_Store 18 | Thumbs.db 19 | .cache 20 | .project 21 | .settings 22 | .tmproj 23 | *.esproj 24 | nbproject 25 | *.sublime-project 26 | *.sublime-workspace 27 | Desktop.ini 28 | desktop.ini 29 | dwsync.xml 30 | _notes 31 | __MACOSX 32 | *.komodoproject 33 | .komodotools 34 | 35 | # Folders to ignore 36 | .hg 37 | .svn 38 | .git 39 | .CVS 40 | .idea 41 | cache/ 42 | log/ 43 | vendor/ 44 | 45 | .sucuriquarantine/ 46 | wp-admin/ 47 | wp-includes/ 48 | wc-logs/ 49 | wp-content/uploads/ 50 | wp-content/uprade/ 51 | wp-content/languages 52 | wp-content/plugins 53 | wp-content/themes/twenty*/ 54 | wp-content/plugins/hello.php 55 | .htaccess 56 | wp-activate.php 57 | wp-blog-header.php 58 | wp-comments-post.php 59 | wp-cron.php 60 | wp-links-opml.php 61 | wp-load.php 62 | wp-login.php 63 | wp-mail.php 64 | wp-settings.php 65 | wp-signup.php 66 | wp-trackback.php 67 | xmlrpc.php 68 | -------------------------------------------------------------------------------- /woocommerce-migrate-products/README.md: -------------------------------------------------------------------------------- 1 | # Migrate WooCommerce products to another Woocommerce via API 2 | 3 | **This is not a plugin**. Place it for example in `import/` dir. 4 | 5 | Uses https://github.com/woocommerce/wc-api-php 6 | 7 | You gonna need API access tokens from *WooCommerce* -> *Settings* -> *API* 8 | 9 | ![](wc-api-settings.png) 10 | 11 | More info about WooCommerce API at 12 | [https://docs.woocommerce.com/document/woocommerce-rest-api/](https://docs.woocommerce.com/document/woocommerce-rest-api/) 13 | 14 | ## Example script output 15 | ![](screenshot.jpg) 16 | -------------------------------------------------------------------------------- /woocommerce-migrate-products/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mikaelz/woocommerce-migrate-products", 3 | "description": "WooCommerce2WooCommerce product migration", 4 | "php": "^7.0", 5 | "authors": [ 6 | { 7 | "name": "Michal Zuber", 8 | "email": "info@nevilleweb.sk" 9 | } 10 | ], 11 | "license": "MIT", 12 | "keywords": ["migrate", "tool"], 13 | "require": { 14 | "automattic/woocommerce": "^1.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /woocommerce-migrate-products/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelz/wordpress-related/293ee96b9af7be98fe284f9cd1e4abc380182eba/woocommerce-migrate-products/screenshot.jpg -------------------------------------------------------------------------------- /woocommerce-migrate-products/wc-api-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikaelz/wordpress-related/293ee96b9af7be98fe284f9cd1e4abc380182eba/woocommerce-migrate-products/wc-api-settings.png -------------------------------------------------------------------------------- /woocommerce-migrate-products/woocommerce-migrate-products.php: -------------------------------------------------------------------------------- 1 | '; 47 | ob_flush(); 48 | flush(); 49 | 50 | $this->_remoteClientApi = new Client( 51 | self::REMOTE_API_URL, 52 | self::REMOTE_API_KEY, 53 | self::REMOTE_API_SECRET, 54 | [ 55 | 'wp_api' => false, 56 | 'version' => 'v3', 57 | 'timeout' => self::CURL_TIMEOUT, 58 | ] 59 | ); 60 | 61 | $this->setRemoteProductCategories(); 62 | 63 | $this->_localClientApi = new Client( 64 | self::LOCAL_API_URL, 65 | self::LOCAL_API_KEY, 66 | self::LOCAL_API_SECRET, 67 | [ 68 | 'wp_api' => false, 69 | 'version' => 'v3', 70 | 'timeout' => self::CURL_TIMEOUT, 71 | ] 72 | ); 73 | 74 | deactivate_plugins('ewww-image-optimizer/ewww-image-optimizer.php'); 75 | 76 | $this->importProducts(); 77 | 78 | $end = time(); 79 | echo sprintf( 80 | 'Import count: %s
End: %s
Took: %d s', 81 | $this->_importCount, 82 | date('d.m.Y H:i:s', $end), 83 | ($end - $start) 84 | ); 85 | 86 | activate_plugins('ewww-image-optimizer/ewww-image-optimizer.php'); 87 | } 88 | 89 | /** 90 | * Set remote product categories 91 | */ 92 | private function setRemoteProductCategories() 93 | { 94 | $response = $this->_remoteClientApi->get( 95 | 'products/categories', 96 | [ 97 | 'fields' => 'id,name' 98 | ] 99 | ); 100 | 101 | foreach ($response['product_categories'] as $category) { 102 | $this->_remoteProductCategories[$category['name']] = $category['id']; 103 | } 104 | } 105 | 106 | /** 107 | * Import products on local 108 | */ 109 | private function importProducts() 110 | { 111 | $offset = 0; 112 | do { 113 | $response = $this->_remoteClientApi->get( 114 | 'products', 115 | [ 116 | 'filter[limit]' => self::IMPORT_LIMIT, 117 | 'filter[offset]' => self::IMPORT_LIMIT * $offset++, 118 | ] 119 | ); 120 | 121 | foreach ($response['products'] as $remoteProduct) { 122 | $this->_processedCount++; 123 | $data['product'] = $this->prepData($remoteProduct); 124 | 125 | if (empty($data['product']['title'])) { 126 | continue; 127 | } 128 | 129 | $this->_localClientApi->post('products', $data); 130 | $this->_importCount++; 131 | } 132 | 133 | echo "Processed: $this->_processedCount
"; 134 | ob_flush(); 135 | flush(); 136 | } while (!empty($response['products'][0])); 137 | } 138 | 139 | /** 140 | * Prepare data 141 | * 142 | * @param array $remoteData Array of remote data 143 | * 144 | * @return array 145 | */ 146 | private function prepData($remoteProduct) 147 | { 148 | if (!empty($remoteProduct['sku']) && $this->productExists($remoteProduct['sku'])) { 149 | return []; 150 | } 151 | 152 | unset($remoteProduct['id']); 153 | unset($remoteProduct['create_at']); 154 | unset($remoteProduct['updated_at']); 155 | unset($remoteProduct['price_html']); 156 | unset($remoteProduct['related_ids']); 157 | unset($remoteProduct['upsell_ids']); 158 | unset($remoteProduct['cross_sell_ids']); 159 | unset($remoteProduct['parent_id']); 160 | unset($remoteProduct['permalink']); 161 | 162 | $remoteProduct['status'] = 'draft'; 163 | $remoteProduct['price'] = ceil($remoteProduct['price']) * 26; 164 | $remoteProduct['regular_price'] = ceil($remoteProduct['regular_price']) * 26; 165 | $remoteProduct['sale_price'] = $remoteProduct['sale_price'] > 0 ? ceil($remoteProduct['sale_price']) * 26 : ''; 166 | $remoteProduct['attributes'] = $this->translateAttributes($remoteProduct['attributes']); 167 | 168 | foreach ($remoteProduct['categories'] as $key => $categoryTitle) { 169 | $remoteProduct['categories'][$key] = $this->mapCategoryId($categoryTitle); 170 | } 171 | 172 | if (!isset($_GET['noimages']) && !empty($remoteProduct['images'][0]['src'])) { 173 | foreach($remoteProduct['images'] as $key => $image) { 174 | $remoteProduct['images'][$key] = [ 175 | 'src' => $image['src'], 176 | 'position' => $key, 177 | ]; 178 | } 179 | } 180 | 181 | foreach ($remoteProduct['variations'] as $key => $variation) { 182 | if ($this->productExists($variation['sku'])) { 183 | return []; 184 | } 185 | 186 | unset($remoteProduct['variations'][$key]['id']); 187 | unset($remoteProduct['variations'][$key]['created_at']); 188 | unset($remoteProduct['variations'][$key]['updated_at']); 189 | unset($remoteProduct['variations'][$key]['permalink']); 190 | 191 | $remoteProduct['variations'][$key]['price'] = ceil($remoteProduct['variations'][$key]['price']) * 26; 192 | $remoteProduct['variations'][$key]['regular_price'] = ceil($remoteProduct['variations'][$key]['regular_price']) * 26; 193 | $remoteProduct['variations'][$key]['attributes'] = $this->translateVariationAttributes($variation['attributes']); 194 | 195 | if (!isset($_GET['noimages']) && !empty($variation['image'][0]['src'])) { 196 | foreach ($remoteProduct['variations'][$key]['image'] as $img_key => $image) { 197 | $remoteProduct['variations'][$key]['image'][$img_key] = [ 198 | 'src' => $image['src'], 199 | 'position' => $img_key, 200 | ]; 201 | } 202 | } 203 | } 204 | 205 | return $remoteProduct; 206 | } 207 | 208 | 209 | /** 210 | * Check if products exists on local 211 | * 212 | * @param string $sku SKU identifier 213 | * 214 | * @return boolean 215 | */ 216 | private function productExists($sku) 217 | { 218 | $exists = false; 219 | $response = $this->_localClientApi->get( 220 | 'products', 221 | [ 222 | 'filter[sku]' => $sku, 223 | 'filter[post_status]' => 'any', 224 | ] 225 | ); 226 | 227 | if (!empty($response['products'][0])) { 228 | $exists = true; 229 | } 230 | 231 | return $exists; 232 | } 233 | 234 | /** 235 | * Remap category ID 236 | * 237 | * @param int $categoryTitle Category Title 238 | * 239 | * @return int 240 | */ 241 | private function mapCategoryId($categoryTitle) 242 | { 243 | $categoryId = $this->_remoteProductCategories[$categoryTitle]; 244 | 245 | $mapping = array( 246 | REMOTE_CAT_ID => LOCAL_CAT_ID, 247 | REMOTE_CAT_ID2 => LOCAL_CAT_ID2, 248 | ); 249 | 250 | return $mapping[$categoryId] ?? 0; 251 | } 252 | 253 | /** 254 | * Translate attributes 255 | * 256 | * @return array $attributes 257 | */ 258 | private function translateAttributes($attributes) 259 | { 260 | foreach ($attributes as $key => $attribute) { 261 | switch ($attribute['name']) { 262 | case 'Attribute name': 263 | $attributes[$key]['name'] = 'New Attribute name'; 264 | $attributes[$key]['slug'] = 'new-attribute-name'; 265 | $attributes[$key]['options'] = $this->translateAttribOptions($attribute['options']); 266 | break; 267 | } 268 | } 269 | 270 | return $attributes; 271 | } 272 | 273 | /** 274 | * Translate attribute options 275 | * 276 | * @return array $options 277 | */ 278 | private function translateAttribOptions($options) 279 | { 280 | $from = [ 281 | 'Option1', 282 | 'Option2', 283 | ]; 284 | 285 | $to = [ 286 | 'New Option1', 287 | 'New Option2', 288 | ]; 289 | 290 | foreach ($options as $key => $value) { 291 | $options[$key] = str_replace($from, $to, $value); 292 | } 293 | 294 | return $options; 295 | } 296 | 297 | /** 298 | * Translate variation attributes 299 | * 300 | * @return array $attributes 301 | */ 302 | private function translateVariationAttributes($attributes) 303 | { 304 | foreach ($attributes as $key => $attribute) { 305 | switch ($attribute['name']) { 306 | case 'Attribute name': 307 | $attributes[$key]['name'] = 'New Attribute name'; 308 | $attributes[$key]['slug'] = 'new-attribute-name'; 309 | $attributes[$key]['option'] = $this->translateVariationAttribOptions($attribute['option']); 310 | break; 311 | } 312 | } 313 | 314 | return $attributes; 315 | } 316 | 317 | 318 | /** 319 | * Translate variation attribute option 320 | * 321 | * @return array $option 322 | */ 323 | private function translateVariationAttribOptions($option) 324 | { 325 | $from = [ 326 | 'slug1', 327 | 'slug2', 328 | ]; 329 | 330 | $to = [ 331 | 'new-slug1', 332 | 'new-slug2', 333 | ]; 334 | 335 | return str_replace($from, $to, $option); 336 | } 337 | } 338 | 339 | return new MigrateProducts(); 340 | -------------------------------------------------------------------------------- /woocommerce-no-cod-for-virtual/woocommerce-no-cod-for-virtual.php: -------------------------------------------------------------------------------- 1 | cart->cart_contents as $item ) { 46 | $product_id = $item['product_id']; 47 | if ( isset( $item['variation_id'] ) && $item['variation_id'] > 0 ) { 48 | $product_id = $item['variation_id']; 49 | } 50 | $product = wc_get_product( $product_id ); 51 | 52 | $is_virtual = get_post_meta( $product_id, '_virtual', true ); 53 | if ( 'yes' === $is_virtual ) { 54 | $reposnse = true; 55 | break; 56 | } 57 | 58 | $is_downloadable = get_post_meta( $product_id, '_downloadable', true ); 59 | if ( 'yes' === $is_downloadable ) { 60 | $reposnse = true; 61 | break; 62 | } 63 | } 64 | 65 | return $reposnse; 66 | } 67 | -------------------------------------------------------------------------------- /woocommerce-optional-advance-pay/OptionalAdvancePay.php: -------------------------------------------------------------------------------- 1 | cart->cart_contents as $item) { 32 | $product_id = $item['product_id']; 33 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { 34 | $product_id = $item['variation_id']; 35 | } 36 | $product = new \WC_Product_Factory(); 37 | $product = $product->get_product($product_id); 38 | if ($item['quantity'] > $product->get_stock_quantity()) { 39 | $inStock = false; 40 | break; 41 | } 42 | } 43 | 44 | return $inStock; 45 | } 46 | 47 | public function editPaymentGateways($available_gateways) 48 | { 49 | if (!$this->isInStock()) { 50 | unset($available_gateways['bacs']); 51 | unset($available_gateways['paypal']); 52 | } 53 | 54 | return $available_gateways; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /woocommerce-optional-advance-pay/README.md: -------------------------------------------------------------------------------- 1 | # WooCommerce Optional Advance Pay 2 | 3 | Enable advance pay (BACS), PayPal and card payment **if all cart quantity is available in stock**. 4 | *Payments need to be enabled*. Plugin only removes enabled payments if product 5 | is not in stock (backorderable). 6 | 7 | Developed on WordPress 4.4.2 and WooCommerce 2.4.12 8 | -------------------------------------------------------------------------------- /woocommerce-optional-advance-pay/woocommerce-optional-advance-pay.php: -------------------------------------------------------------------------------- 1 | get_upsells()) { 22 | return $message; 23 | } 24 | 25 | $args = array( 26 | 'post_type' => 'product', 27 | 'ignore_sticky_posts' => 1, 28 | 'no_found_rows' => 1, 29 | 'posts_per_page' => 3, 30 | 'orderby' => 'rand', 31 | 'post__in' => $upsells, 32 | 'post__not_in' => array($product_id), 33 | 'meta_query' => WC()->query->get_meta_query(), 34 | ); 35 | 36 | $products = new WP_Query($args); 37 | $woocommerce_loop['name'] = 'up-sells'; 38 | $woocommerce_loop['columns'] = apply_filters('woocommerce_up_sells_columns', 3); 39 | 40 | if (!$products->have_posts()) { 41 | return $message; 42 | } 43 | 44 | $message .= '
'; 45 | 46 | ob_start(); 47 | ?> 48 |
49 |

50 | have_posts()) { 54 | $products->the_post(); 55 | wc_get_template_part('content', 'product'); 56 | } 57 | 58 | woocommerce_product_loop_end(); 59 | ?> 60 |
61 |