Created
August 9, 2024 11:55
-
-
Save sachyya/a4510df207801cce70b505bd886e17c9 to your computer and use it in GitHub Desktop.
Skip out of stock products from being indexed
This file contains hidden or 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
<?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