无法从php中的全局变量中获取值

时间:2015-10-09 13:21:56

标签: php wordpress global-variables

这是我在我的一个php插件文件中的代码。

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;

我正在尝试将$ citrus_total_val的值传递给另一个支付网关插件。

这是代码:

  global $citrus_total_val; 

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

但这里没有传递价值。我做错了什么?

2 个答案:

答案 0 :(得分:0)

试试这个:

$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;
    }
}

答案 1 :(得分:0)

尝试将其放入功能中,就像使用全球$ 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;
    }
}