October 12, 2022

Woocommerce Useful Snippets for WordPress Themes

Woocommerce is best plugin in current market after it's sucess lots of demand

we cover in this articale how to add/remove fuctionality in woocommerce theme, these code snippets help you building your dynamic site

1 . Third party theme support WooCommerce snippet

code is used for declaring WooCommerce support in your theme

function woocommerce_support() {

add_theme_support( 'woocommerce' );

}
add_action( 'after_setup_theme', 'woocommerce_support' );

2 . How to Change shop page title

you can replace woocommerce default shop page via WC snippet

function wc_shop_page_title( $page_title ) {

if( 'Shop' == $page_title) {

return "Usercode shop";

}

}

add_filter( 'woocommerce_page_title', 'wc_shop_page_title');

3. How to change add-to-cart buttom in WC single page

Single page cart button text change code

/ To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); 
function woocommerce_custom_single_add_to_cart_text() { return __( 'Buy Now', 'woocommerce' ); }

4. How to change add-to-cart buttom in WC archives page

WC Archive page button text change

// To change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' );  
function woocommerce_custom_product_add_to_cart_text() {  return __( 'Buy Now', 'woocommerce' );}

5. Skip cart page and redirect to the checkout page after click add to cart

function add_to_cart_checkout_redirect() {

wp_safe_redirect( get_permalink( get_option( 'woocommerce_checkout_page_id' ) ) );

die();

}

add_action( 'woocommerce_add_to_cart', 'add_to_cart_checkout_redirect', 16 );

Social Share Button :

Leave a Reply

Your email address will not be published. Required fields are marked *

chevron-down-circle
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram