Last active
October 23, 2020 03:53
-
-
Save sebastianmoran-mainwp/e7f81cc40f924f1d08800d050d6ff471 to your computer and use it in GitHub Desktop.
WP Search with Algolia with WooCommerce Products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_product_shared_attributes( array $shared_attributes, WP_Post $post ) { | |
$product = wc_get_product( $post ); | |
$shared_attributes['price'] = $product->get_price(); | |
$shared_attributes['regular_price'] = $product->get_regular_price(); | |
$shared_attributes['sale_price'] = $product->get_sale_price(); | |
$shared_attributes['is_on_sale'] = $product->is_on_sale(); | |
$shared_attributes['sku'] = $product->get_sku(); | |
$shared_attributes['stock_quantity'] = $product->get_stock_quantity(); | |
return $shared_attributes; | |
} | |
add_filter( 'algolia_post_product_shared_attributes', 'add_product_shared_attributes', 10, 2 ); | |
add_filter( 'algolia_searchable_post_product_shared_attributes', 'add_product_shared_attributes', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/WebDevStudios/wp-search-with-algolia/issues/88 | |
https://wordpress.org/support/topic/add-product-info-to-wp_searchable_posts-indices/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment