下面的代碼將在購(gòu)物車中只有特定產(chǎn)品時(shí)完全移除T&C要求:
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 = 15; $cart_items = WC()->cart->get_cart(); // get cart items // Check if there is only one item in cart if( count($cart_items) > 2 ) { 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; }
代碼應(yīng)該放置在活動(dòng)子主題的functions.php文件中,或者放置在插件中。已經(jīng)進(jìn)行了測(cè)試并確認(rèn)可以正常工作。