Snippets Collections
// Add a checkbox to the terms and conditions section
add_action('woocommerce_checkout_terms_and_conditions', 'add_custom_checkout_checkbox', 20);
function add_custom_checkout_checkbox() {
    woocommerce_form_field('factor_need', array(
        'type'  => 'checkbox',
        'class' => array('woocommerce-form__input woocommerce-form__input-checkbox'),
        'label' => ('آیا مایل به دریافت فاکتور هستید؟', 'woocommerce'),
    ));
}

// Save the checkbox value in the order meta
add_action('woocommerce_checkout_update_order_meta', 'save_custom_checkout_checkbox');
function save_custom_checkout_checkbox($order_id) {
    if (isset($_POST['factor_need'])) {
        update_post_meta($order_id, 'factor_need', 'yes');
    } else {
        update_post_meta($order_id, 'factor_need', 'no');
    }
}

// Display the checkbox value in the admin order details
add_action('woocommerce_admin_order_data_after_billing_address', 'display_custom_checkout_checkbox_in_admin', 10, 1);
function display_custom_checkout_checkbox_in_admin($order) {
    $factor_need = get_post_meta($order->get_id(), 'factor_need', true);
    if ($factor_need === 'yes') {
        echo '<p><strong>' . ('نیاز به فاکتور:', 'woocommerce') . '</strong> ' . __('هست', 'woocommerce') . '</p>';
    } 
}
<style> 
  INPUT:checked + label {color: #00F;} 
</style>

<input id="theId" type="checkbox"><label for="theId"> The cat is here</label> 
<fieldset style="width:fit-content"><legend>Where is the Cat?</legend>
	<input id="cat_garden" name="cat_where" type="radio"><label for="cat_garden"> Garden</label> 
	<input id="cat_bed" name="cat_where" type="radio"><label for="cat_bed"> Bed</label> 
	<input id="cat_cushion" name="cat_where" type="radio"><label for="cat_cushion"> Cushion</label> 
</fieldset>
function save_test() {
    showloading();
 
    let AssessmentCategorie = []
    $("input[name='AssessmentCategorie[]']:checked").each(function () {
        AssessmentCategorie.push(parseInt($(this).val()));
    });

 $.post("ajax/save_test.php", {
     
        AssessmentCategorie: AssessmentCategorie,

    }, function (data) {

        $("#save_test").html(data);
        get_test();
        hide_loading();

    });
  
  }
star

Mon Aug 05 2024 15:07:42 GMT+0000 (Coordinated Universal Time)

#php #wordpress #checkout #factor #checkbox
star

Wed Feb 07 2024 00:31:20 GMT+0000 (Coordinated Universal Time)

#css #html #form #checkbox #radio_button
star

Sun Aug 28 2022 13:15:03 GMT+0000 (Coordinated Universal Time)

#ajax #checkbox

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension