CustomizeStoreWithBlocks.php
2 years ago
CustomizingProductCatalog.php
1 year ago
EUVATNumber.php
2 years ago
EditProductsOnTheMove.php
2 years ago
EmailImprovements.php
1 year ago
FirstProduct.php
1 year ago
GivingFeedbackNotes.php
3 years ago
InstallJPAndWCSPlugins.php
4 weeks ago
LaunchChecklist.php
2 years ago
MagentoMigration.php
2 years ago
ManageOrdersOnTheGo.php
2 years ago
MarketingJetpack.php
4 weeks ago
MigrateFromShopify.php
2 years ago
MobileApp.php
2 years ago
NewSalesRecord.php
3 years ago
NoteActionForbiddenException.php
4 weeks ago
OnboardingPayments.php
2 years ago
OnlineClothingStore.php
2 years ago
OrderMilestones.php
2 years ago
PaymentsMoreInfoNeeded.php
5 months ago
PaymentsRemindMeLater.php
5 months ago
PerformanceOnMobile.php
2 years ago
PersonalizeStore.php
3 years ago
RealTimeOrderAlerts.php
2 years ago
ScheduledUpdatesPromotion.php
5 months ago
SellingOnlineCourses.php
2 years ago
TrackingOptIn.php
1 year ago
UnsecuredReportFiles.php
2 years ago
WooCommercePayments.php
2 years ago
WooCommerceSubscriptions.php
2 years ago
WooSubscriptionsNotes.php
1 year ago
MarketingJetpack.php
143 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Admin Jetpack Marketing Note Provider. |
| 4 | * |
| 5 | * Adds notes to the merchant's inbox concerning Jetpack Backup. |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Admin\Notes; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | use Automattic\Jetpack\Constants; |
| 13 | use Automattic\WooCommerce\Admin\Notes\Note; |
| 14 | use Automattic\WooCommerce\Admin\Notes\Notes; |
| 15 | use Automattic\WooCommerce\Admin\Notes\NoteTraits; |
| 16 | use Automattic\WooCommerce\Admin\PluginsHelper; |
| 17 | |
| 18 | /** |
| 19 | * Suggest Jetpack Backup to Woo users. |
| 20 | * |
| 21 | * Note: This should probably live in the Jetpack plugin in the future. |
| 22 | * |
| 23 | * @see https://developer.woocommerce.com/2020/10/16/using-the-admin-notes-inbox-in-woocommerce/ |
| 24 | */ |
| 25 | class MarketingJetpack { |
| 26 | // Shared Note Traits. |
| 27 | use NoteTraits; |
| 28 | |
| 29 | /** |
| 30 | * Name of the note for use in the database. |
| 31 | */ |
| 32 | const NOTE_NAME = 'wc-admin-marketing-jetpack-backup'; |
| 33 | |
| 34 | /** |
| 35 | * Product IDs that include Backup. |
| 36 | */ |
| 37 | const BACKUP_IDS = [ |
| 38 | 2010, |
| 39 | 2011, |
| 40 | 2012, |
| 41 | 2013, |
| 42 | 2014, |
| 43 | 2015, |
| 44 | 2100, |
| 45 | 2101, |
| 46 | 2102, |
| 47 | 2103, |
| 48 | 2005, |
| 49 | 2006, |
| 50 | 2000, |
| 51 | 2003, |
| 52 | 2001, |
| 53 | 2004, |
| 54 | ]; |
| 55 | |
| 56 | /** |
| 57 | * Maybe add a note on Jetpack Backups for Jetpack sites older than a week without Backups. |
| 58 | */ |
| 59 | public static function possibly_add_note() { |
| 60 | /** |
| 61 | * Check if Jetpack is installed. |
| 62 | */ |
| 63 | $installed_plugins = PluginsHelper::get_installed_plugin_slugs(); |
| 64 | if ( ! in_array( 'jetpack', $installed_plugins, true ) ) { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | $data_store = \WC_Data_Store::load( 'admin-note' ); |
| 69 | |
| 70 | // Do we already have this note? |
| 71 | $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); |
| 72 | if ( ! empty( $note_ids ) ) { |
| 73 | |
| 74 | $note_id = array_pop( $note_ids ); |
| 75 | $note = Notes::get_note( $note_id ); |
| 76 | if ( false === $note ) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | // If Jetpack Backups was purchased after the note was created, mark this note as actioned. |
| 81 | if ( self::has_backups() && Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) { |
| 82 | $note->set_status( Note::E_WC_ADMIN_NOTE_ACTIONED ); |
| 83 | $note->save(); |
| 84 | } |
| 85 | |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // Check requirements. |
| 90 | if ( ! self::is_wc_admin_active_in_date_range( 'week-1-4', DAY_IN_SECONDS * 3 ) || ! self::can_be_added() || self::has_backups() ) { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | // Add note. |
| 95 | $note = self::get_note(); |
| 96 | $note->save(); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the note. |
| 101 | */ |
| 102 | public static function get_note() { |
| 103 | $note = new Note(); |
| 104 | $note->set_title( __( 'Protect your WooCommerce Store with Jetpack Backup.', 'woocommerce' ) ); |
| 105 | $note->set_content( __( 'Store downtime means lost sales. One-click restores get you back online quickly if something goes wrong.', 'woocommerce' ) ); |
| 106 | $note->set_type( Note::E_WC_ADMIN_NOTE_MARKETING ); |
| 107 | $note->set_name( self::NOTE_NAME ); |
| 108 | $note->set_content_data( (object) array() ); |
| 109 | $note->set_source( 'woocommerce-admin-notes' ); |
| 110 | $note->add_action( |
| 111 | 'jetpack-backup-woocommerce', |
| 112 | __( 'Get backups', 'woocommerce' ), |
| 113 | esc_url( 'https://jetpack.com/upgrade/backup-woocommerce/?utm_source=inbox&utm_medium=automattic_referred&utm_campaign=jp_backup_to_woo' ), |
| 114 | Note::E_WC_ADMIN_NOTE_ACTIONED |
| 115 | ); |
| 116 | return $note; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Check if this blog already has a Jetpack Backups product. |
| 121 | * |
| 122 | * @return boolean Whether or not this blog has backups. |
| 123 | */ |
| 124 | protected static function has_backups() { |
| 125 | $product_ids = []; |
| 126 | |
| 127 | $plan = get_option( 'jetpack_active_plan' ); |
| 128 | if ( ! empty( $plan ) ) { |
| 129 | $product_ids[] = $plan['product_id']; |
| 130 | } |
| 131 | |
| 132 | $products = get_option( 'jetpack_site_products' ); |
| 133 | if ( ! empty( $products ) ) { |
| 134 | foreach ( $products as $product ) { |
| 135 | $product_ids[] = $product['product_id']; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return (bool) array_intersect( self::BACKUP_IDS, $product_ids ); |
| 140 | } |
| 141 | |
| 142 | } |
| 143 |