Created
October 27, 2021 05:18
-
-
Save topmask/d7f2415e8a607801bb06160d5da783a4 to your computer and use it in GitHub Desktop.
Fix for “Sold Individually” Products
This file contains 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
add_filter( 'woocommerce_product_add_to_cart_url', 'elftoy_fix_for_individual_products', 10, 2 ); | |
function elftoy_fix_for_individual_products( $add_to_cart_url, $product ){ | |
if( $product->get_sold_individually() // if individual product | |
&& WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $product->id ) ) // if in the cart | |
&& $product->is_purchasable() // we also need these two conditions | |
&& $product->is_in_stock() ) { | |
$add_to_cart_url = wc_get_checkout_url(); | |
} | |
return $add_to_cart_url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment