Sunday 15 March 2015

How to change the Product Quantity to a Dropdown in WooCommerce

// 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 = '<option value="">Select quantity</option>';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$options .= '<option value="' . $count . '">' . $count . '</option>';
}
echo '<div class="quantity_select" style="' . $defaults['style'] . '">Quantity<select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';

WooCommerce: Remove related products info

Add this to your functions.php file:

function woocommerce_remove_related_products(){
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
add_action('woocommerce_after_single_product_summary', 'woocommerce_remove_related_products');

Thursday 12 March 2015

WooCommerce: Change the number of related products displayed in your shop

  1. Add the following code to the functions.php file of active theme
// Customize Woocommerce Related Products Output
 
 Example 1. Display 4 products in 2 columns
 
 function woocommerce_output_related_products() {
      woocommerce_related_products(4,2);       // Display 4 products in 2 columns
 }


Example 2. Display 4 products in 4 columns
 
// Customize Woocommerce Related Products Output
function woocommerce_output_related_products() {
      woocommerce_related_products(4,4);   // Display 4 products in 4 columns
} 

WooCommerce - Change number of products displayed per page

To change  number of products displayed per page in woocommerce, in your active theme functions.php

Put this in theme's functions.php


// Display 16 products per page.
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 16;' ), 20 );
 

Friday 6 March 2015

WooCommerce: Change add to cart text and link to redirect to single product page

Put the following in your theme’s functions.php file.

add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_to_cart_loop' );
 
function change_add_to_cart_loop( $product ) {
    global $product; // this may not be necessary as it should have pulled the object in already
 
    return '<a href="' . esc_url( $product->get_permalink( $product->id ) ) . '">READ MORE</a>';
}


I would recommend to add any custom PHP code or CSS changes to a child theme. This is to prevent the lost of this customization if the parent theme is ever updated automatically.

If you do not know how to create a child theme in WordPress, please reference this link http://codex.wordpress.org/Child_Themes

Wishlist button in products list page or category page

Add this to your functions.php theme's file


 
add_action('woocommerce_after_shop_loop_item', 'show_add_to_wishlist', 50 );
function show_add_to_wishlist()
{
  echo do_shortcode('[yith_wcwl_add_to_wishlist]');
}