OBW: Add Facebook to recommended step

The end date for the Facebook recommendation
is October 8, 2019.

When the option is checked, this will install the extension
'Facebook for WooCommerce' on the user's site.
This commit is contained in:
Valerie 2018-12-13 13:41:34 -05:00
parent ca316d8933
commit 8a796138ef
2 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><defs><style>.cls-1{fill:#4267b2;}.cls-2{fill:#fff;}</style></defs><title>flogo_RGB_HEX-512</title><path class="cls-1" d="M483.74,0H28.26A28.26,28.26,0,0,0,0,28.26V483.74A28.26,28.26,0,0,0,28.26,512H273.5V314H207V236.5h66.5v-57c0-66.13,40.39-102.14,99.38-102.14,28.25,0,52.54,2.1,59.62,3v69.11l-40.68,0c-32.1,0-38.32,15.25-38.32,37.64V236.5h76.74l-10,77.5H353.5V512H483.74A28.26,28.26,0,0,0,512,483.74V28.26A28.26,28.26,0,0,0,483.74,0Z"/><path id="f" class="cls-2" d="M353.5,512V314h66.75l10-77.5H353.5V187.14c0-22.39,6.22-37.64,38.32-37.64l40.68,0V80.37c-7.08-.94-31.37-3-59.62-3-59,0-99.38,36-99.38,102.14v57H207V314h66.5V512Z"/></svg>

After

Width:  |  Height:  |  Size: 732 B

View File

@ -133,6 +133,21 @@ class WC_Admin_Setup_Wizard {
return current_user_can( 'install_plugins' );
}
/**
* Should we show the Facebook install option?
* True only if the user can install plugins,
* and up until the end date of the recommendation.
*
* @return boolean
*/
protected function should_show_facebook() {
$end_date_facebook_recommendation = new DateTime( '8 October 2019' );
$current_user_date = new DateTime( current_time( 'Y-m-d' ) );
return current_user_can( 'install_plugins' ) &&
$end_date_facebook_recommendation >= $current_user_date;
}
/**
* Should we display the 'Recommended' step?
* True if at least one of the recommendations will be displayed.
@ -142,7 +157,8 @@ class WC_Admin_Setup_Wizard {
protected function should_show_recommended_step() {
return $this->should_show_theme()
|| $this->should_show_automated_tax()
|| $this->should_show_mailchimp();
|| $this->should_show_mailchimp()
|| $this->should_show_facebook();
}
/**
@ -1910,6 +1926,17 @@ class WC_Admin_Setup_Wizard {
'plugins' => array( array( 'name' => __( 'Mailchimp for WooCommerce', 'woocommerce' ), 'slug' => 'mailchimp-for-woocommerce' ) ),
) );
endif;
if ( $this->should_show_facebook() ) :
$this->display_recommended_item( array(
'type' => 'facebook',
'title' => __( 'Facebook', 'woocommerce' ),
'description' => __( 'Enjoy all Facebook products combined in one extension: pixel tracking, catalog sync, messenger chat, shop functionality and Instagram shopping (coming soon)!', 'woocommerce' ),
'img_url' => WC()->plugin_url() . '/assets/images/obw-facebook-icon.svg',
'img_alt' => __( 'Facebook icon', 'woocommerce' ),
'plugins' => array( array( 'name' => __( 'Facebook for WooCommerce', 'woocommerce' ), 'slug' => 'facebook-for-woocommerce' ) ),
) );
endif;
?>
</ul>
<p class="wc-setup-actions step">
@ -1930,6 +1957,7 @@ class WC_Admin_Setup_Wizard {
$setup_storefront = isset( $_POST['setup_storefront_theme'] ) && 'yes' === $_POST['setup_storefront_theme'];
$setup_automated_tax = isset( $_POST['setup_automated_taxes'] ) && 'yes' === $_POST['setup_automated_taxes'];
$setup_mailchimp = isset( $_POST['setup_mailchimp'] ) && 'yes' === $_POST['setup_mailchimp'];
$setup_facebook = isset( $_POST['setup_facebook'] ) && 'yes' === $_POST['setup_facebook'];
update_option( 'woocommerce_calc_taxes', $setup_automated_tax ? 'yes' : 'no' );
update_option( 'woocommerce_setup_automated_taxes', $setup_automated_tax );
@ -1956,6 +1984,16 @@ class WC_Admin_Setup_Wizard {
);
}
if ( $setup_facebook ) {
$this->install_plugin(
'facebook-for-woocommerce',
array(
'name' => __( 'Facebook for WooCommerce', 'woocommerce' ),
'repo-slug' => 'facebook-for-woocommerce',
)
);
}
wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
exit;
}