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>';
    } 
}
add_action( 'wp_head', function () { ?>
<style>

	.woocommerce-message, .woocommerce-info {
    border-top-color: var( --e-global-color-secondary );
}

.woocommerce-message::before, .woocommerce-info::before {
    color: var( --e-global-color-secondary );
}

</style>
<?php } );
/**
*  Out of stock message for product variations.
* @param string $text default message.
* @return string
*/
function puri_out_of_stock_message( $text ){
 $text = 'המוצר אזל מהמלאי, לכניסה לרשימת המתנה, אנא צרו קשר!';
 return $text;
}
add_filter( 'woocommerce_out_of_stock_message', 'puri_out_of_stock_message', 999);
/** unrequiered checkout fields**/
add_filter( 'woocommerce_default_address_fields', 'customise_postcode_fields' );
function customise_postcode_fields( $address_fields ) {
    $address_fields['postcode']['required'] = false;
    return $address_fields;
} 

add_filter( 'woocommerce_checkout_fields' , 'misha_not_required_fields', 9999 );
 
function misha_not_required_fields( $f ) {
 
	unset( $f['billing']['billing_postcode']['required'] );
	unset( $f['shipping']['shipping_postcode']['required'] );
 
	// the same way you can make any field required, example:
	// $f['billing']['billing_company']['required'] = true;
 
	return $f;
}
add_filter( 'woocommerce_checkout_fields' , 'virtual_products_less_fields' );

function virtual_products_less_fields( $fields ) {

    $virtual_products = true;

    foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

        if ( ! $cart_item['data']->is_virtual() ) $virtual_products = false;
    }

    if( $virtual_products===true) {
        unset($fields['billing']['billing_company']);
        unset($fields['billing']['billing_address_1']);
        unset($fields['billing']['billing_address_2']);
        unset($fields['billing']['billing_city']);
        unset($fields['billing']['billing_postcode']);
        unset($fields['billing']['billing_country']);
        unset($fields['billing']['billing_state']);
        unset($fields['billing']['billing_phone']);

        add_filter( 'woocommerce_enable_order_notes_field', '__return_false',9999 );
    }

    return $fields;

}
 * @snippet       Hide ALL shipping rates in ALL zones when Free Shipping is available
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=260
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.3
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
  
add_filter( 'woocommerce_package_rates', 'bbloomer_unset_shipping_when_free_is_available_all_zones', 10, 2 );
   
function bbloomer_unset_shipping_when_free_is_available_all_zones( $rates, $package ) {
      
$all_free_rates = array();
     
foreach ( $rates as $rate_id => $rate ) {
      if ( 'free_shipping' === $rate->method_id ) {
         $all_free_rates[ $rate_id ] = $rate;
         break;
      }
}
     
if ( empty( $all_free_rates )) {
        return $rates;
} else {
        return $all_free_rates;
} 
 
}
// Set a minimum dollar amount per order
add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
function spyr_set_min_total() {
	// Only run in the Cart or Checkout pages
	if( is_cart() || is_checkout() ) {
		global $woocommerce;

		// Set minimum cart total
		$minimum_cart_total = 500;

		// Total we are going to be using for the Math
		// This is before taxes and shipping charges
		$total = WC()->cart->subtotal;
		
		// Compare values and add an error is Cart's total
	    // happens to be less than the minimum required before checking out.
		// Will display a message along the lines of
		// A Minimum of 10 USD is required before checking out. (Cont. below)
		if( $total <= $minimum_cart_total  ) {
			// Display our error message
			wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
				.'<br />Current cart\'s total: %s %s',
				$minimum_cart_total,
				get_option( 'woocommerce_currency'),
				$total,
				get_option( 'woocommerce_currency') ),
			'error' );
		}
	}
}
/**
 * Woocommerce redirect to checkout after add to cart
 */
add_filter( 'woocommerce_add_to_cart_redirect', 'barbareshet_skip_cart_redirect_checkout' );

function barbareshet_skip_cart_redirect_checkout( $url ) {
	return wc_get_checkout_url();
}
add_filter( 'woocommerce_default_address_fields', 'customise_postcode_fields' );
function customise_postcode_fields( $address_fields ) {
    $address_fields['postcode']['required'] = false;

    return $address_fields;
}
/**
 * Hide shipping rates when free shipping is available.
 *
 * @param array $rates Array of rates found for the package.
 * @return array
 */
