Categories
Uncategorized

How to Make Billing and Shipping Fields Optional and required in WooCommerce?

Make Billing and Shipping Fields Optional and required in WooCommerce

 
For not required
  1. country
  2. first_name
  3. last_name
  4. company
  5. address_1
  6. address_2
  7. city
  8. state
  9. postcode
add_filter( 'woocommerce_default_address_fields' , 'optional_default_address_fields' );
 function optional_default_address_fields( $address_fields ) {
 $address_fields['company']['required'] = false;
 $address_fields['postcode']['required'] = false;
 $address_fields['city']['required'] = false;
 $address_fields['state']['required'] = false;
 return $address_fields;
 }
For required
add_filter( 'woocommerce_default_address_fields' , 'optional_default_address_fields' );
 function optional_default_address_fields( $address_fields ) {
 $address_fields['company']['required'] = true;
 $address_fields['postcode']['required'] = true;
 $address_fields['city']['required'] = true;
 $address_fields['state']['required'] = true;
 return $address_fields;
 }

Make Billing and Shipping Fields Optional and required in WooCommerce

t looks like all of the WooCommerce checkout fields are added in the billing form template but I’m not sure where they’re coming from. Is there an easy way to change which of these fields are required? I don’t need the phone, but I do need the company field instead and I’m not seeing where the fields are.


The WooCommerce checkout fields are generated outside of the checkout template, so we have to do a bit of digging to find them. At the top of the billing form template, we notice that we’re using the $checkout global: @global WC_Checkout $checkout

This tells us we need to look at the WC_Checkout class to find where these fields are being generated instead, and we’ll go down a tiny rabbit hole 🙂 .

The checkout class defines the checkout fields for billing and shipping, and it pulls them from WC()->countries->get_address_fields. This means we have to dig down one more level, and go to /includes/class-wc-countries.php. As these fields may change by country or state / province, they’re generated here when we check the country, and then the checkout template outputs the right fields in the right order for the selected country.

The first thing I’m going to do is find the “company” field. I do a bit of searching, and find that it’s generated by get_default_address_fields, and can be modified by the woocommerce_default_address_fields filter, which passes in all of these fields.

Click here to get more information

Read More Posts

Categories
Html/Css Jquery PHP Uncategorized

How to submit form with anchor tag (link) in jquery?

 Submit form with anchor tag (a and link) in jquery
<form method="get" action="">
<input type="text" name="ID" value="jassi">
<input type="text" name="con" value="singh">
<a href="" onclick="this.closest('form').submit();return false;" value="CONSTRUCTION CONTRACT">CONSTRUCTION CONTRACT</a>
</form>

 Submit form with anchor tag (a and link) in jquery

 

Read More Posts

Categories
Uncategorized

How to sorting in descending and ascending in sql?

Sorting in descending order in SQL

Descending

“select * from $dealtable where user_id=’$uid’ AND status=’$status’ ORDER BY ID DESC”

Ascending

“select * from $dealtable where user_id=’$uid’ AND status=’$status’ ORDER BY ID ASC”

Categories
Uncategorized

How to Prevent negative inputs in form input type=“number”?

Prevent negative inputs in form input type=“number”?


<html>
<body>
<form action=”#”>
  <input type=”number” name=”test” min=0 oninput=”validity.valid||(value=”);”><br>
  <input type=”submit” value=”Submit”>
</form>
</body>
</html>
Categories
Uncategorized

How to trigger (use) an event when contenteditable is changed in jQuery?

Trigger an event when contenteditable is changed



<div class=”changeable” contenteditable=”true”> Click this div to edit it </div>
jQuery(document).ready(function($){
var contents = $(‘.changeable’).html();
$(‘.changeable’).blur(function() {
    if (contents!=$(this).html()){
        alert(‘Handler for .change() called.’);
        contents = $(this).html();
    }
});
});
Categories
Uncategorized

How to get warning when exit browser without saving?

Get warning when exit browser without saving

My website is www.wpcodekit.com

<script>
jQuery(document).ready(function($){

$(window).unbind(‘beforeunload’);

$(“input[type=’submit’]”).click(function(){
     $(window).unbind(‘beforeunload’);
});

$(“input”).on(“change paste keyup”, function() {

  $(window).bind(‘beforeunload’, function(){
return ‘Are you sure you want to leave?’;
  });

});

var contenteditable = document.querySelector(‘[contenteditable]’),
    text = contenteditable.textContent;

$(contenteditable).each(function(){

$(this).on(“change paste keyup”, function() {

$(window).bind(‘beforeunload’, function(){
return ‘Are you sure you want to leave?’;
});

});
});

$(“input[type=’submit’]”).click(function(){
     $(window).unbind(‘beforeunload’);
});

});
</script>

