Skip to content

Instantly share code, notes, and snippets.

@sebastianmoran-mainwp
Last active October 23, 2020 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastianmoran-mainwp/e7f81cc40f924f1d08800d050d6ff471 to your computer and use it in GitHub Desktop.
Save sebastianmoran-mainwp/e7f81cc40f924f1d08800d050d6ff471 to your computer and use it in GitHub Desktop.
WP Search with Algolia with WooCommerce Products
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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment