unable to get value from global variable in php

This is the code I have in one of my php plugin file.

add_filter('woocommerce_cart_totals_order_total_html','test_func');
function test_func() {
    global $woocommerce, $totalship;
    $cart_subtotal = (float)$woocommerce->cart->subtotal;
    if( $cart_subtotal < 1000 ) {
    $cart_subtotal01 = $woocommerce->cart->get_cart_subtotal();
    $cart_subtotal11 = explode('</span>', $cart_subtotal01);
    $text_tax ='';
    if($cart_subtotal11[1]) {
        $text_tax = $cart_subtotal11[1];
    }
    $allcarttotal = $cart_subtotal+$totalship;  
    $value = '<strong><span class="amount">Rs.&nbsp;' . $allcarttotal . '</span>'.$text_tax.'</strong>';
    $citrus_total_val = $value;
    return $citrus_total_val;
        //return $value;
    }
    else {
    $docart_total = $cart_subtotal - $totalship;
    $citrus_total_val = $docart_total;
    return $citrus_total_val;
        //return $docart_total;
    }
}
global $citrus_total_val;

I am trying to pass the value of $citrus_total_val to another plugin for payment gateway.

Read More

This is the code:

  global $citrus_total_val; 

  //Setup URL and signatue etc.
  $currencycode = get_woocommerce_currency();       
  $merchantTxnId = $order_id;
  $orderAmount = $citrus_total_val;

But the value is not passed here. What am I doing wrong?

Related posts

2 comments

  1. Try this:

    $citrus_total_val = '';
    add_filter('woocommerce_cart_totals_order_total_html','test_func');
    function test_func() {
        global $woocommerce, $totalship;
        global $citrus_total_val;
        $cart_subtotal = (float)$woocommerce->cart->subtotal;
        if( $cart_subtotal < 1000 ) {
        $cart_subtotal01 = $woocommerce->cart->get_cart_subtotal();
        $cart_subtotal11 = explode('</span>', $cart_subtotal01);
        $text_tax ='';
        if($cart_subtotal11[1]) {
            $text_tax = $cart_subtotal11[1];
        }
        $allcarttotal = $cart_subtotal+$totalship;  
        $value = '<strong><span class="amount">Rs.&nbsp;' . $allcarttotal . '</span>'.$text_tax.'</strong>';
        $citrus_total_val = $value;
        return $citrus_total_val;
            //return $value;
        }
        else {
        $docart_total = $cart_subtotal - $totalship;
        $citrus_total_val = $docart_total;
        return $citrus_total_val;
            //return $docart_total;
        }
    }
    
  2. try putting it in the function, like you did with global $woocommerce, $totalship;

    add_filter('woocommerce_cart_totals_order_total_html','test_func');
    function test_func() {
        global $woocommerce, $totalship;
        global $citrus_total_val;
        $cart_subtotal = (float)$woocommerce->cart->subtotal;
        if( $cart_subtotal < 1000 ) {
        $cart_subtotal01 = $woocommerce->cart->get_cart_subtotal();
        $cart_subtotal11 = explode('</span>', $cart_subtotal01);
        $text_tax ='';
        if($cart_subtotal11[1]) {
            $text_tax = $cart_subtotal11[1];
        }
        $allcarttotal = $cart_subtotal+$totalship;  
        $value = '<strong><span class="amount">Rs.&nbsp;' . $allcarttotal . '</span>'.$text_tax.'</strong>';
        $citrus_total_val = $value;
        return $citrus_total_val;
            //return $value;
        }
        else {
        $docart_total = $cart_subtotal - $totalship;
        $citrus_total_val = $docart_total;
        return $citrus_total_val;
            //return $docart_total;
        }
    }
    

Comments are closed.