function my_hide_shipping_when_free_is_available( $rates ) {
	$free = array();
	foreach ( $rates as $rate_id => $rate ) {
		if ( 'free_shipping' === $rate->method_id ) {
			$free[ $rate_id ] = $rate;
			break;
		}
	}
	return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
* This piece of code will hide fields for the chosen method.
.hide_pickup {
    display: none !important;
}
*/
 
// Hide Local Pickup shipping method
add_filter( 'woocommerce_checkout_fields', 'hide_local_pickup_method' );
function hide_local_pickup_method( $fields_pickup ) {
    // change below for the method
    $shipping_method_pickup ='local_pickup:4';
    // change below for the list of fields. Add (or delete) the field name you want (or don’t want) to use
    $hide_fields_pickup = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city', 'billing_state');
 
    $chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping_pickup = $chosen_methods_pickup[0];
 
    foreach($hide_fields_pickup as $field_pickup ) {
        if ($chosen_shipping_pickup == $shipping_method_pickup) {
            $fields_pickup['billing'][$field_pickup]['required'] = false;
            $fields_pickup['billing'][$field_pickup]['class'][] = 'hide_pickup';
        }
        $fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';
    }
    return $fields_pickup;
}
// Local Pickup - hide fields
add_action( 'wp_head', 'local_pickup_fields', 999 );
function local_pickup_fields() {
    if (is_checkout()) :
    ?>
    <style>
        .hide_pickup {display: none!important;}
    </style>
    <script>
        jQuery( function( $ ) {
            if ( typeof woocommerce_params === 'undefined' ) {
                return false;
            }
            $(document).on( 'change', '#shipping_method input[type="radio"]', function() {
                // change local_pickup:4 accordingly
            $('.billing-dynamic_pickup').toggleClass('hide_pickup', this.value == 'local_pickup:4');
            });
        });
    </script>
    <?php
    endif;
}
function cw_custom_checkbox_fields( $checkout ) {
        echo '<div class="cw_custom_class"><h3>'.__('אישור דיוור: ').'</h3>';
        woocommerce_form_field( 'custom_checkbox', array(
            'type'          => 'checkbox',
            'label'         => __('אני מאשר\ת את הדיוור.'),
            'required'  => false,
        ), $checkout->get_value( 'custom_checkbox' ));
        echo '</div>';
    }
add_action( 'woocommerce_before_cart', 'calculator_free_shipping_cart_notice' );
  
function calculator_free_shipping_cart_notice() {
  
   $min_amount = 350; //change this to your free shipping threshold
   
   $current = WC()->cart->subtotal;
  
   if ( $current < $min_amount ) {
      $added_text = ' עוד ' . wc_price( $min_amount - $current ) . ' ויש לכם שליח עד הבית בחינם!';
      $return_to = wc_get_page_permalink( 'home' );
      $notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), 'הוסיפו פריטים לסל למשלוח חינם', $added_text );
      wc_print_notice( $notice, 'notice' );
   }
  
}

add_action( 'woocommerce_before_checkout_form', 'free_shipping_cart_notice' );
  
function free_shipping_cart_notice() {
  
   $min_amount = 350; //change this to your free shipping threshold
   
   $current = WC()->cart->subtotal;
  
   if ( $current < $min_amount ) {
      $added_text = ' עוד ' . wc_price( $min_amount - $current ) . ' ויש לכם שליח עד הבית בחינם!';
      $return_to = wc_get_page_permalink( 'home' );
      $notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), 'הוסיפו פריטים לסל למשלוח חינם', $added_text );
      wc_print_notice( $notice, 'notice' );
   }
  
}
star

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

#php #wordpress #checkout #factor #checkbox
star

Tue May 18 2021 20:51:56 GMT+0000 (Coordinated Universal Time)

#checkout
star

Tue May 18 2021 20:51:37 GMT+0000 (Coordinated Universal Time)

#checkout
star

Tue May 18 2021 20:43:04 GMT+0000 (Coordinated Universal Time)

#checkout
star

Tue May 18 2021 20:27:24 GMT+0000 (Coordinated Universal Time)

#checkout
star

Tue May 18 2021 16:58:32 GMT+0000 (Coordinated Universal Time)

#checkout
star

Tue May 18 2021 12:23:25 GMT+0000 (Coordinated Universal Time) https://wpsimplehacks.com/how-to-hide-woocommerce-checkout-fields-when-local-pickup-is-selected/

#checkout #delivery
star

Tue May 18 2021 12:19:26 GMT+0000 (Coordinated Universal Time)

#checkout

Save snippets that work with our extensions

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