Hi All,
I will be sharing with you most common Woocommerce hooks that I find very useful. I have been working with Woocommerce for around 2 years. And most of the clients indeed have the same request over and over. For this post, I just looked in my previous client and collected all the information that I think is necessary. Please insert this snippet in your functions.php
1. Change the “Add to cart button” in archive page
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // 2.1 + function woo_archive_custom_cart_button_text() { return __( 'Your custom text', 'woocommerce' ); }
2. Change the “Add to cart button” in single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 + function woo_custom_cart_button_text() { return __( 'Custom Text Text', 'woocommerce' ); }
3. Reduce the strength of password meter when user sign up
add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' ); function reduce_min_strength_password_requirement( $strength ) { // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything). return 2; }
4. Remove and renaming single product tab. Woocommerce has 3 default product tabs which are description, reviews, and additional information.
With the filter “woocommerce_product_tabs” unset the default tabs and add any tabs you prefer. In the example below, I added 4 new tabs, which is about, quality, sizing, and shipping tab.
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 ); function woo_remove_product_tabs( $tabs ) { unset( $tabs['description'] ); unset( $tabs['reviews'] ); // Remove the reviews tab unset( $tabs['additional_information'] ); $tabs['about_tab'] = array( 'title' => __( 'About', 'woocommerce' ), 'priority' => 10, 'callback' => 'woo_about_tab_content' ); $tabs['quality_tab'] = array( 'title' => __( 'Quality', 'woocommerce' ), 'priority' => 20, 'callback' => 'woo_quality_tab_content' ); $tabs['sizing_tab'] = array( 'title' => __( 'Sizing', 'woocommerce' ), 'priority' => 30, 'callback' => 'woo_sizing_tab_content' ); $tabs['shipping_tab'] = array( 'title' => __( 'Shipping', 'woocommerce' ), 'priority' => 40, 'callback' => 'woo_shipping_tab_content' ); return $tabs; } function woo_quality_tab_content() { echo '<div></div>'; } function woo_about_tab_content() { echo '<div></div>'; } function woo_sizing_tab_content() { echo '<div></div>'; } function woo_shipping_tab_content() { echo '<div></div>'; }
5. Renaming the label in the checkout field
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); function custom_override_checkout_fields( $fields ) { $fields['billing']['billing_email']['label'] = 'Email'; $fields['billing']['billing_address_2']['label'] = 'House Number *'; $fields['billing']['billing_address_2']['placeholder'] = 'House Number'; $fields['billing']['billing_number_suffix']['label'] = 'House Number suffix'; $fields['shipping']['shipping_address_2']['label'] = 'House Number *'; $fields['shipping']['shipping_address_2']['placeholder'] = 'House Number'; $fields['shipping']['shipping_number_suffix']['label'] = 'House Number suffix'; $fields['billing']['billing_postcode']['label'] = 'Postcode'; $fields['billing']['billing_postcode']['placeholder'] = 'Postcode'; $fields['billing']['billing_city']['label'] = 'City'; $fields['shipping']['shipping_postcode']['label'] = 'Postcode'; return $fields; }