mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/76795858/remove-woocommerce-checkout-term-and-conditions-when-specific-product-is-alone-i
16 lines
660 B
Text
16 lines
660 B
Text
add_filter( 'woocommerce_checkout_show_terms', 'remove_terms_and_conditions_for_specific_unique_item' );
|
|
function remove_terms_and_conditions_for_specific_unique_item( $show_terms ) {
|
|
// Replace "123" with the desired product ID
|
|
$targeted_id = 123;
|
|
$cart_items = WC()->cart->get_cart(); // get cart items
|
|
|
|
// Check if there is only one item in cart
|
|
if( count($cart_items) > 1 ) {
|
|
return $show_terms;
|
|
}
|
|
// Check if the targeted product ID is the only item in cart
|
|
if ( reset($cart_items)['product_id'] == $targeted_id ) {
|
|
return false; // Remove terms and conditions field
|
|
}
|
|
return $show_terms;
|
|
}
|