Snippets Collections
// where we have two arrays of checked and unchecked 

 function onHandleCheckbox(checkbox) {
        // create a new attay of objects with the value and checked status
        checkbox.addEventListener("change", () => {
            const status = [...trainingRadioBtns].map((btn) => ({
                value: btn.value,
                checked: btn.checked,
            }));
            // update global checkedValues array with objects of items that are checked then another with items unchecked
            checkedValues = status.filter((btn) => btn.checked).map((btn) => btn.value);
            notSelected = status.filter((btn) => !btn.checked).map((btn) => btn.value);
            // console.log("selected", checkedValues);
            // console.log("not selected", notSelected);

            // return values to the filteredItems array that match the below
            filteredItems = locations.filter((item) => {
                // Each individual match condition for filtering from the checkedvalues array or the notselected array
                const matchesFunded = (checkedValues.includes("governmentService") && item.governmentService) || notSelected.includes("governmentService");
                const matchesOnline = (checkedValues.includes("isAvailableOnline") && item.isAvailableOnline) || notSelected.includes("isAvailableOnline");
                const matchesPartTime = (checkedValues.includes("isAvailablePartTime") && item.isAvailablePartTime) || notSelected.includes("isAvailablePartTime");
                const matchesApprentice = (checkedValues.includes("apprenticeshipTraineeship") && item.apprenticeshipTraineeship) || notSelected.includes("apprenticeshipTraineeship");
                const matchesVetFeeCourse = (checkedValues.includes("isVetFeeCourse") && item.isVetFeeCourse) || notSelected.includes("isVetFeeCourse");

                // Check if the item matches All of the selected filters and return
                return matchesFunded && matchesOnline & matchesPartTime & matchesApprentice & matchesVetFeeCourse;
            });

            // updating functions
            noLocationsOverlay(filteredItems);

            checkLoadButton(filteredItems);

            displayLocations();

            updateMarkers(filteredItems);
        });
    }
// 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

Wed Feb 12 2025 22:58:02 GMT+0000 (Coordinated Universal Time)

#checkbox #conditionals
star

Mon Feb 10 2025 14:42:19 GMT+0000 (Coordinated Universal Time) https://moderncss.dev/12-modern-css-one-line-upgrades/#accent-color

#css #ui #form #radio-button #checkbox #range #progress
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