Created
August 30, 2019 14:23
-
-
Save felipe-pita/7293af06c6b630945e94b2f0a003ad6b to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Remove produtos fora de estoque do cross sell | |
* @See https://github.com/woocommerce/woocommerce/blob/444dffdda27750b98ce1517d5f6f4d8153c53967/includes/class-wc-cart.php#L817 | |
*/ | |
add_filter('woocommerce_cart_crosssell_ids', 'remove_out_of_stock_from_crosssell', 10, 1 ); | |
function remove_out_of_stock_from_crosssell( $wp_parse_id_list ){ | |
if (!empty($wp_parse_id_list)) { | |
foreach ($wp_parse_id_list as $product_id) { | |
$product = wc_get_product($product_id); | |
// Verifica de o produto esta fora de estoque | |
if ( $product->managing_stock() && !$product->is_in_stock() ) { | |
// Remove o produto da listagem | |
if (($key = array_search($product_id, $wp_parse_id_list)) !== false) { | |
unset($wp_parse_id_list[$key]); | |
} | |
} | |
} | |
} | |
return $wp_parse_id_list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment