skip to Main Content

I want to change the text of the place order text if the order total is 0 to be something different which is for the free orders.

I tried this

add_filter( 'woocommerce_order_button_text', 'misha_custom_button_text' );
 
function misha_custom_button_text( $button_text ) {
   return 'Submit'; // new text is here 
}

I hope i find a solution
Best Regards

2

Answers


  1. Replace your function with below and try once if it work for you.

    function misha_custom_button_text($button_text) {
        $total = WC()->cart->total;
    
        if ($total == 0) {
            $button_text = "Submit";
        }
        return $button_text;
    }
    

    You can get cart total from WC()->cart->cart_contents_total and apply condition whatever you want.

    Hope this helps you.

    Login or Signup to reply.
  2. Replace your code with this code.

    add_filter('woocommerce_order_button_text', 'misha_custom_button_text', 9999);
    
    function misha_custom_button_text($button_text) {
        global $woocommerce;
        $total = $woocommerce->cart->total;
        if ($total == 0) {
            $button_text = "Free Orders";
        }
        return $button_text;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search