Skip to content

Instantly share code, notes, and snippets.

@arelthia
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save arelthia/2415e02a424be66b1e98 to your computer and use it in GitHub Desktop.

Select an option

Save arelthia/2415e02a424be66b1e98 to your computer and use it in GitHub Desktop.
Only show terms of service for specific product.
//Conditional Terms of Service
add_filter( 'woocommerce_checkout_show_terms' , 'syb_remove_terms' );
function syb_remove_terms( $fields ) {
foreach ( WC()->cart->get_cart() as $item ) {
if ( $item['product_id'] == '401') {
return true;
}
}
return false;
}
//Start Conditional Terms of Service
//check terms by default because they are not required
function syb_check_terms( $bool ){
return true;
}
//do not check terms by default because they are required
function syb_user_check_terms( $bool ){
return false;
}
add_filter( 'woocommerce_checkout_show_terms' , 'syb_remove_terms' );
function syb_remove_terms() {
foreach ( WC()->cart->get_cart() as $item ) {
if ( $item['product_id'] == '401') {
add_filter( 'woocommerce_terms_is_checked_default', 'syb_user_check_terms', 10);
return true;
}
}
//Check terms by default. Do not require user to check terms
add_filter( 'woocommerce_terms_is_checked_default', 'syb_check_terms', 10);
//Hide the terms
?>
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery( '.woocommerce #payment .terms').hide();
});
</script>
<?php
return true;
}
//End Conditional Terms of Service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment