Monday 31 October 2016

How to hide Coupon form in WooCommerce, WordPress?

In case you're not utilizing coupons by any stretch of the imagination, you can conceal the structure on the truck and checkout page by unchecking "coupons checkbox" from WooCommerce > Settings > General, yet most times you'll need to leave coupons empowered on the off chance that you have to give a client a rebate for reasons unknown.

Or Can Disable it by adding following code.


Add following code in "functions.php" file.

<?php
// hide coupon form everywhere in woocommerce site
function hide_coupon_field( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}

return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field' );
?>



For more Interesting, Useful Article & codes visit IT New Code.

Woocommerce add to cart button redirect to checkout Learn

Method 1 for manual link:-

Try WooCommerce default method for add to cart button redirect to checkout. You can find the option in the WooCommerce -> Settings -> Products -> Display area. When the option “Redirect to the cart page after successful addition” is checked it will redirect all users to the cart after adding a product to the cart.
Uncheck it.



Then directly use following code:-
<a href="/checkout/?add-to-cart=2817&amp;quantity=1">Add to Cart</a>
2817 is procuct id.
1 is number of products add in cart.

Method 2:-

1. You can find the option in the WooCommerce -> Settings -> Products -> Display area. When the option “Redirect to the cart page after successful addition” is checked it will redirect all users to the cart after adding a product to the cart.
Uncheck it.



2. Woocommerce > Settings > Checkout (Tab) - where you should select pages for cart and checkout.
Selcect Cart Page as Checkout option from drop down menu.


Just it.
Now, Add to cart button will redirect to checkout page.


For more Interesting, Useful Article & codes visit IT New Code.




Sunday 9 October 2016

How to change WordPress login page WordPress Logo?

You can change WordPress login page WordPress logo to website logo using Two methods.

Method 1:-

Using Plugin:-
Customize Login Image:
https://wordpress.org/plugins/customize-login-image/screenshots/

WP Custom Admin Login Page Logo:
https://wordpress.org/plugins/wp-custom-login-page-logo/screenshots/


Method 2:-

Using code:-
First you need to open your theme’s "functions.php" file and then paste the following code:

<?php
function custom_loginlogo() {
echo '<style type="text/css">
h1 a {background-image: url('.get_bloginfo('template_directory').'/images/login_logo.png) !important; }
</style>';
}
add_action('login_head', 'custom_loginlogo');
?>

put Your website logo behalf of "login_logo.png" logo image.


For more Interesting, Useful Article & codes visit IT New Code.

Saturday 8 October 2016

How to any value display only till 2 decimal points?

Using following methods can display only 2 decimal point value.

Method 1:-
<?php
 $final_total=199.9;
 
    $formattedNum = number_format($final_total, 2);
    echo $formattedNum;
 ?>

Method 2:- 
 
<?php 
 $final_total=199.9;
 echo $number = sprintf('%0.2f', $final_total); 
 ?>
 
 


For more Interesting, Useful Article & codes visit IT New Code.

How to hide other Shipping methods When free Shipping is available in WooCommerce, WordPress?


Some times there are many methods use for diffident need & conditions in WooCommerce. In it one comman condition is like "Hide other Shipping methods When free Shipping is available". Below is given solution of this condition.

First create Free Shipping method with condition.Then,

Add following code in functions.php file


Snippets for WooCommerce 2.5
<?php
/**
 * woocommerce_package_rates is a 2.1+ hook
 */
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

/**
 * Hide shipping rates when free shipping is available
 *
 * @param array $rates Array of rates found for the package
 * @param array $package The package array/object being shipped
 * @return array of modified rates
 */
function hide_shipping_when_free_is_available( $rates, $package ) {
 
  // Only modify rates if free_shipping is present
  if ( isset( $rates['free_shipping'] ) ) {
 
  // To unset a single rate/method, do the following. This example unsets flat_rate shipping
  unset( $rates['flat_rate'] );
 
  // To unset all methods except for free_shipping, do the following
  $free_shipping          = $rates['free_shipping'];
  $rates                  = array();
  $rates['free_shipping'] = $free_shipping;
}

return $rates;
}
?>



Snippets for WooCommerce Version 2.6+
<?php
/**
 * Hide shipping rates when free shipping is available.
 * Updated to support WooCommerce 2.6 Shipping Zones.
 *
 * @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 );
?>





For more Interesting, Useful Article & codes visit IT New Code.


How to Create Contact form 7 HTML Structure code for send E-mail in WordPress?

First Create Contact form in contact form 7 Plugin.
Then Put following code in Mail structure.

CODE:-

<div style="width:70%;background: rgba(204, 204, 204, 0.36);padding: 30px;margin: 0 auto;">
<center><img style="max-height: 100px;" src="Logo_url"></center>
<center><h2>Inquiry About Site</h2></center>
<center>
<table style="background: #DDDDDD;color: #005BC6;width: 90%;">
<tbody>
<tr style="line-height: 24px;">
<td style="padding: 5px 10px;color: #000;font-weight: bold;">Name:</td>
<td style="padding: 5px 10px;line-height: 17px;">[your-name]</td>
</tr>

<tr style="line-height: 24px;">
<td style="padding: 5px 10px;color: #000;font-weight: bold;">Email:</td>
<td style="padding: 5px 10px;line-height: 17px;">[your-email]</td>
</tr>

<tr style="line-height: 24px;">
<td style="padding: 5px 10px;color: #000;font-weight: bold;">Contact No:</td>
<td style="padding: 5px 10px;line-height: 17px;">[tel-no]</td>
</tr>

<tr style="line-height: 24px;">
<td style="padding: 5px 10px;color: #000;font-weight: bold;">Message:</td>
<td style="padding: 5px 10px;line-height: 17px;">[your-message]</td>
</tr>

</tbody>
</table>
<center>
</div>

<center><small>This email sent from "<a href="#" target="_blank">#</a>".</small></center>

You can change as your form need.


For more Interesting, Useful Article & codes visit IT New Code.

In WordPress if template name is "something" then excecute code?

Just add following code where you need.


<?php
if ( is_page_template('template_file_name.php') ) {
    // Returns true when 'template_file_name.php' is being used.
} else {
    // Returns false when 'template_file_name.php' is not being used.
}
?>


For more Interesting, Useful Article & codes visit IT New Code.

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah