Skip to content

Instantly share code, notes, and snippets.

@sachyya
Created August 9, 2024 11:55
Show Gist options
  • Save sachyya/a4510df207801cce70b505bd886e17c9 to your computer and use it in GitHub Desktop.
Save sachyya/a4510df207801cce70b505bd886e17c9 to your computer and use it in GitHub Desktop.
Skip out of stock products from being indexed
<?php
add_filter('cm_typesense_force_remove_post_on_update', 'theme_prefix_skip_or_remove_doc', 10, 2);
add_filter('cm_typesense_bulk_import_skip_post', 'theme_prefix_skip_or_remove_doc', 10, 2);
function theme_prefix_skip_or_remove_doc( $skip, $product ) {
if ($product->post_type == 'product') {
$product_obj = wc_get_product($product);
$stock_status = $product_obj->get_stock_status();
if ('outofstock' == $stock_status) {
$skip = true;
}
}
return $skip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment