Exemplo n.º 1
0
function conditional_checkout_field($checkout)
{
    echo '<div id="conditional_checkout_field">';
    $check_in_cart = conditional_product_in_cart('FND');
    //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) {
        woocommerce_form_field('custom_field', array('type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __('Friday Night Dinner Seating <br /><span class="extrainfo">Provide the total number of guests in your party, as well as their names if they are purchasing their tickets in a separate order</span>'), 'placeholder' => __('Name and number of people in party'), 'required' => true), $checkout->get_value('custom_field'));
    }
}
function conditional_checkout_field_process()
{
    $pid = get_option('oizuled_conditional_fields_pid');
    $check_in_cart = conditional_product_in_cart($pid);
    // Check if the field is required and set, if not then show an error message.
    if ($check_in_cart == true && get_option('oizuled_conditional_fields_required') == 'yes' && !$_POST['conditional_field']) {
        wc_add_notice(__(get_option('oizuled_conditional_fields_requiredtext')), 'error');
    }
}