-
-
Save WPprodigy/aa6b26dce224a43444bd to your computer and use it in GitHub Desktop.
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
<?php | |
function wc_ninja_product_is_in_the_cart() { | |
$items = array( '31' ); | |
// Create array from current cart | |
$cartitems = WC()->cart->get_cart(); | |
// Count items in cart | |
$itemcount = count( $cartitems ); | |
foreach($cartitems as $cartitem) { | |
$productid = $cartitem[product_id]; | |
if ( in_array( $productid, $items ) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
/** | |
* Borra los campos si se cumplen las condiciones indicadas | |
*/ | |
function wc_ninja_remove_checkout_field( $fields ) { | |
if ( ! wc_ninja_product_is_in_the_cart() ) { | |
unset( $fields['billing']['billing_justify2'] ); | |
} | |
return $fields; | |
} | |
add_filter( 'woocommerce_checkout_fields' , 'wc_ninja_remove_checkout_field' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment