Friday, May 29, 2015

WooCommerce Change Description Tab Title & Heading To Product Name



To change the WooCommerce Single Product Description tab title and heading to the product name, place the following PHP code in your theme’s functions.php file



<?php
// Change the description tab title to product name
add_filter( 'woocommerce_product_tabs', 'wc_change_product_description_tab_title', 10, 1 );
function wc_change_product_description_tab_title( $tabs ) {
global $post;
if ( isset( $tabs['description']['title'] ) )
$tabs['description']['title'] = $post->post_title;
return $tabs;
}
// Change the description tab heading to product name
add_filter( 'woocommerce_product_description_heading', 'wc_change_product_description_tab_heading', 10, 1 );
function wc_change_product_description_tab_heading( $title ) {
global $post;
return $post->post_title;
}
?>

WooCommerce Product Quantity Dropdown



WooCommerce by default adds a quantity input box to your product pages where customers can enter quantities, but a lot of times you want to have more control over the quantities and make it more idiot proof on your site for customers by allowing them to select the quantities instead of entering it themselves.

The following snippet of code I wrote will replace the default WooCommerce quantity input box and replace it with a dropdown select option of quantities. It is fully compatible with the Min/Max Quantities extension which allows you to display quantities in the dropdown based on the minimum, maximum and group values so the customer can only select values in which the product can be bought instead of having to use plus and minus buttons or entering a value manually.

To turn your WooCommerce quantity input boxes into dropdown select options simply copy the following code to your theme’s functions.php file

<?php
// Place the following code in your theme's functions.php file
// override the quantity input with a dropdown
function woocommerce_quantity_input() {
global $product;
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left; margin-right:10px;', $product )
);
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else $min = 1;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else $max = 20;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$options .= '<option value="' . $count . '">' . $count . '</option>';
}
echo '<div class="quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
}
?>

WooCommerce Add Payment Type to Emails


WooCommerce send customers and store admins emails when new orders are placed, these emails contains all sorts of info relating to the order, however it is missing a couple of things that can be useful to customers or store admins.

One of the fields that is not present in the WooCommerce order emails are the payment type, some WooCommerce store admins would perhaps want to know this data in emails for decisions on whether to ship items immediately or to hold off for a while for money to clear.

To add the payment type to all WooCommerce emails or just admin email add the following code to your theme’s functions.php file, this is upgrade safe and the changes will stay in place after WooCommerce updates.

<?php
// Place the following code in your theme's functions.php file to add the payment type to all emails
add_action( 'woocommerce_email_after_order_table', 'wc_add_payment_type_to_emails', 15, 2 );
function wc_add_payment_type_to_emails( $order, $is_admin_email ) {
echo '<p><strong>Payment Type:</strong> ' . $order->payment_method_title . '</p>';
}
// Place the following code in your theme's functions.php file to add the payment type to admin emails only
add_action( 'woocommerce_email_after_order_table', 'wc_add_payment_type_to_admin_emails', 15, 2 );
function wc_add_payment_type_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo '<p><strong>Payment Type:</strong> ' . $order->payment_method_title . '</p>';
}
}
?>

WooCommerce Add Shipping Method to Emails


WooCommerce does add a lot of information to the emails that goes out to the customers and admin but there are some things that are not part of the emails and another one of those things are the Shipping Method.

The shipping method could useful to display in emails to let shop admin knows how to ship the order if these emails are being used as packaging slips, or to let the customer know what type of shipping they selected at checkout.

To add the shipping method to all WooCommerce emails or just add it to the admin emails add the following code to your theme’s functions.php file.

<?php
// Place the following code in your theme's functions.php file to add the shipping method to all emails
add_action( 'woocommerce_email_after_order_table', 'wc_add_shipping_method_to_emails', 15, 2 );
function wc_add_shipping_method_to_emails( $order, $is_admin_email ) {
echo '<p><strong>Shipping Method:</strong> ' . $order->get_shipping_method() . '</p>';
}
// Place the following code in your theme's functions.php file to add the shipping methid to admin emails only
add_action( 'woocommerce_email_after_order_table', 'wc_add_shipping_method_to_admin_emails', 15, 2 );
function wc_add_shipping_method_to_admin_emails( $order, $is_admin_email ) {
if ( $is_admin_email ) {
echo '<p><strong>Shipping Method:</strong> ' . $order->get_shipping_method() . '</p>';
}
}
?>

WooCommerce Allow Checkout in Multiples Only



Say you operate a WooCommerce store where you sell products that are shipped in boxes but want customers to make up their own boxes with different products, by default WooCommerce will only allow you to sell products in the the quantities you set the product up with and the customer will be able to check out with any amount of items in the cart.

For instance if you operate a online wine store with WooCommerce and would like to sell your wine by the bottle but only want customers to checkout if they have quantities selected that would make up a whole box, the following tutorial is for you.

With the code below you can setup your products that each product is a single bottle of wine and then force the customer to add multiples of any 6 products to the cart before they would be able to checkout. If the customer for example adds only 5 bottles to the cart and then tries to checkout they will be presented with a message to order in multiples of 6.

You can even take it a step further and only allow the rule to apply to products with a certain shipping class, this will allow you to sell single bottles as well as cases without having the multiples rule apply to the case products.

To force the customer to add multiples of a certain quantity to the cart before being able to checkout add the following code to your theme’s functions.php file.

<?php
// check that cart items quantities totals are in multiples of 6
add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities' );
function woocommerce_check_cart_quantities() {
$multiples = 6;
$total_products = 0;
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$total_products += $values['quantity'];
}
if ( ( $total_products % $multiples ) > 0 )
wc_add_notice( sprintf( __('You need to buy in quantities of %s products', 'woocommerce'), $multiples ), 'error' );
}
// Limit cart items with a certain shipping class to be purchased in multiple only
add_action( 'woocommerce_check_cart_items', 'woocommerce_check_cart_quantities_for_class' );
function woocommerce_check_cart_quantities_for_class() {
$multiples = 6;
$class = 'bottle';
$total_products = 0;
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$product = get_product( $values['product_id'] );
if ( $product->get_shipping_class() == $class ) {
$total_products += $values['quantity'];
}
}
if ( ( $total_products % $multiples ) > 0 )
wc_add_notice( sprintf( __('You need to purchase bottles in quantities of %s', 'woocommerce'), $multiples ), 'error' );
}
?>

WooCommerce Remove Product Description From Single Product Page


There are some cases where you would like to have you WooCommerce products not display a description, this tutorial will help you achieve just that.

By default WooCommerce has two description fields, a short description and a long description. The short description is usually an excerpt take from the long description unless you enter your own short description on the product page.

The short description is displayed right next to the image on the product page underneath the title, where as the long description is displayed in a tab at the bottom of the product page.

If you would like to either remove the WooCommerce short description or the long description tab, or both, you can do so by adding the following code to your theme’s functions.php file.

<?php
// remove product description from single product pages
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_filter( 'woocommerce_product_tabs', 'wc_remove_description_tab', 11, 1 );
function wc_remove_description_tab( $tabs ) {
if ( isset( $tabs['description'] ) ) {
unset( $tabs['description'] );
}
}
?>

 

Copyright @ 2013 WooCommerce Helper .

Designed by Kcon Technosoft