Home Forums Virtue Theme Deliver to a different address? not collapsed by default in checkout

This topic is: resolved
Posted in: Virtue Theme  


  • February 8, 2018 at 8:29 am #178365

    checkout delevery address not collapsed

    Ive added custom code to include a conditional checkout terms and conditions tick box based on products orderd.

    If the additional terms and conditions box is shown based on category of product in cart then the deleivery address feild is collapsed as it should be.

    But if an item that is added to cart is not a product in the caterories that triggers the additional terms and conditions box then the delivery feild is exspanded.

    add_action('woocommerce_review_order_before_submit', 'bbloomer_add_checkout_tickbox', 20);
    function bbloomer_add_checkout_tickbox() {
    <p class="form-row terms">
    <input type="checkbox" class="input-checkbox" name="deliverycheck" id="deliverycheck" />
    <label for="deliverycheck" class="checkbox">I acknowledge it is my responsibility to check with my primary healthcare provider that it is suitable to take these supplements with any prescribed medication, or over the counter medications, I may be taking now or in the future.</label>
    // Show notice if customer does not tick
    add_action('woocommerce_checkout_process', 'bbloomer_not_approved_delivery');
    function bbloomer_not_approved_delivery() {
        if ( ! (int) isset( $_POST['deliverycheck'] ) ) {
            wc_add_notice( __( 'Please acknowledge the terms of sale' ), 'error' );
    //checkout notice
     * Check if a specific product category is in the cart
    function wc_ninja_category_is_in_the_cart() {
    	// Add your special category slugs here
    	$categories = array( 'metabolic-packs', 'minerals', 'glandulars', 'vitamins', 'combination formulas', 'digestive aids' );
    	// Products currently in the cart
    	$cart_ids = array();
    	// Categories currently in the cart
    	$cart_categories = array();
    	// Find each product in the cart and add it to the $cart_ids array
    	foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
    		$cart_product = $values['data'];
    		$cart_ids[]   = $cart_product->id;
    	// Connect the products in the cart w/ their categories
    	foreach( $cart_ids as $id ) {
    		$products_categories = get_the_terms( $id, 'product_cat' );
    		// Loop through each product category and add it to our $cart_categories array
    		foreach ( $products_categories as $products_category ) {
    			$cart_categories[] = $products_category->slug;
    		// If one of the special categories are in the cart, return true.
    	if ( ! empty( array_intersect( $categories, $cart_categories ) ) ) {
    		return true;
    	} else {
    		return false;
     * Conditionally remove a checkout field based on products in the cart
    function wc_ninja_remove_checkout_field( $actions ) {
    	if ( ! wc_ninja_category_is_in_the_cart() ) {
    		unset( $actions['bbloomer_add_checkout_tickbox'] );
    	return $fields;
    add_filter( 'woocommerce_review_order_before_submit' , 'wc_ninja_remove_checkout_field' );

    Sorry, this forum is for Premium customers only. Please Login to continue

    If you are using a free theme you can access support on wordpress.org by searching for the free theme and using the support tab.