Created
October 25, 2018 03:40
-
-
Save msaari/0ae5ff44216db5e3f071c68455c3e5ec to your computer and use it in GitHub Desktop.
WooCommerce weight boost for products in stock.
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 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