Skip to content

Commit

Permalink
Search: automatically select product result format for sites with Woo…
Browse files Browse the repository at this point in the history
…Commerce active (#19065)

* Automatically select product result format for sites with WooCommerce active

* Fix typo

* Add Jetpack::get_active_plugins check for WP.com simple sites

* Add changelog

* Update changelog

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
  • Loading branch information
bluefuton and jeherve committed Mar 11, 2021
1 parent a0f55ad commit b659820
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

Jetpack Search: during setup, automatically use the product result format for sites with WooCommerce active.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function inject_javascript_options() {
'enableSort' => get_option( $prefix . 'enable_sort', '1' ) === '1',
'highlightColor' => get_option( $prefix . 'highlight_color', '#FFC' ),
'overlayTrigger' => get_option( $prefix . 'overlay_trigger', 'immediate' ),
'resultFormat' => get_option( $prefix . 'result_format', 'minimal' ),
'resultFormat' => get_option( $prefix . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_MINIMAL ),
'showPoweredBy' => get_option( $prefix . 'show_powered_by', '1' ) === '1',
),

Expand Down Expand Up @@ -448,10 +448,11 @@ public function auto_config_search() {
}

// Set default result format to "expanded".
update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', 'expanded' );
update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_EXPANDED );

$this->auto_config_excluded_post_types();
$this->auto_config_overlay_sidebar_widgets();
$this->auto_config_woo_result_format();
}

/**
Expand Down Expand Up @@ -611,6 +612,7 @@ protected function get_preconfig_widget_options() {

return $settings;
}

/**
* Automatically configure post types to exclude from one of the search widgets
*
Expand Down Expand Up @@ -642,4 +644,22 @@ public function auto_config_excluded_post_types() {
update_option( Jetpack_Search_Options::OPTION_PREFIX . 'excluded_post_types', join( ',', $post_types_to_disable ) );
}
}

/**
* Automatically set result format to 'product' if WooCommerce is installed
*
* @since 9.6.0
*/
public function auto_config_woo_result_format() {
if ( ! method_exists( 'Jetpack', 'get_active_plugins' ) ) {
return false;
}

// Check if WooCommerce plugin is active (based on https://docs.woocommerce.com/document/create-a-plugin/).
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ) ) {
return false;
}

update_option( Jetpack_Search_Options::OPTION_PREFIX . 'result_format', Jetpack_Search_Options::RESULT_FORMAT_PRODUCT );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ class Jetpack_Search_Options {
*/
const OPTION_PREFIX = 'jetpack_search_';

/**
* Available result formats.
*
* @since 9.6.0
* @var string
*/
const RESULT_FORMAT_MINIMAL = 'minimal';
const RESULT_FORMAT_EXPANDED = 'expanded';
const RESULT_FORMAT_PRODUCT = 'product';

/**
* Returns a boolean for whether instant search is enabled.
*
Expand Down

0 comments on commit b659820

Please sign in to comment.