Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: automatically select product result format for sites with WooCommerce active #19065

Merged
merged 6 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ) ) {
bluefuton marked this conversation as resolved.
Show resolved Hide resolved
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