Categories
Uncategorized

How to get default value from input field in jquery?

Get default value from input field in jquery

$(“#name”).on(“change paste keyup”, function() {

 var default_value = this.defaultValue;

});

Categories
Uncategorized

How to send custom email template on buy specific product in woocommerce?

Send custom email template on buy specific product in woocommerce

add_action( ‘woocommerce_thankyou’, ‘wpcodekit_check_order_product_id’ );

function wpcodekit_check_order_product_id( $order_id ){

$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
   $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
   if($product_id === 6112) {
 
$customername = $order->get_billing_first_name() .’ ‘.$order->get_billing_last_name();
$message = file_get_contents(WP_CONTENT_DIR . ‘/themes/twentynineteen-child/emails/premiumsupport.html’);
$message = str_replace(“{customeremail}”,$customername,$message);
$toadmin = $order->get_billing_email();
$quotename = “Let Us Structure Your Partnership”;
$headers = ‘From: “‘ . $quotename . ‘” <no-reply@brrrrinvest.com>’ . “rn”;
$headers .= “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type: text/html; charset=UTF-8” . “rn”;

wp_mail( $toadmin, $quotename, $message, $headers );
}

if(($product_id === 2750)||($product_id === 2749)) {
 
$customername = $order->get_billing_first_name() .’ ‘.$order->get_billing_last_name();
$message = file_get_contents(WP_CONTENT_DIR . ‘/themes/twentynineteen-child/emails/emailconsult.html’);
$message = str_replace(“{customeremail}”,$customername,$message);
$toadmin = $order->get_billing_email();
$quotename = “Let Us Structure Your Partnership”;
$headers = ‘From: “‘ . $quotename . ‘” <no-reply@brrrrinvest.com>’ . “rn”;
$headers .= “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type: text/html; charset=UTF-8” . “rn”;

wp_mail( $toadmin, $quotename, $message, $headers );
}
}
}

Categories
Uncategorized

How to send custom email template in wordpress?

 Send custom email template in wordpress

$body = file_get_contents(WP_CONTENT_DIR . ‘/themes/Avada-Child-Theme/contact-email.html’);
$body = str_replace(“#name#”,$_POST[‘quotename’],$body);
$body = str_replace(“#email#”,'<a style=”color:#fff” href=”mailto:’.$_POST[‘quoteemail’].'”>’.$_POST[‘quoteemail’].'</a>’,$body);
$body = str_replace(“#mobile#”,$_POST[‘quotemobile’],$body);
$body = str_replace(“#message#”,$_POST[‘quotemessage’],$body);

$toadmin = “Scott@USAPrivateMoney.com, Jack@USAPrivateMoney.com, Prospect.60008.140@realtyjuggler.com”;

$adminmessage = “You just got one more visitor that is “.$quoteemail.” who filled proof of funds letter. Please find the attachment”;

$headers = ‘From: “‘ . $quotename . ‘” <no-reply@usaprivatemoney.com>’ . “rn”;
$headers .= “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type: text/html; charset=UTF-8” . “rn”;


mail( $toadmin, $quotename, $body, $headers );

Example

  if($product_id === 6112) {
 
$customername = $order->get_billing_first_name() .’ ‘.$order->get_billing_last_name();
$message = file_get_contents(WP_CONTENT_DIR . ‘/themes/twentynineteen-child/emails/premiumsupport.html’);
$message = str_replace(“{customeremail}”,$customername,$message);
$toadmin = $order->get_billing_email();
$quotename = “Let Us Structure Your Partnership”;
$headers = ‘From: “‘ . $quotename . ‘” <no-reply@brrrrinvest.com>’ . “rn”;
$headers .= “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type: text/html; charset=UTF-8” . “rn”;

wp_mail( $toadmin, $quotename, $message, $headers );
}

Categories
Uncategorized

How to check if Order Contains Product ID in woocommerce (if product is buy)?

Check if Order Contains Product ID in woocommerce

add_action( ‘woocommerce_thankyou’, ‘codekit_check_order_product_id’ );
 
function codekit_check_order_product_id( $order_id ){
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
   $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
   if ( $product_id === ABC ) {
       // do something
   }
}
}