Skip to main content

Posts

Showing posts from January, 2020

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 country first_name last_name company address_1 address_2 city state 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;

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="hidden" name="ID" value="<?php echo $dealid;?>"> <input type="hidden" name="con" value="construction-contract"> <a href="" onclick="this.closest('form').submit();return false;" value="CONSTRUCTION CONTRACT" class="contract-button">CONSTRUCTION CONTRACT</a> </form>

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

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>

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>

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>' . "\r\n"; $he

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    } } }

How to get order info (billing info) from order in woocommerce?

woocommerce-easily-get-order-info-total-items-etc-from-order // Get Order ID $order->get_id(); // Get Order Totals $0.00 $order->get_formatted_order_total(); $order->get_cart_tax(); $order->get_currency(); $order->get_discount_tax(); $order->get_discount_to_display(); $order->get_discount_total(); $order->get_fees(); $order->get_formatted_line_subtotal(); $order->get_shipping_tax(); $order->get_shipping_total(); $order->get_subtotal(); $order->get_subtotal_to_display(); $order->get_tax_location(); $order->get_tax_totals(); $order->get_taxes(); $order->get_total(); $order->get_total_discount(); $order->get_total_tax(); $order->get_total_refunded(); $order->get_total_tax_refunded(); $order->get_total_shipping_refunded(); $order->get_item_count_refunded(); $order->get_total_qty_refunded(); $order->get_qty_refunded_for_item(); $order->get_total_refunded_for_item(); $order->get_

How to add another email in woocommerce order?

  Add another email in woocommerce order add_filter( 'woocommerce_email_recipient_customer_completed_order', 'your_email_recipient_filter_function', 10, 2); function your_email_recipient_filter_function($recipient, $object) {     $recipient = $recipient . ',jaspreet797386@gmail.com';     return $recipient; } 

How to Remove WooCommerce Breadcrumbs in WordPress?

Remove WooCommerce Breadcrumbs in WordPress add_action('template_redirect', 'remove_shop_breadcrumbs' ); function remove_shop_breadcrumbs(){     if (is_shop())         remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0); } OR if(is_shop()){ ... } // shop page if(is_front_page() ){ ... } // static front page if(is_home()){ ... } // default page                                                                         OR remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);

How to Hide WooCommerce Product Quantity Field from Product Pages?

Hide WooCommerce Product Quantity Field from Product Pages www.wpcodekit.com function quantity_wp_head() {   if ( is_product() ) {     ?> <style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style> <?php     } }     add_action( 'wp_head', 'quantity_wp_head' ); Or add_filter( 'woocommerce_is_sold_individually', 'cw_remove_quantity_fields'); function cw_remove_quantity_fields( $return, $product ) { switch ( $product->product_type ) : case "grouped": return true; break; case "external": return true; break; case "variable": return true; break; default: return true; break; endswitch; } Or function cw_remove_quantity_fields( $return, $product ) {     return true; } add_filter( 'woocommerce_is_sold_individually', 'cw_remove_quantity_fields', 10, 2 ); How to Hide WooCommerc

How to fetch file name, extension and basename from url in php?

Fetch file name, extension and basename from url in php <?php $file = 'http://localhost/brrrr/wp-content/uploads/2019/11/New-Business-card-4.jpg'; $ext = pathinfo($file); echo $ext['dirname'] . '<br/>';   // Returns folder/directory echo $ext['basename'] . '<br/>';  // Returns file.html echo $ext['extension'] . '<br/>'; // Returns .html  echo $ext['filename'] . '<br/>';  // Returns file  ?>

How to accept image extension from url in php?

Accept image extension from url in php <?php  $file_name = 'http://localhost/brrrr/wp-content/uploads/2019/11/New-Business-card-4.jpg'; echo $file_name."<br>"; $allowed = array('gif', 'png', 'jpg'); $ext = pathinfo($file_name, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) {     echo 'error'; } else{ echo "this is ok"; }   ?>

How to create elementor popup with code in wordpress?

Create elementor popup with code in wordpress Use in main-function file // Add Shortcode function elementor_poup( $atts ) { // Attributes $atts = shortcode_atts( array( 'id' => '', ), $atts ); $etid = $atts['id']; echo '<div class="elementor-popup-'.$etid.'"><div class="e-popup-content"><div class="eclose"><svg viewBox="0 0 10.6 11"><polygon points="6.3,5.4 10.4,1.4 9.2,0.3 5.3,4.2 1.3,0.3 0.2,1.4 4.3,5.4 0.2,9.5 1.3,10.7 5.3,6.8 9.2,10.7 10.4,9.5 "></polygon></svg></div>'; echo do_shortcode("[elementor-template id=$etid]"); echo '</div></div>'; echo'<style> .epopup-'.$etid.' { cursor:pointer; } .elementor-popup-'.$etid.' .eclose {     z-index: 99999;     position: absolute;     top: 1em;     right: 1em;     cursor: pointer;