Change “Add to Cart” text on shop page and single product page
Modify the “Add to Cart” button text for simple and variable products:

/**
* Modify the "Add to Cart" button text for Simple and Variable Products.
*
* This snippet customizes the text on the "Add to Cart" button for
* both the shop/archive page and single product pages.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
// Change "Add to Cart" text on shop/archive page
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_add_to_cart_text_archive', 10, 1 );
function custom_add_to_cart_text_archive( $text ) {
return __( 'Your Custom Text', 'woocommerce' );
}
// Change "Add to Cart" text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_text', 10, 1 );
function custom_add_to_cart_text( $text ) {
return __( 'Your Custom Text', 'woocommerce' );
}
Redirect to Checkout After Adding to Cart
Automatically redirect customers to the checkout page as soon as they add an item to their cart:
/**
* Disable AJAX Add to Cart on the Shop page
*
* This snippet lets you disable AJAX Add to Cart on the Shop page.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'wp_enqueue_scripts', 'disable_ajax_add_to_cart_on_shop' );
function disable_ajax_add_to_cart_on_shop() {
if (is_shop() || is_product_category()) {
wp_dequeue_script( 'wc-add-to-cart' );
}
}
// Redirect to checkout after adding to cart
add_filter( 'woocommerce_add_to_cart_redirect', 'custom_add_to_cart_redirect' );
function custom_add_to_cart_redirect() {
return wc_get_checkout_url();
}
Remove Related Products from Product Pages
Remove the “Related Products” section from product pages:
/**
* Remove Related Products from Product Pages
*
* This snippet allows you to remove the "Related Products: from all product pages.
* This snippet is not compatible with the WooCommerce Checkout Block.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
Set Minimum Order Amount for Checkout (Not compatible with the Checkout block)
Enforces a minimum order amount for checkout:
/**
* Set Minimum Order Amount for Checkout
*
* This snippet allows you to enforce a minimum order amount in order to check out.
* This snippet is not compatible with the WooCommerce Checkout Block.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'woocommerce_checkout_process', 'custom_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'custom_minimum_order_amount' );
function custom_minimum_order_amount() {
$minimum = 200; // Set minimum amount
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
wc_print_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to proceed to checkout.',
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
} else {
wc_add_notice(
sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to proceed to checkout.',
wc_price( WC()->cart->total ),
wc_price( $minimum )
), 'error'
);
}
}
}
Automatically Apply a Coupon on Checkout
Automatically apply a specific coupon to the cart:

/**
* Automatically Apply a Coupon on Checkout
*
* This snippet allows you to automatically apply a coupon on checkout.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'woocommerce_before_cart', 'apply_coupon_automatically' );
add_action( 'woocommerce_before_checkout_form', 'apply_coupon_automatically' );
function apply_coupon_automatically() {
$coupon_code = 'test'; // Replace with the actual coupon code you want to apply.
// Check if the cart does not already have the coupon applied
if ( ! WC()->cart->has_discount( $coupon_code ) ) {
WC()->cart->apply_coupon( $coupon_code );
wc_print_notices();
}
}
Add a Custom Fee to Checkout
Add a custom fee to the WooCommerce checkout, for example, a handling fee or packaging fee:

/**
* Add a Custom Fee to Checkout
*
* This snippet lets you add a custom fee to checkout. For example, a handling fee or
* a packaging fee.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'woocommerce_cart_calculate_fees', 'add_custom_checkout_fee' );
function add_custom_checkout_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
WC()->cart->add_fee( 'Handling Fee', 5 );
}
Hide Prices for Logged-Out Users
You can hide product prices for visitors who are not logged in:

/**
* Hide Prices for Logged-Out Users
*
* This snippet lets you hide product prices for logged-out users.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'wp', 'hide_prices_for_logged_out_users' );
function hide_prices_for_logged_out_users() {
if ( ! is_user_logged_in() && ! is_admin() ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
Display a Free Shipping Notice (Not compatible with the Cart block)
Show a custom message on the Cart page when the customer qualifies for free shipping:

/**
* Display a Free Shipping Notice
*
* This snippet lets you to display a free shipping notice.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_action( 'woocommerce_before_cart', 'custom_free_shipping_notice' );
function custom_free_shipping_notice() {
$min_amount = 50; // Set minimum amount for free shipping
$current_total = WC()->cart->subtotal;
if ( $current_total >= $min_amount ) {
echo '<div class="woocommerce-info">Congrats! You qualify for free shipping.</div>';
}
}
WooCommerce Reviews Display Name as “F.Lastname”
Modify the Reviews display name to “F.Lastname”:

/**
* Modify WooCommerce Product Review Author Format
*
* This snippet changes the display of product review authors
* to "F. Lastname" format instead of showing their full name.
*
* Usage: Add this to your theme's functions.php or a custom plugin.
*/
add_filter('get_comment_author', 'comments_filter_uprise', 10, 1);
function comments_filter_uprise( $author ) {
$comment = get_comment(); // Retrieve the comment object
if ( $comment ) {
// Try getting user by email
$user = get_user_by('email', $comment->comment_author_email);
if ( $user ) {
// Format the author name as "F. Lastname"
return substr($user->first_name, 0, 1) . '. ' . $user->last_name;
}
// If no user found, try by user ID (in case it's a registered user)
if ( $comment->user_id ) {
$user = get_userdata($comment->user_id);
if ( $user ) {
return substr($user->first_name, 0, 1) . '. ' . $user->last_name;
}
}
}
// Default: return the original comment author
return $author;
}