Skip to content

Instantly share code, notes, and snippets.

@msaari
Created October 25, 2018 03:40
Show Gist options
  • Select an option

  • Save msaari/0ae5ff44216db5e3f071c68455c3e5ec to your computer and use it in GitHub Desktop.

Select an option

Save msaari/0ae5ff44216db5e3f071c68455c3e5ec to your computer and use it in GitHub Desktop.
WooCommerce weight boost for products in stock.
<?php
// Add this to theme functions.php.
add_filter( 'relevanssi_match', 'rlv_woo_stocklevel' );
function rlv_woo_stocklevel( $match ) {
$in_stock = true;
if ( has_term( 'outofstock', 'product_visibility', $match->doc ) ) {
// Product is not in stock.
$in_stock = false;
}
if ( $in_stock ) {
// If product is in stock, multiply the weight by 10.
$match->weight *= 10;
}
return $match;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment