Changeset 2932041
- Timestamp:
- 06/29/2023 02:40:45 AM (3 years ago)
- Location:
- very-simple-woocommerce-upsell-popup/trunk
- Files:
-
- 2 edited
-
README.txt (modified) (1 diff)
-
index.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
very-simple-woocommerce-upsell-popup/trunk/README.txt
r2866829 r2932041 1 1 === Woocommerce Upsell / cross sell Popup plugin=== 2 3 2 4 Contributors: upsellpopup 5 6 3 7 Donate link: https://woocommerce.upsellpopup.com/ 8 9 4 10 Tags: ross sell, upsell, popup, up sell, related products, add to cart popup, added to cart popup, modal, add to cart, cross-sell, cross sell popup 11 12 5 13 Requires at least: 5.0.0 14 15 6 16 Tested up to: 6.1.1 7 Stable tag: 1.8.7 17 18 19 Stable tag: 1.8.9 20 21 8 22 License: GPLv3 23 24 9 25 License URI: https://www.gnu.org/licenses/gpl-3.0.html 10 26 27 28 29 30 11 31 Two in One upsell and cross sell popup plugin for Woocommerce. Show non-intrusive, responsive popup to your visitors when they click add to cart button. This plugin may be useful for store owners who want a simple and lightweight plugin to recommend product B when user buys product A. 12 32 33 34 35 36 13 37 == Description == 14 38 39 40 41 42 15 43 [PRO Live Demo](https://demo.upsellpopup.com/) 16 44 45 46 47 48 17 49 An upsell & cross sell popup plugin for Woocommerce. Show non-intrusive, responsive popup to your visitors when they click the add to cart button on the products you specify. 18 50 51 52 53 54 19 55 This plugin may be useful for store owners who want a simple and lightweight plugin to recommend product B when user buys product A. The cross will help sell different product categories and the upsell will improve your AOV cart basket size 56 57 20 58 One click add to cart with option to add quanitites and several features. Plugin is trusted by more than 40,000 customers so far, highly rated in wordpress. 21 59 60 61 62 63 22 64 This plugin is an extension of the [Woocommerce](https://wordpress.org/plugins/woocommerce/) plugin. You must have Woocommerce active alongside this plugin for it to work properly. 23 65 66 67 68 69 24 70 - Tested with Woocommerce version 6.0.0 up to the latest version 7.2.2. 71 72 25 73 - This plugin is compatible with PHP 7! 26 74 75 76 77 78 27 79 ## What Does It Do 28 80 81 82 83 84 29 85 * When a user clicks on the 'add to cart' button on a product you specify, the product will be added to cart and a yes/no popup will be shown asking if the user is also interested in a complementary product (configurable). 30 86 87 88 89 90 31 91 * For complementary product that the product type is **SIMPLE**: If the user clicks yes, the complementary product will also be added to cart. 32 92 93 94 95 96 33 97 * For complementary product that the product type is **VARIABLE**: If the user clicks yes, you can choose whether to redirect your user to the complementary product's product page, OR to let your user choose a variant on the popup and add that variant to cart without navigating away from popup. 34 98 99 100 101 102 35 103 * After the product you upsell & cross sell is added to user's cart, you can choose whether to redirect user to cart page, checkout page, or make them stay on the same page. 36 104 105 106 107 108 37 109 * If the user clicks no, you can also choose to redirect the user to cart page, checkout page, or stay on the same page. 38 110 111 112 113 114 39 115 * Popup will fire when user adds a product to cart from shop page, product category page, or single product page. 40 116 117 118 119 120 41 121 * **(NEW!)** Now you can easily turn AJAX on and off for add to cart button on single product pages! 42 122 123 124 125 126 43 127 Please refer to screenshots for pre-made templates included in the plugin. 44 128 129 130 131 132 45 133 ### Woocommerce Settings 46 134 135 136 137 138 47 139 For the plugin to work as intended, set the Woocommerce setting as follows: 48 140 141 142 143 144 49 145 Go to *Woocommerce > Settings > Products > General > Shop pages*. 50 146 147 148 149 150 51 151 And then for ***'Add to cart behaviour'***, uncheck *'Redirect to the cart page after successful addition'*. 52 152 153 154 155 156 53 157 AJAX can be enabled or disabled for add to cart buttons on archives, popups will fire regardless. 54 158 159 160 161 162 55 163 ### Woocommerce Upsell Popup PRO 56 164 165 166 167 168 57 169 Get the [PRO version](https://woocommerce.upsellpopup.com/woocommerce-upsell-popup-pro-plugin/) to have more control of your popups! 58 170 171 172 173 174 59 175 [ [LIVE DEMO!](https://demo.upsellpopup.com/) ] 60 176 177 178 179 180 61 181 **What you can do with our PRO version:** 62 182 183 184 185 186 63 187 - Customize and change the text on your popups! 188 189 64 190 - Change the text on the popup buttons! 191 192 65 193 - Customizable popup templates! 194 195 66 196 - Create your own popup template, and create as many popup templates as you want! 197 198 67 199 - Upsell & cross sell multiple products per popup. 200 201 68 202 - Show upsell and cross-sell product prices on your popup. 203 204 69 205 - Your users will be able to add multiple products to cart from your popup with a click of a button. 206 207 70 208 - You can create "Frequently bought together with..." popup and show as many products on the popup as you like. 209 210 71 211 - An option to show "Complete the look" or "Shop the look" concept to encourage your users to buy more items. 72 212 213 214 215 216 73 217 Read plugin documentation [here](https://woocommerce.upsellpopup.com/documentations/). 74 218 219 220 221 222 75 223 ### Translation Ready 76 224 225 226 227 228 77 229 The plugin is ready to be translated to your local language, .pot file is included in `/languages` folder. 78 230 231 232 233 234 79 235 ### Support 80 236 237 238 239 240 81 241 Please use WordPress.org forum to ask for support, to submit bug reports, to ask questions about the free plugin, or to suggest a new feature. 82 242 243 244 245 246 83 247 Only use the [contact form](https://woocommerce.upsellpopup.com/contact/) on our website if you're inquiring about the PRO version. 84 248 249 250 251 252 85 253 == Installation == 86 254 255 256 257 258 87 259 1. Upload plugin folder to `/wp-content/plugins/` directory, or install the plugin from your WordPress dashboard `Plugins>Add New`. 260 261 88 262 2. Activate the plugin. 263 264 89 265 3. Go to Woocommerce product edit page and start configuring your upsell or cross sell popup. 90 266 267 268 269 270 91 271 == Frequently Asked Questions == 92 272 273 274 275 276 93 277 = Something is not working! Is there a quick fix? = 94 278 279 280 281 282 95 283 Here's what you could try: 96 284 285 286 287 288 97 289 Go to *Woocommerce > Upsell Popup > General*. 98 290 291 292 293 294 99 295 Here you will see an option to turn off AJAX. Tick the box that says ***'Turn off AJAX on single product pages'***. 100 296 297 298 299 300 101 301 This didn't fix your issue? Here are other things you could try to fix your issue: [Quick Fix](https://woocommerce.upsellpopup.com/docs/woocommerce-upsell-popup-pro-docs/quick-fix-to-most-issues/). 102 302 303 304 305 306 103 307 = How can I customize the popups to have the look and style that I want? = 104 308 309 310 311 312 105 313 If you know CSS, choose ***Template 4 - No CSS*** for your popup and then you can drop your CSS codes in your child theme's stylesheet to style the popup as you like. 106 314 315 316 317 318 107 319 = How can I customize the text on the popups? = 108 320 321 322 323 324 109 325 There are 2 ways to do so. 326 327 110 328 1. You can use localization (translation) or `gettext` hook to change the text. 329 330 111 331 2. Or you can get our [PRO version](https://woocommerce.upsellpopup.com/woocommerce-upsell-popup-pro-plugin/) to customize the text on your popups and better - make your own templates! 112 332 333 334 335 336 113 337 = How can I change the Yes/No text on the popup buttons? = 114 338 339 340 341 342 115 343 Same as above. There are 2 ways to do so. 344 345 116 346 1. You can use localization (translation) or `gettext` hook to change the text. 347 348 117 349 2. Or you can get our [PRO version](https://woocommerce.upsellpopup.com/woocommerce-upsell-popup-pro-plugin/) in which you will have the option to change the Yes/No text on your popup buttons easily. 118 350 351 352 353 354 119 355 = Can I upsell /cross sell more than one product on my popup? = 120 356 357 358 359 360 121 361 You can do so with our [PRO version](https://woocommerce.upsellpopup.com/woocommerce-upsell-popup-pro-plugin/). 122 362 363 364 365 366 123 367 = Does this plugin support Woocommerce native upsell and cross sell products? = 124 368 369 370 371 372 125 373 Our [PRO version](https://woocommerce.upsellpopup.com/woocommerce-upsell-popup-pro-plugin/) supports Woocommerce native upsell and cross sell products (Woocommerce Linked Products). See this [documentation page](https://woocommerce.upsellpopup.com/docs/woocommerce-upsell-popup-pro-docs/setting-up-upsell-products/). 126 374 375 376 377 378 127 379 = Can I translate this plugin to my language? = 128 380 381 382 383 384 129 385 Yes, this plugin is translation ready, `.pot` file is included in the `/languages` folder. 130 386 387 388 389 390 131 391 == Screenshots == 132 392 393 394 395 396 133 397 1. Default popup template. 398 399 134 400 2. Popup template for VARIABLE upsell product. 401 402 135 403 3. Popup template (Basic). 404 405 136 406 4. Popup template (Colorful). 407 408 137 409 5. Popup template (Dark on Light). 410 411 138 412 6. Upsell popup options on Woocommerce product edit screen. 413 414 139 415 7. Main setting page. 140 416 417 == Changelog = 418 419 == 1.8.9 = 420 421 * Compatibility check with latest wordpress version 6.2.2. 422 423 == Changelog === 1.8.8 = 424 425 * Compatibility check with latest wordpress version. 426 427 428 141 429 == Changelog === 1.8.7 = 430 431 142 432 * Compatibility check with latest php version 8.0.28. 143 433 434 435 436 437 144 438 == Changelog === 1.8.6 = 439 440 145 441 * Color picker issue fixed 146 442 443 444 445 446 147 447 == Changelog === 1.8.5 = 448 449 148 450 * Deployment issue fixed 149 451 452 453 454 455 150 456 == Changelog === 1.8.4 = 457 458 151 459 * Additional comments added 152 460 461 462 463 464 153 465 == Changelog === 1.8.3 = 466 467 154 468 * Compatibility check with latest wordpress version. 155 469 470 471 472 473 156 474 == Changelog === 1.8.2 = 475 476 157 477 * Compatibility check with pro version. 158 478 479 480 481 482 159 483 == Changelog === 1.8.1 = 484 485 160 486 * Coupon code and button color change options 161 487 488 489 490 491 162 492 == Changelog === 1.8.0 = 493 494 163 495 * Reference screenshot added 164 496 497 498 499 500 165 501 == Changelog === 1.7.9 = 502 503 166 504 * Option to display discount coupon code 167 505 506 507 508 509 168 510 == Changelog === 1.7.8 = 511 512 169 513 * Compatibility test and fix with wordpress version 6.0. 170 514 515 516 517 518 171 519 = 1.7.7 = 520 521 172 522 * Quantity options and cart price auto update added. 173 523 524 525 526 527 174 528 = 1.7.6 = 529 530 175 531 * Multiple quantity options for upsell product global setting for upsell products. 176 532 533 534 535 536 177 537 = 1.7.4 = 538 539 178 540 * Woocommerce compatibility. 179 541 542 543 544 545 180 546 = 1.7.3 = 547 548 181 549 * Fixed headers already sent warning when ajax is disabled for add to cart buttons. 182 550 551 552 553 554 183 555 = 1.7.2 = 556 557 184 558 * Variable Upsell popup template became the new default popup template. The old Variable Upsell template stays unchanged. 559 560 185 561 * Updated language file. 186 562 563 564 565 566 187 567 = 1.7.1 = 568 569 188 570 * Fixed bug found in previous two releases. 571 572 189 573 * Fixed bug for action removal at init hook, added conditional statements accordingly. 190 574 575 576 577 578 191 579 = 1.7.0 = 580 581 192 582 * Restored Quadlayers ajax add to cart script as default AJAX script for single product pages. 583 584 193 585 * Added ability for users to switch between Quadlayers ajax script and native Woocommerce handler. 586 587 194 588 * Updated language file. 195 589 590 591 592 593 196 594 = 1.6.0 = 595 596 197 597 * Replaced Quadlayers ajax add to cart script, now using Woocommerce native handler, fixing certain product types not correctly adding to cart issue. 598 599 198 600 * Fixed redirection behavior bug for the NO buttons when AJAX is turned off on single product pages. 601 602 199 603 * Disabled out of stock variant from being selected on variable upsell template. 604 605 200 606 * Added validation check for variable upsell template, warning shown if no option is selected. 607 608 201 609 * Updated language file. 202 610 611 612 613 614 203 615 = 1.5.0 = 616 617 204 618 * Added an option to let user choose whether to use AJAX or no AJAX for add to cart button on single product pages. AJAX is still enabled by default. 619 620 205 621 * Fixed certain product types not adding to cart (only without AJAX add to cart button). 622 623 206 624 * Added support for LearnDash LMS (Woocommerce integration) course product type. 625 626 207 627 * Updated language file. 208 628 629 630 631 632 209 633 = 1.4.1 = 634 635 210 636 * Added a new template for variable upsell product to enable user to choose variant on popup without navigating away. 637 638 211 639 * Fixed loading spinner overlay not covering whole popup (css fix). 640 641 212 642 * All links changed to the new plugin website. 213 643 644 645 646 647 214 648 = 1.4.0 = 649 650 215 651 * New plugin structure, revised how popup is called on single product page. 652 653 216 654 * Added AJAX to add to cart button on single product page by default for faster loading of popup. 655 656 217 657 * Fixed headers already sent error on single product page. 658 659 218 660 * Added a new template (Template 2) to PRO template selection. 661 662 219 663 * Updated language file. 220 664 665 666 667 668 221 669 = 1.3.1 = 670 671 222 672 * Removed font family in default popup template so that default font in user's theme will be used. 673 674 223 675 * Additional checks added for admin_init hook when checking for pro compatibility. 676 677 224 678 * Added a new link on documentation tab settings. 225 679 680 681 682 683 226 684 = 1.3.0 = 685 686 227 687 * Global and product category setting page added to make it easier for store owners to manage hundreds or thousands of products, either by category or by store-wide. 688 689 228 690 * Implemented tabs for cleaner settings UI, added new support and documentation page. 691 692 229 693 * Moved functions related to metabox and global setting page to separate files for better maintenance. 694 695 230 696 * Changed free/pro structure, only pro version 1.1.2 and above are compatible with this version. 697 698 231 699 * Updated language file. 232 700 701 702 703 704 233 705 = 1.2.3 = 706 707 234 708 * Improved security and sanitization for metabox user input. 709 710 235 711 * Maintained compatibilty with pro version. 236 712 713 714 715 716 237 717 = 1.2.2 = 718 719 238 720 * Removed out of stock upsell products from being displayed on popups. 721 722 239 723 * Improved the handling of variations at popup level. 724 725 240 726 * Now only published product and active product variations get shown on popups. 241 727 728 729 730 731 242 732 = 1.2.1 = 733 734 243 735 * Added url validation and sanitization before redirection. 736 737 244 738 * Removed unnecessary conditions check where no actions happens. 245 739 740 741 742 743 246 744 = 1.2.0 = 745 746 247 747 * Reverted most functionalities back to v0.6, making the plugin leaner and more lightweight than v1.0.0 to v1.1.0. 748 749 248 750 * Removed some features to avoid option clutter and to focus on original key features. Complete features can be found on the PRO version. Only upgrade if you don't mind this. 751 752 249 753 * Removed unnecessary ajax loading spinner on page load. 754 755 250 756 * Added check for version compatibilty between this plugin and its pro extension. Terminate activation if not compatible. 757 758 251 759 * Updated i18n. 252 760 761 762 763 764 253 765 = 1.1.0 = 766 767 254 768 * Added complete-the-look section to default popup template for multiple upsell products. 769 770 255 771 * Maintained compatibilty with pro version. 256 772 773 774 775 776 257 777 = 1.0.1 = 778 779 258 780 * Fixed uncaught error caused by deleted upsell products, added check for published product and product post type. 259 781 782 783 784 785 260 786 = 1.0.0 = 787 788 261 789 * Added support for multiple upsell products per popup. 790 791 262 792 * Added default template for multiple upsell products popup, making use of Flickity carousel. 793 794 263 795 * Implemented better UX design for multiple upsell products popup, default template shows product prices and total price of products selected. 796 797 264 798 * Default template for single upsell popup was improved to include upsell product price and made to match default template for multiple upsell popup. 799 800 265 801 * Added support for Woocommerce native Linked Products upsells and cross sells. 802 803 266 804 * Backward compatibilty support added for our classic upsell product meta field. 805 806 267 807 * Improved product meta box UI and UX. 808 809 268 810 * JS and CSS files are now minified. 811 812 269 813 * Maintained responsiveness of popup templates. 814 815 270 816 * Added loading spinner for ajax actions on popups. 817 818 271 819 * Prevented popups from firing consecutively after the first popup's added to cart action. 820 821 272 822 * Init hook changed to wp_loaded hook for non-ajax popup actions, preventing headers already sent error. 273 823 824 825 826 827 274 828 = 0.6 = 829 830 275 831 * Added an option to change redirection behavior of the popup's no button. 832 833 276 834 * Improved how plugin product meta data are saved. 835 836 277 837 * Improved security. 838 839 278 840 * Added version check for pro add-on. 841 842 279 843 * Templates text change. 280 844 845 846 847 848 281 849 = 0.5 = 850 851 282 852 * Added new option for user to change redirection behavior of popups. 853 854 283 855 * Added new template as default template. 856 857 284 858 * Improved il8n on templates. 859 860 285 861 * Modified styles on templates. 286 862 863 864 865 866 287 867 = 0.4 = 868 869 288 870 * Added support for PRO version. 871 872 289 873 * Updated translation. 290 874 875 876 877 878 291 879 = 0.3 = 880 881 292 882 * Added support for internationalization/i18n/translation. 883 884 293 885 * Localization to Bahasa Melayu. 294 886 887 888 889 890 295 891 = 0.2 = 892 893 296 894 * Popups are now compatible to be used with add to cart buttons that use AJAX. 895 896 297 897 * Added another plugin dependency check. Plugin activation fails if Woocommerce is not activated. 898 899 298 900 * Form in popup templates now has an ID. 299 901 902 903 904 905 300 906 = 0.1 = 907 908 301 909 * Initial release. 302 910 911 912 913 914 303 915 == Upgrade Notice == 304 916 917 918 919 920 305 921 = 1.7.4 = 922 923 306 924 * Woocommerce compatibility. 307 925 926 927 928 929 308 930 = 1.7.6 = 931 932 309 933 * Multiple quantity options for upsell product global setting for upsell products. 310 934 935 936 937 938 311 939 = 1.7.7 = 940 941 312 942 * Quantity options and cart price auto update added. 313 943 944 945 946 947 314 948 == Changelog === 1.7.9 = 949 950 315 951 * Option to display discount coupon code 316 952 953 954 955 956 317 957 == Changelog === 1.8.0 = 958 959 318 960 * Reference screenshot added -
very-simple-woocommerce-upsell-popup/trunk/index.php
r2866829 r2932041 1 1 <?php 2 3 2 4 /** 5 6 3 7 * Plugin Name: Woocommerce Upsell Popup 8 9 4 10 * Plugin URI: https://woocommerce.upsellpopup.com/ 11 12 5 13 * Description: An upsell & cross-sell popup plugin for Woocommerce. Show unobtrusive and responsive popup to your visitors when they click add to cart button. 6 * Version: 1.8.7 14 15 16 * Version: 1.8.9 17 18 7 19 * Author: Upsell Popup 20 21 8 22 * Author URI: https://woocommerce.upsellpopup.com/ 23 24 9 25 * WC requires at least: 6.0.0 26 27 10 28 * WC tested up to: 7.2.2 29 30 11 31 * Text Domain: very-simple-woocommerce-upsell-popup 32 33 12 34 */ 13 35 36 37 38 39 14 40 if ( ! defined( 'ABSPATH' ) ) exit; 41 42 15 43 define('thp-wc-upsell-popup-frzn', TRUE); 16 44 45 46 47 48 17 49 include ( 'wup-options.php' ); 50 51 18 52 include ( 'wup-metabox.php' ); 53 54 19 55 include ( 'wup-noajax.php' ); 20 56 57 58 59 60 21 61 $thp_addtocart_popup_btn = false; 22 62 63 64 65 66 23 67 function thp_wuppro_active() { 68 69 24 70 if ( ! function_exists('is_plugin_active')) { 71 72 25 73 require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 26 } 27 74 75 76 } 77 78 79 80 81 28 82 if( is_plugin_active( 'woocommerce-upsell-popup-pro/index.php' ) ) { 83 84 29 85 return true; //pro version is active 30 } 86 87 88 } 89 90 31 91 return false; 92 93 32 94 } 33 95 96 97 98 99 34 100 if (thp_wuppro_active()) { 101 102 35 103 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/wuppro-metabox.php' ); 104 105 36 106 } 37 107 38 108 109 110 111 112 113 114 39 115 function thp_woocommerce_inactive() { 116 117 40 118 if ( ! function_exists('is_plugin_inactive')) { 119 120 41 121 require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); 42 } 43 122 123 124 } 125 126 127 128 129 44 130 if( is_plugin_inactive( 'woocommerce/woocommerce.php' ) ) { 131 132 45 133 return true; //woocommerce is inactive 46 } 134 135 136 } 137 138 47 139 return false; 140 141 48 142 } 49 143 50 144 145 146 147 148 149 150 51 151 function thp_wc_upsell_dependency_check() { 152 153 52 154 if ( thp_woocommerce_inactive() ) { 155 156 53 157 add_action( 'admin_notices', 'thp_wc_upsell_dep_warning' ); 158 159 54 160 return; 55 } 56 161 162 163 } 164 165 166 167 168 57 169 load_plugin_textdomain( 'very-simple-woocommerce-upsell-popup', false, basename( dirname( __FILE__ ) ) . '/languages' ); 170 171 58 172 } 173 174 59 175 add_action( 'plugins_loaded', 'thp_wc_upsell_dependency_check' ); 60 176 61 177 178 179 180 181 182 183 62 184 function thp_wc_upsell_dep_warning() { 185 186 63 187 ?> 188 189 64 190 <div class="notice notice-error"> 191 192 65 193 <p><?php _e( "Woocommerce Upsell Popup requires Woocommerce in order for it to work properly!", 'very-simple-woocommerce-upsell-popup' ); ?></p> 194 195 66 196 </div> 197 198 67 199 <?php 200 201 68 202 } 69 203 70 204 205 206 207 208 209 210 71 211 function thp_wc_upsell_activation_check() { 72 212 213 214 215 216 73 217 if ( thp_woocommerce_inactive() ) { 218 219 74 220 deactivate_plugins( plugin_basename( __FILE__ ) ); 221 222 75 223 wp_die( __( "Woocommerce Upsell Popup requires Woocommerce to be active. Please install and activate Woocommerce before trying to activate this plugin again.", 'very-simple-woocommerce-upsell-popup' ) ); 76 } 224 225 226 } 227 228 77 229 } 230 231 78 232 register_activation_hook( __FILE__, 'thp_wc_upsell_activation_check' ); 79 233 80 234 235 236 237 238 239 240 81 241 function thp_wuppro_compatibility_check() { 82 242 243 244 245 246 83 247 if ( (current_user_can('activate_plugins')) && (!wp_doing_ajax()) ) { 248 249 84 250 if ( thp_wuppro_active() ) { 251 252 85 253 $thp_wuppro_at_least = '1.1.2'; 86 254 255 256 257 258 87 259 $thp_wuppro_data = get_plugin_data( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/index.php', false, false ); 260 261 88 262 $thp_wuppro_user_v = $thp_wuppro_data['Version']; 89 263 264 265 266 267 90 268 if ( version_compare($thp_wuppro_user_v, $thp_wuppro_at_least, '<') ) { 91 269 270 271 272 273 92 274 deactivate_plugins( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/index.php' ); 93 275 276 277 278 279 94 280 $url = 'https://woocommerce.upsellpopup.com/my-account/'; 95 281 282 283 284 285 96 286 $notice_string = sprintf( wp_kses( __( 'The latest version of Woocommerce Upsell Popup is only compatible with Woocommerce Upsell Popup PRO version 1.1.2 or later. Please upgrade PRO to latest version!<br /><br /> Login to <a href="%s" target="_blank" rel="noopener noreferrer">your account</a> to download the latest version of Woocommerce Upsell Popup PRO.', 'very-simple-woocommerce-upsell-popup' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ), 'br' => array() ) ), esc_url( $url ) ); 97 287 288 289 290 291 98 292 wp_die( $notice_string ); 293 294 99 295 exit; 100 } 101 } 296 297 298 } 299 300 301 } 302 303 102 304 } 305 306 103 307 } 308 309 104 310 add_action( 'admin_init', 'thp_wuppro_compatibility_check' ); 105 311 106 312 313 314 315 316 317 318 107 319 function thp_wuppro_version_check() { 320 321 108 322 if ( thp_wuppro_active() ) { 323 324 109 325 $thp_wuppro_latest_v = '1.1.2'; 110 326 327 328 329 330 111 331 $thp_wuppro_data = get_plugin_data( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/index.php', false, false ); 332 333 112 334 $thp_wuppro_user_v = $thp_wuppro_data['Version']; 113 335 336 337 338 339 114 340 if ( version_compare($thp_wuppro_user_v, $thp_wuppro_latest_v, '<') ) { 341 342 115 343 $url = 'https://woocommerce.upsellpopup.com/my-account/'; 344 345 116 346 $notice_string = sprintf( wp_kses( __( 'There is a new update available for Woocommerce Upsell Popup Pro. Please login to <a href="%s" target="_blank" rel="noopener noreferrer">your account</a> to download the latest version.', 'very-simple-woocommerce-upsell-popup' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array() ) ) ), esc_url( $url ) ); 347 348 117 349 echo '<div class="notice notice-warning is-dismissible">'; 350 351 118 352 echo '<p>'.$notice_string.'</p>'; 353 354 119 355 echo '</div>'; 120 } 121 } 356 357 358 } 359 360 361 } 362 363 122 364 } 365 366 123 367 add_action('admin_notices', 'thp_wuppro_version_check'); 124 368 125 369 370 371 372 373 374 375 126 376 function thp_wup_settings_link( $links ) { 377 378 127 379 $settings_link = '<a href="'.esc_url( get_admin_url(null, 'admin.php?page=thp-wup-main-settings') ).'">' . 380 381 128 382 esc_html( __( 'Settings', 'very-simple-woocommerce-upsell-popup' ) ) . '</a>'; 129 383 384 385 386 387 130 388 return array_merge( array( $settings_link ), $links ); 389 390 131 391 } 392 393 132 394 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'thp_wup_settings_link' ); 133 395 134 396 397 398 399 400 401 402 135 403 function thp_popup_frontend_scripts () { 404 405 136 406 if (!thp_wuppro_active()) { 137 407 408 409 410 411 138 412 $ajax_enabled = get_option( 'woocommerce_enable_ajax_add_to_cart' ); 139 413 414 415 416 417 140 418 if ( is_shop() || is_product_category() ) { 419 420 141 421 if ( 'yes' === $ajax_enabled ) { 422 423 142 424 wp_enqueue_script( 'thp-popup-js', plugin_dir_url( __FILE__ ).'js/wup-ajax.min.js', array('jquery'), '', false ); 425 426 143 427 wp_localize_script( 'thp-popup-js', 'thp_popup_vars', array( 428 429 144 430 'ajaxurl' => admin_url( 'admin-ajax.php' ), 431 432 145 433 'added_to_cart' => __( 'Added to Cart!', 'very-simple-woocommerce-upsell-popup' ), 434 435 146 436 'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' ) 437 438 147 439 ) 440 441 148 442 ); 443 444 149 445 wp_enqueue_script( 'wup-noajax-js', plugin_dir_url( __FILE__ ).'js/wup-noajax.min.js', array('jquery'), '', false ); 150 } 446 447 448 } 449 450 151 451 else { 452 453 152 454 wp_enqueue_script( 'wup-noajax-js', plugin_dir_url( __FILE__ ).'js/wup-noajax.min.js', array('jquery'), '', false ); 455 456 153 457 wp_localize_script( 'wup-noajax-js', 'wup_noajax_js_vars', array( 458 459 154 460 'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' ) 461 462 155 463 ) 464 465 156 466 ); 157 } 158 } 467 468 469 } 470 471 472 } 473 474 159 475 elseif ( is_product() ) { 160 476 477 478 479 480 161 481 $wup_options = ( !empty(get_option( 'thp_wup_options' )) ? get_option( 'thp_wup_options' ) : '' ); 482 483 162 484 $ajax_off = ( !empty($wup_options['ajax_off']) ? $wup_options['ajax_off'] : '' ); 163 485 486 487 488 489 164 490 if (!$ajax_off) { //ajax enabled 491 492 165 493 494 495 166 496 wp_enqueue_script( 'thp-popup-js', plugin_dir_url( __FILE__ ).'js/wup-ajax.min.js', array('jquery'), '', false ); 497 498 167 499 wp_localize_script( 'thp-popup-js', 'thp_popup_vars', array( 500 501 168 502 'ajaxurl' => admin_url( 'admin-ajax.php' ), 503 504 169 505 'added_to_cart' => __( 'Added to Cart!', 'very-simple-woocommerce-upsell-popup' ), 506 507 170 508 'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' ) 509 510 171 511 ) 512 513 172 514 ); 515 516 173 517 518 519 174 520 wp_enqueue_script( 'wup-noajax-js', plugin_dir_url( __FILE__ ).'js/wup-noajax.min.js', array('jquery'), '', false ); 521 522 175 523 524 525 176 526 $use_wc_ajax = ( !empty($wup_options['use_wc_ajax']) ? $wup_options['use_wc_ajax'] : '' ); 527 528 177 529 530 531 178 532 if ( (!$use_wc_ajax) && (!wp_script_is( 'woo-ajax-add-to-cart', 'enqueued' )) ) //uses quadlayers 533 534 179 535 wp_enqueue_script( 'woo-ajax-add-to-cart', plugin_dir_url( __FILE__ ).'js/quadlayers-ajax-add-to-cart.min.js', array('jquery', 'wc-add-to-cart'), '', true ); 536 537 180 538 elseif ($use_wc_ajax) //uses wc 539 540 181 541 wp_enqueue_script( 'wup-woo-ajax-add-to-cart', plugin_dir_url( __FILE__ ).'js/ajaxified.min.js', array('jquery', 'wc-add-to-cart'), '', true ); 182 } 542 543 544 } 545 546 183 547 elseif ($ajax_off) { //ajax disabled 548 549 184 550 wp_enqueue_script( 'wup-noajax-js', plugin_dir_url( __FILE__ ).'js/wup-noajax.min.js', array('jquery'), '', false ); 551 552 185 553 wp_localize_script( 'wup-noajax-js', 'wup_noajax_js_vars', array( 554 555 186 556 'choose_one' => __( 'Please choose one option!', 'very-simple-woocommerce-upsell-popup' ) 557 558 187 559 ) 560 561 188 562 ); 189 } 190 } 191 } 563 564 565 } 566 567 568 } 569 570 571 } 572 573 192 574 } 575 576 193 577 add_action( 'wp_enqueue_scripts', 'thp_popup_frontend_scripts' ); 194 578 195 579 580 581 582 583 584 585 196 586 function thp_wup_ajax_add_to_cart_handler() { 587 588 197 589 WC_Form_Handler::add_to_cart_action(); 590 591 198 592 WC_AJAX::get_refreshed_fragments(); 593 594 199 595 } 596 597 200 598 add_action( 'wc_ajax_thp_wup_add_to_cart', 'thp_wup_ajax_add_to_cart_handler' ); 599 600 201 601 add_action( 'wc_ajax_nopriv_thp_wup_add_to_cart', 'thp_wup_ajax_add_to_cart_handler' ); 202 602 203 603 604 605 606 607 608 609 204 610 function thp_wup_remove_action_for_wc_handler() { 205 611 612 613 614 615 206 616 $wup_options = ( !empty(get_option( 'thp_wup_options' )) ? get_option( 'thp_wup_options' ) : '' ); 617 618 207 619 $ajax_off = ( !empty($wup_options['ajax_off']) ? $wup_options['ajax_off'] : '' ); 208 620 621 622 623 624 209 625 if ($ajax_off) 626 627 210 628 return; 211 629 630 631 632 633 212 634 $use_wc_ajax = ( !empty($wup_options['use_wc_ajax']) ? $wup_options['use_wc_ajax'] : '' ); 213 635 636 637 638 639 214 640 if (! $use_wc_ajax) { 641 642 215 643 return; 216 } 644 645 646 } 647 648 217 649 else if ( ($use_wc_ajax) && (is_ajax()) && (! is_admin()) ) { 650 651 218 652 remove_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ), 20 ); 219 } 653 654 655 } 656 657 658 659 220 660 221 661 } 662 663 222 664 add_action( 'init', 'thp_wup_remove_action_for_wc_handler' ); 223 665 224 666 667 668 669 670 671 672 225 673 function thp_upsell_backend_scripts( $hook ) { 674 675 226 676 global $post; 227 677 678 679 680 681 228 682 if ( ($hook == 'post-new.php') || ($hook == 'post.php') || (@$_REQUEST['page'] == 'thp-wup-main-settings')) { 683 684 229 685 if ( ('product' === @$post->post_type) || (@$_REQUEST['page'] == 'thp-wup-main-settings')) { 686 687 230 688 wp_enqueue_style( 'thp-select2-css', plugin_dir_url( __FILE__ ).'css/select2.min.css' ); 689 690 231 691 wp_enqueue_style( 'thp-upsell-admin-css', plugin_dir_url( __FILE__ ).'css/wup-admin-style.min.css' ); wp_enqueue_style( 'wp-color-picker' ); 692 693 232 694 wp_enqueue_script( 'my-script-handle', plugin_dir_url( __FILE__ ).'js/flytonic_color_picker.js', array( 'wp-color-picker' ), false, true); 695 696 233 697 wp_enqueue_script( 'thp-select2-js', plugin_dir_url( __FILE__ ).'js/select2.min.js', array( 'jquery' ), '4.0.3', true ); 698 699 234 700 wp_enqueue_script( 'thp-upsell-admin-js', plugin_dir_url( __FILE__ ).'js/product-search.min.js', array( 'jquery' ), false, true ); 701 702 235 703 wp_localize_script('thp-upsell-admin-js', 'thp_upsellmetabox_vars', array( 704 705 236 706 'select2_searchproduct_placeholder' => __( 'Search for product name..', 'very-simple-woocommerce-upsell-popup' ), 707 708 237 709 'select2_template_placeholder' => __( 'Choose template..', 'very-simple-woocommerce-upsell-popup' ), 710 711 238 712 'select2_redirect_placeholder' => __( 'Choose behavior..', 'very-simple-woocommerce-upsell-popup' ) 713 714 239 715 ) 716 717 240 718 ); 719 720 241 721 } 722 723 242 724 } 725 726 243 727 } 728 729 244 730 add_action( 'admin_enqueue_scripts', 'thp_upsell_backend_scripts', 10, 1 ); 245 731 246 732 733 734 735 736 737 738 247 739 function thp_search_product_to_upsell() { 740 741 248 742 if ( ! current_user_can( 'manage_options' ) ) { 743 744 249 745 return; 250 } 746 747 748 } 749 750 751 752 251 753 252 754 ob_start(); 253 755 756 757 758 759 254 760 $thp_search_term = filter_input( INPUT_GET, 'thp_search_term', FILTER_SANITIZE_STRING ); 761 762 255 763 $thp_current_prod_id = filter_input( INPUT_GET, 'thp_current_prod_id', FILTER_SANITIZE_NUMBER_INT ); 256 764 765 766 767 768 257 769 if ( empty( $thp_search_term ) ) { 770 771 258 772 die(); 259 } 773 774 775 } 776 777 260 778 $arg = array( 779 780 261 781 'post_status' => 'publish', 782 783 262 784 'post_type' => 'product', 785 786 263 787 'posts_per_page' => 50, 788 789 264 790 's' => $thp_search_term, 791 792 265 793 'post__not_in' => array( $thp_current_prod_id ) 794 795 266 796 ); 797 798 267 799 $the_query = new WP_Query( $arg ); 800 801 268 802 $found_products = array(); 803 804 269 805 if ( $the_query->have_posts() ) { 806 807 270 808 while ( $the_query->have_posts() ) { 809 810 271 811 $the_query->the_post(); 812 813 272 814 $_product = wc_get_product( get_the_ID() ); 815 816 273 817 818 819 274 820 $product = array( 821 822 275 823 'id' => $_product->get_id(), 824 825 276 826 'text' => get_the_title() . ' (ID:' . get_the_ID() . ')' 827 828 277 829 ); 830 831 278 832 $found_products[] = $product; 279 } 280 } 281 833 834 835 } 836 837 838 } 839 840 841 842 843 282 844 wp_reset_postdata(); 845 846 283 847 wp_send_json( $found_products ); 848 849 284 850 die(); 851 852 285 853 } 854 855 286 856 add_action( 'wp_ajax_thp_search_product_to_upsell', 'thp_search_product_to_upsell' ); 287 857 288 858 859 860 861 862 863 864 289 865 function thp_fire_php_include($product_id) { 290 866 867 868 869 870 291 871 $wup_options = ( !empty(get_option( 'thp_wup_options' )) ? get_option( 'thp_wup_options' ) : '' ); 872 873 292 874 /*$global_settings_on = ( !empty($wup_options['global_settings_on']) ? $wup_options['global_settings_on'] : '' );*/ 875 876 293 877 $individual_settings_on = ( !empty(get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true)) ? get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true) : '' ); 878 879 294 880 $cat_settings_on = ( !empty($wup_options['cat_settings_on']) ? $wup_options['cat_settings_on'] : '' ); 295 881 882 883 884 885 296 886 /*if ($global_settings_on) { 887 888 297 889 $global_upsell_enabled = ( !empty($wup_options['enable_upsell_global']) ? $wup_options['enable_upsell_global'] : '' ); 298 890 891 892 893 894 299 895 if (!$global_upsell_enabled) 896 897 300 898 return; 899 900 301 901 }*/ 902 903 302 904 if($individual_settings_on){ 905 906 303 907 if(!empty(get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true))){ 908 909 304 910 $single_upsell_enabled = get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true); 305 911 912 913 914 915 306 916 if (!$single_upsell_enabled) 917 918 307 919 return; 308 } 309 } 920 921 922 } 923 924 925 } 926 927 310 928 else if ($cat_settings_on) { 311 929 930 931 932 933 312 934 $new_cat_ids = array(); 935 936 313 937 $cat_list_ids = wp_get_post_terms($product_id, 'product_cat', array('fields'=>'ids')); 314 938 939 940 941 942 315 943 foreach ($cat_list_ids as $cat_list_id) { 316 944 945 946 947 948 317 949 $cat_info = get_term_by('id', $cat_list_id, 'product_cat'); 950 951 318 952 $cat_name = $cat_info->name; 319 953 954 955 956 957 320 958 /*if ($cat_info->parent) { 959 960 321 961 $cat_list_id = $cat_info->parent; 962 963 322 964 $parent_info = get_term_by('id', $cat_list_id, 'product_cat'); 965 966 323 967 $cat_name = $parent_info->name; 324 } 968 969 970 } 971 972 325 973 echo '<pre>'; print_r($cat_info); die;*/ 974 975 326 976 $new_cat_ids[$cat_list_id] = $cat_name; 327 } 328 977 978 979 } 980 981 982 983 984 329 985 asort($new_cat_ids); //sort by category name in ascending order 330 986 987 988 989 990 331 991 reset($new_cat_ids); 332 992 993 994 995 996 333 997 $cat_id = key($new_cat_ids); //first category ID 334 998 999 1000 1001 1002 335 1003 $cat_upsell_enabled = ( !empty($wup_options['enable_upsell_cat'.@$cat_id]) ? $wup_options['enable_upsell_cat'.@$cat_id] : '' ); 336 1004 1005 1006 1007 1008 337 1009 if (!$cat_upsell_enabled) 1010 1011 338 1012 return; 1013 1014 339 1015 }else{ 1016 1017 340 1018 $global_upsell_enabled = ( !empty($wup_options['enable_upsell_global']) ? $wup_options['enable_upsell_global'] : '' ); 341 1019 1020 1021 1022 1023 342 1024 if (!$global_upsell_enabled) 1025 1026 343 1027 return; 344 } 1028 1029 1030 } 1031 1032 345 1033 /*else { 1034 1035 346 1036 if(!empty(get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true))){ 1037 1038 347 1039 $single_upsell_enabled = get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true); 348 1040 1041 1042 1043 1044 349 1045 if (!$single_upsell_enabled) 1046 1047 350 1048 return; 351 } 1049 1050 1051 } 1052 1053 352 1054 }*/ 353 1055 1056 1057 1058 1059 354 1060 $thp_upsell_prod_ids = array(); 1061 1062 355 1063 $thp_classic_enabled = ''; 1064 1065 356 1066 $thp_linked_upsells_enabled = ''; 1067 1068 357 1069 $thp_classic_prodid = get_post_meta($product_id, 'thp_upsell_product_select', true); 358 1070 1071 1072 1073 1074 359 1075 if (thp_wuppro_active()) { 360 1076 1077 1078 1079 1080 361 1081 if ($individual_settings_on) { 1082 1083 362 1084 $thp_linked_upsells_enabled = get_post_meta($product_id, 'thp_wc_linkedprods_upsells', true); 1085 1086 363 1087 $thp_classic_enabled = get_post_meta($product_id, 'thp_classic_single_upsell', true); 364 1088 1089 1090 1091 1092 365 1093 if ($thp_classic_enabled && $thp_classic_prodid) { 1094 1095 366 1096 1097 1098 367 1099 $classic_obj = new WC_Product($thp_classic_prodid); 1100 1101 368 1102 1103 1104 369 1105 if ( ( 'publish' == get_post_status ( $thp_classic_prodid ) ) && ( get_post_type( $thp_classic_prodid ) == 'product' ) && ( $classic_obj->is_in_stock() ) ) { 1106 1107 370 1108 $thp_upsell_prod_ids[] = $thp_classic_prodid; 1109 1110 371 1111 } 372 } 373 } 1112 1113 1114 } 1115 1116 1117 } 1118 1119 374 1120 else if ($cat_settings_on) { 1121 1122 375 1123 $thp_linked_upsells_enabled = ( !empty($wup_options['linkedprods_upsells_cat'.@$cat_id]) ? $wup_options['linkedprods_upsells_cat'.@$cat_id] : '' ); 376 } 1124 1125 1126 } 1127 1128 377 1129 else { 1130 1131 378 1132 $thp_linked_upsells_enabled = ( !empty($wup_options['linkedprods_upsells_global']) ? $wup_options['linkedprods_upsells_global'] : '' ); 379 380 } 381 1133 1134 1135 1136 1137 1138 } 1139 1140 1141 1142 1143 382 1144 /*if ($global_settings_on) { 1145 1146 383 1147 $thp_linked_upsells_enabled = ( !empty($wup_options['linkedprods_upsells_global']) ? $wup_options['linkedprods_upsells_global'] : '' ); 384 } 1148 1149 1150 } 1151 1152 385 1153 else if ($cat_settings_on) { 1154 1155 386 1156 $thp_linked_upsells_enabled = ( !empty($wup_options['linkedprods_upsells_cat'.@$cat_id]) ? $wup_options['linkedprods_upsells_cat'.@$cat_id] : '' ); 387 } 1157 1158 1159 } 1160 1161 388 1162 else { 1163 1164 389 1165 $thp_linked_upsells_enabled = get_post_meta($product_id, 'thp_wc_linkedprods_upsells', true); 1166 1167 390 1168 $thp_classic_enabled = get_post_meta($product_id, 'thp_classic_single_upsell', true); 391 1169 1170 1171 1172 1173 392 1174 if ($thp_classic_enabled && $thp_classic_prodid) { 1175 1176 393 1177 1178 1179 394 1180 $classic_obj = new WC_Product($thp_classic_prodid); 1181 1182 395 1183 1184 1185 396 1186 if ( ( 'publish' == get_post_status ( $thp_classic_prodid ) ) && ( get_post_type( $thp_classic_prodid ) == 'product' ) && ( $classic_obj->is_in_stock() ) ) { 1187 1188 397 1189 $thp_upsell_prod_ids[] = $thp_classic_prodid; 1190 1191 398 1192 } 399 } 1193 1194 1195 } 1196 1197 400 1198 }*/ //end if else 401 1199 1200 1201 1202 1203 402 1204 $product_obj = ''; 403 1205 1206 1207 1208 1209 404 1210 if ($thp_linked_upsells_enabled==1) { 1211 1212 405 1213 $product_obj = new WC_Product($product_id); 406 1214 1215 1216 1217 1218 407 1219 $wc_upsell_ids = $product_obj->get_upsell_ids(); 1220 1221 408 1222 $single_upsell_enabled = get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true); 409 1223 1224 1225 1226 1227 410 1228 $global_settings_on = ( !empty($wup_options['global_settings_on']) ? $wup_options['global_settings_on'] : '' ); 1229 1230 411 1231 $global_upsell_enabled = ( !empty($wup_options['enable_upsell_global']) ? $wup_options['enable_upsell_global'] : '' ); 1232 1233 412 1234 $list_of_global_upsell_products = ( !empty($wup_options['list_of_global_upsell_products']) ? $wup_options['list_of_global_upsell_products'] : '' ); 413 1235 1236 1237 1238 1239 414 1240 $cat_settings_on = ( !empty($wup_options['cat_settings_on']) ? $wup_options['cat_settings_on'] : '' ); 1241 1242 415 1243 $list_of_global_upsell_products_cat = ( !empty($wup_options['list_of_global_upsell_products_cat'.@$cat_id]) ? $wup_options['list_of_global_upsell_products_cat'.@$cat_id] : '' ); 1244 1245 416 1246 $cat_upsell_enabled = ( !empty($wup_options['enable_upsell_cat'.@$cat_id]) ? $wup_options['enable_upsell_cat'.@$cat_id] : '' ); 417 1247 1248 1249 1250 1251 418 1252 if ((!empty($wc_upsell_ids)) && (!empty($single_upsell_enabled))) { 1253 1254 419 1255 foreach ( $wc_upsell_ids as $upsell_id ) { 1256 1257 420 1258 if ( ( get_post_type( $upsell_id ) == 'product' ) && ( 'publish' == get_post_status ( $upsell_id ) ) ) { 1259 1260 421 1261 $upsell_obj = new WC_Product($upsell_id); 1262 1263 422 1264 if ( $upsell_obj->is_in_stock() ) 1265 1266 423 1267 $thp_upsell_prod_ids[] = $upsell_id; 1268 1269 424 1270 } 1271 1272 425 1273 elseif ( get_post_type( $upsell_id ) == 'product_variation' ) { 1274 1275 426 1276 $upsell_variation_obj = new WC_Product_Variation($upsell_id); 1277 1278 427 1279 1280 1281 428 1282 if ( ($upsell_variation_obj->is_in_stock()) && (wp_get_post_parent_id( $upsell_id ) != false) ) 1283 1284 429 1285 $thp_upsell_prod_ids[] = $upsell_id; 1286 1287 430 1288 } 1289 1290 431 1291 } 1292 1293 432 1294 }else if((!empty($list_of_global_upsell_products_cat)) && (!empty($cat_upsell_enabled)) && (!empty($cat_settings_on))){ 1295 1296 433 1297 foreach ( $list_of_global_upsell_products_cat as $upsell_id ) { 1298 1299 434 1300 $thp_upsell_prod_ids[] = $upsell_id; 1301 1302 435 1303 } 1304 1305 436 1306 }else if((!empty($list_of_global_upsell_products)) && (!empty($global_upsell_enabled)) && (!empty($global_settings_on))){ 1307 1308 437 1309 foreach ( $list_of_global_upsell_products as $upsell_id ) { 1310 1311 438 1312 $thp_upsell_prod_ids[] = $upsell_id; 1313 1314 439 1315 } 440 } 441 } 442 1316 1317 1318 } 1319 1320 1321 } 1322 1323 1324 1325 1326 443 1327 if ($thp_linked_upsells_enabled==2) { 444 1328 1329 1330 1331 1332 445 1333 $global_upsell_enabled = ( !empty($wup_options['enable_upsell_global']) ? $wup_options['enable_upsell_global'] : '' ); 1334 1335 446 1336 $global_settings_on = ( !empty($wup_options['global_settings_on']) ? $wup_options['global_settings_on'] : '' ); 1337 1338 447 1339 $list_of_global_cross_upsell_products = ( !empty($wup_options['list_of_global_cross_upsell_products']) ? $wup_options['list_of_global_cross_upsell_products'] : '' ); 448 1340 1341 1342 1343 1344 449 1345 $cat_settings_on = ( !empty($wup_options['cat_settings_on']) ? $wup_options['cat_settings_on'] : '' ); 1346 1347 450 1348 $list_of_global_cross_upsell_products_cat = ( !empty($wup_options['list_of_global_cross_upsell_products_cat'.@$cat_id]) ? $wup_options['list_of_global_cross_upsell_products_cat'.@$cat_id] : '' ); 1349 1350 451 1351 $cat_upsell_enabled = ( !empty($wup_options['enable_upsell_cat'.@$cat_id]) ? $wup_options['enable_upsell_cat'.@$cat_id] : '' ); 452 1352 1353 1354 1355 1356 453 1357 if (! is_object($product_obj)) 1358 1359 454 1360 $product_obj = new WC_Product($product_id); 455 1361 1362 1363 1364 1365 456 1366 $wc_crosssell_ids = $product_obj->get_cross_sell_ids(); 1367 1368 457 1369 $single_upsell_enabled = get_post_meta($product_id, 'thp_wc_enable_upsell_on_single_product', true); 458 1370 1371 1372 1373 1374 459 1375 if ((!empty($wc_crosssell_ids)) && (!empty($single_upsell_enabled))) { 1376 1377 460 1378 foreach ( $wc_crosssell_ids as $crosssell_id ) { 1379 1380 461 1381 if ( ( get_post_type( $crosssell_id ) == 'product' ) && ( 'publish' == get_post_status ( $crosssell_id ) ) ) { 1382 1383 462 1384 $crosssell_obj = new WC_Product($crosssell_id); 1385 1386 463 1387 if ( $crosssell_obj->is_in_stock() ) 1388 1389 464 1390 $thp_upsell_prod_ids[] = $crosssell_id; 1391 1392 465 1393 } 1394 1395 466 1396 elseif ( get_post_type( $crosssell_id ) == 'product_variation' ) { 1397 1398 467 1399 $crosssell_variation_obj = new WC_Product_Variation($crosssell_id); 1400 1401 468 1402 1403 1404 469 1405 if ( ($crosssell_variation_obj->is_in_stock()) && (wp_get_post_parent_id( $crosssell_id ) != false) ) 1406 1407 470 1408 $thp_upsell_prod_ids[] = $crosssell_id; 1409 1410 471 1411 } 1412 1413 472 1414 } 1415 1416 473 1417 }else if((!empty($list_of_global_cross_upsell_products_cat)) && (!empty($cat_upsell_enabled)) && (!empty($cat_settings_on))){ 474 1418 1419 1420 1421 1422 475 1423 foreach ( $list_of_global_cross_upsell_products_cat as $upsell_id ) { 1424 1425 476 1426 1427 1428 477 1429 $thp_upsell_prod_ids[] = $upsell_id; 1430 1431 478 1432 1433 1434 479 1435 } 480 1436 1437 1438 1439 1440 481 1441 }else if((!empty($list_of_global_cross_upsell_products)) && (!empty($global_upsell_enabled)) && (!empty($global_settings_on))){ 482 1442 1443 1444 1445 1446 483 1447 foreach ( $list_of_global_cross_upsell_products as $upsell_id ) { 1448 1449 484 1450 1451 1452 485 1453 $thp_upsell_prod_ids[] = $upsell_id; 1454 1455 486 1456 1457 1458 487 1459 } 488 489 } 490 } 491 1460 1461 1462 1463 1464 1465 } 1466 1467 1468 } 1469 1470 1471 1472 1473 492 1474 $thp_upsell_prod_ids = array_unique($thp_upsell_prod_ids); 493 } 1475 1476 1477 } 1478 1479 494 1480 elseif (!thp_wuppro_active()) { 1481 1482 495 1483 if ($thp_classic_prodid) { 496 1484 1485 1486 1487 1488 497 1489 $classic_obj = new WC_Product($thp_classic_prodid); 498 1490 1491 1492 1493 1494 499 1495 if ( ( 'publish' == get_post_status ( $thp_classic_prodid ) ) && ( get_post_type( $thp_classic_prodid ) == 'product' ) && ( $classic_obj->is_in_stock() ) ) { 1496 1497 500 1498 $thp_upsell_prod_ids[] = $thp_classic_prodid; 501 } 502 1499 1500 1501 } 1502 1503 1504 1505 1506 503 1507 if (! $thp_upsell_prod_ids) 1508 1509 504 1510 return; 505 } 506 } 507 1511 1512 1513 } 1514 1515 1516 } 1517 1518 1519 1520 1521 508 1522 if ( (! $thp_upsell_prod_ids) && (! $thp_classic_prodid) ) 1523 1524 509 1525 return; 510 1526 1527 1528 1529 1530 511 1531 if (is_ajax()) //reminder: is_ajax is woocommerce function, not wordpress 1532 1533 512 1534 $popup = ''; 513 1535 1536 1537 1538 1539 514 1540 if ( ( sizeof($thp_upsell_prod_ids) == 1 ) || ( $thp_classic_prodid && !$thp_classic_enabled && !$thp_linked_upsells_enabled ) ) { //backward compatibilty 1541 1542 515 1543 $found = false; 1544 1545 516 1546 1547 1548 517 1549 if ($thp_upsell_prod_ids) 1550 1551 518 1552 $single_upsell_id = $thp_upsell_prod_ids[0]; 1553 1554 519 1555 elseif (!$thp_upsell_prod_ids && $thp_classic_prodid) 1556 1557 520 1558 $single_upsell_id = $thp_classic_prodid; 521 1559 1560 1561 1562 1563 522 1564 if ( sizeof( WC()->cart->get_cart() ) > 0 ) { 1565 1566 523 1567 foreach ( WC()->cart->get_cart() as $cart_item => $values ) { 1568 1569 524 1570 $_product = $values['data']; 1571 1572 525 1573 if ( $_product->get_id() == $single_upsell_id ) { 1574 1575 526 1576 $found = true; //product to upsell found in cart, no need to show popup 1577 1578 527 1579 } 528 } 529 } 1580 1581 1582 } 1583 1584 1585 } 1586 1587 530 1588 if ( ! $found ) { 1589 1590 531 1591 global $woocommerce; 1592 1593 532 1594 $woocommerce->session->set_customer_session_cookie(true); 533 1595 1596 1597 1598 1599 534 1600 $thp_popup_template = get_post_meta($product_id, 'thp_upsellpopup_template', true); 535 1601 1602 1603 1604 1605 536 1606 if (is_ajax()) 1607 1608 537 1609 ob_start(); 538 1610 1611 1612 1613 1614 539 1615 if ( ($thp_popup_template) && (thp_wuppro_active()) && (strpos($thp_popup_template, 'protemp') !== false) ) { 1616 1617 540 1618 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-custom.php' ); 541 } 1619 1620 1621 } 1622 1623 542 1624 elseif ( ($thp_popup_template) && (thp_wuppro_active()) && ($thp_popup_template == 'template5') ) { //will deprecate soon 1625 1626 543 1627 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template5.php' ); 544 } 1628 1629 1630 } 1631 1632 545 1633 elseif ( ($thp_popup_template) && ($thp_popup_template != 'template5') && ($thp_popup_template != 'template-default') && (strpos($thp_popup_template, 'protemp') === false) ) { 1634 1635 546 1636 include ( 'templates/single/thp-popup-'.$thp_popup_template.'.php' ); 547 } 1637 1638 1639 } 1640 1641 548 1642 else { 1643 1644 549 1645 include ( 'templates/single/thp-popup-template-default.php' ); 550 } 551 1646 1647 1648 } 1649 1650 1651 1652 1653 552 1654 if (is_ajax()) 1655 1656 553 1657 $popup = ob_get_clean(); 554 } 555 } 1658 1659 1660 } 1661 1662 1663 } 1664 1665 556 1666 elseif ( sizeof($thp_upsell_prod_ids) > 1 ) { 1667 1668 557 1669 global $woocommerce; 1670 1671 558 1672 $woocommerce->session->set_customer_session_cookie(true); 559 1673 1674 1675 1676 1677 560 1678 $thp_popup_template = get_post_meta($product_id, 'thp_upsellpopup_template_multiple', true); 561 1679 1680 1681 1682 1683 562 1684 if (is_ajax()) 1685 1686 563 1687 ob_start(); 564 1688 1689 1690 1691 1692 565 1693 if ($thp_popup_template) { 566 1694 1695 1696 1697 1698 567 1699 if ( $thp_popup_template == 'template-default' ) { 1700 1701 568 1702 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-default-mult.php' ); 569 } 1703 1704 1705 } 1706 1707 570 1708 elseif ($thp_popup_template == 'template-radio') { 1709 1710 571 1711 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-radio-mult.php' ); 572 } 1712 1713 1714 } 1715 1716 573 1717 elseif ($thp_popup_template == 'template-yesno') { 1718 1719 574 1720 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-yesno-btn-mult.php' ); 575 } 1721 1722 1723 } 1724 1725 576 1726 elseif ($thp_popup_template == 'template-variable') { 1727 1728 577 1729 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-variable-mult.php' ); 578 } 1730 1731 1732 } 1733 1734 579 1735 elseif ($thp_popup_template == 'template-fc') { 1736 1737 580 1738 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-fc-mult.php' ); 581 } 1739 1740 1741 } 1742 1743 582 1744 elseif ($thp_popup_template == 'template-variablefc') { 1745 1746 583 1747 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-variable-fc-mult.php' ); 584 } 1748 1749 1750 } 1751 1752 585 1753 elseif ( strpos($thp_popup_template, '.php') ) { 1754 1755 586 1756 1757 1758 587 1759 $thp_popup_template = filter_var( $thp_popup_template, FILTER_SANITIZE_STRING); 1760 1761 588 1762 $thp_popup_template = pathinfo($thp_popup_template, PATHINFO_BASENAME); 1763 1764 589 1765 1766 1767 590 1768 if ( file_exists( get_stylesheet_directory() . '/wuppro/multiple/' . $thp_popup_template ) ) 1769 1770 591 1771 include ( get_stylesheet_directory() . '/wuppro/multiple/' . $thp_popup_template ); 1772 1773 592 1774 else //if file does not exist 1775 1776 593 1777 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-default-mult.php' ); 594 } 1778 1779 1780 } 1781 1782 595 1783 else { 1784 1785 596 1786 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-default-mult.php' ); 597 } 598 599 } 1787 1788 1789 } 1790 1791 1792 1793 1794 1795 } 1796 1797 600 1798 else { 1799 1800 601 1801 include ( plugin_dir_path( __DIR__ ).'woocommerce-upsell-popup-pro/templates/thp-popup-template-default-mult.php' ); 602 } 603 1802 1803 1804 } 1805 1806 1807 1808 1809 604 1810 if (is_ajax()) 1811 1812 605 1813 $popup = ob_get_clean(); 606 } 1814 1815 1816 } 1817 1818 1819 1820 607 1821 608 1822 if (is_ajax()) 1823 1824 609 1825 return $popup; 1826 1827 610 1828 } 611 1829 612 1830 1831 1832 1833 1834 1835 1836 613 1837 function thp_ajax_popup_trigger() { 1838 1839 614 1840 $product_id = filter_input( INPUT_GET, 'prod_id', FILTER_SANITIZE_NUMBER_INT ); 1841 1842 615 1843 $popup = thp_fire_php_include($product_id); 616 1844 1845 1846 1847 1848 617 1849 echo $popup; 1850 1851 618 1852 die(); 1853 1854 619 1855 } 1856 1857 620 1858 add_action('wp_ajax_nopriv_thp_ajax_popup_trigger', 'thp_ajax_popup_trigger'); 1859 1860 621 1861 add_action('wp_ajax_thp_ajax_popup_trigger', 'thp_ajax_popup_trigger'); 622 1862 623 1863 1864 1865 1866 1867 1868 1869 624 1870 function thp_popup_form_action_ajax () { 625 1871 1872 1873 1874 1875 626 1876 $clicked = filter_input( INPUT_GET, 'clicked', FILTER_SANITIZE_STRING ); 1877 1878 627 1879 $product_id = filter_input( INPUT_GET, 'prod_id', FILTER_SANITIZE_NUMBER_INT ); 1880 1881 628 1882 $redirect_url = ''; 629 1883 1884 1885 1886 1887 630 1888 if ($clicked == 'yes') { 631 1889 1890 1891 1892 1893 632 1894 $upsell_product_id = filter_input( INPUT_GET, 'up_pid', FILTER_SANITIZE_NUMBER_INT ); 633 1895 1896 1897 1898 1899 634 1900 if ( get_post_type( $upsell_product_id ) == 'product' ) 1901 1902 635 1903 $_product = wc_get_product( $upsell_product_id ); 636 1904 1905 1906 1907 1908 637 1909 if (( get_post_type( $upsell_product_id ) == 'product_variation' ) || ( $_product->is_type( 'simple' ) ) || ( $_product->is_type( 'course' ) )) { 1910 1911 638 1912 //WC()->cart->add_to_cart( $upsell_product_id ); 1913 1914 639 1915 if(isset($_REQUEST['quality-'.$upsell_product_id.''])){ 1916 1917 640 1918 WC()->cart->add_to_cart( $upsell_product_id,$_REQUEST['quality-'.$upsell_product_id.''] ); 1919 1920 641 1921 }else{ 1922 1923 642 1924 WC()->cart->add_to_cart( $upsell_product_id ); 643 } 1925 1926 1927 } 1928 1929 644 1930 $redirection = get_post_meta($product_id, 'thp_upsellpopup_redirect', true); 645 1931 1932 1933 1934 1935 646 1936 if ( $redirection == '2cart' ) { 1937 1938 647 1939 $redirect_url = get_permalink( get_option( 'woocommerce_cart_page_id' ) ); 648 } 1940 1941 1942 } 1943 1944 649 1945 elseif ( $redirection == '3checkout' ) { 1946 1947 650 1948 $redirect_url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); 651 } 652 } 1949 1950 1951 } 1952 1953 1954 } 1955 1956 653 1957 else { 1958 1959 654 1960 $redirect_url = get_permalink( $upsell_product_id ); 655 } 656 } 1961 1962 1963 } 1964 1965 1966 } 1967 1968 657 1969 elseif ($clicked == 'no') { 658 1970 1971 1972 1973 1974 659 1975 $redirection = get_post_meta($product_id, 'thp_upsellpopup_redirect_no', true); 660 1976 1977 1978 1979 1980 661 1981 if ( $redirection == '2cart' ) { 1982 1983 662 1984 $redirect_url = get_permalink( get_option( 'woocommerce_cart_page_id' ) ); 663 } 1985 1986 1987 } 1988 1989 664 1990 elseif ( $redirection == '3checkout' ) { 1991 1992 665 1993 $redirect_url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); 666 } 667 } 668 1994 1995 1996 } 1997 1998 1999 } 2000 2001 2002 2003 2004 669 2005 echo $redirect_url; 2006 2007 670 2008 die(); 2009 2010 671 2011 } 2012 2013 672 2014 add_action('wp_ajax_nopriv_thp_popup_form_action_ajax', 'thp_popup_form_action_ajax'); 2015 2016 673 2017 add_action('wp_ajax_thp_popup_form_action_ajax', 'thp_popup_form_action_ajax'); 674 2018 675 2019 2020 2021 2022 2023 2024 2025 676 2026 function thp_popup_form_action_ajax_mult () { 677 2027 2028 2029 2030 2031 678 2032 $product_id = filter_input( INPUT_POST, 'prod_id', FILTER_SANITIZE_NUMBER_INT ); 2033 2034 679 2035 parse_str( filter_input( INPUT_POST, 'up_pids', FILTER_SANITIZE_STRING ), $up_prod_ids ); 680 2036 2037 2038 2039 2040 681 2041 foreach($up_prod_ids as $mult_upsell_id => $i){ 2042 2043 682 2044 foreach($i as $n => $id){ 2045 2046 683 2047 //WC()->cart->add_to_cart( $id ); 2048 2049 684 2050 if(isset($_REQUEST['quality-'.$id.''])){ 2051 2052 685 2053 WC()->cart->add_to_cart( $id,$_REQUEST['quality-'.$id.''] ); 2054 2055 686 2056 }else{ 2057 2058 687 2059 WC()->cart->add_to_cart( $id ); 688 } 689 } 690 } 691 2060 2061 2062 } 2063 2064 2065 } 2066 2067 2068 } 2069 2070 2071 2072 2073 692 2074 $redirection = get_post_meta($product_id, 'thp_upsellpopup_redirect', true); 693 2075 2076 2077 2078 2079 694 2080 if ( $redirection == '2cart' ) { 2081 2082 695 2083 $redirect_url = get_permalink( get_option( 'woocommerce_cart_page_id' ) ); 696 } 2084 2085 2086 } 2087 2088 697 2089 elseif ( $redirection == '3checkout' ) { 2090 2091 698 2092 $redirect_url = get_permalink( get_option( 'woocommerce_checkout_page_id' ) ); 699 } 700 2093 2094 2095 } 2096 2097 2098 2099 2100 701 2101 echo $redirect_url; 2102 2103 702 2104 die(); 2105 2106 703 2107 } 2108 2109 704 2110 add_action('wp_ajax_nopriv_thp_popup_form_action_ajax_mult', 'thp_popup_form_action_ajax_mult'); 2111 2112 705 2113 add_action('wp_ajax_thp_popup_form_action_ajax_mult', 'thp_popup_form_action_ajax_mult'); 706 2114 707 2115 2116 2117 2118 2119 2120 2121 708 2122 function thp_format_wc_price () { 709 2123 2124 2125 2126 2127 710 2128 $raw_total = filter_input( INPUT_GET, 'total', FILTER_SANITIZE_STRING ); 711 2129 2130 2131 2132 2133 712 2134 $formatted_total = wc_price($raw_total); 713 2135 2136 2137 2138 2139 714 2140 echo $formatted_total; 2141 2142 715 2143 die(); 2144 2145 716 2146 } 2147 2148 717 2149 add_action('wp_ajax_nopriv_thp_format_wc_price', 'thp_format_wc_price'); 2150 2151 718 2152 add_action('wp_ajax_thp_format_wc_price', 'thp_format_wc_price'); 719 2153 720 2154 2155 2156 2157 2158 2159 2160
Note: See TracChangeset
for help on using the changeset viewer.