Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
Last active August 29, 2015 14:27
Show Gist options
  • Save ScottDeLuzio/37488af5ede56ffc24e4 to your computer and use it in GitHub Desktop.
Save ScottDeLuzio/37488af5ede56ffc24e4 to your computer and use it in GitHub Desktop.
Check if product is in cart
<?php
function conditional_checkout_field( $checkout ) {
echo '<div id="conditional_checkout_field">';
$check_in_cart = conditional_product_in_cart(xxxx); //replace xxxx with the product id
// Check if the product is in the cart and show the custom fields if it is
if ($check_in_cart === true ) {
echo '<h2>'.__('My Custom Checkout Field').'</h2>';
woocommerce_form_field( 'custom_field', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Label for my Custom Field'),
'placeholder' => __('Placeholder to help describe what you are looking for'),
), $checkout->get_value( 'custom_field' ));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment