我做过类似的事情:
<?php
class Cart {
protected static $_instance = null;
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
//....
}
$cart = new Cart();
$cart->init();
function EVA_Cart() {
return Cart::instance();
}
function deposit_total(){
$cart = EVA_Cart();
$totals = array_sum( $cart->deposits );
return wc_price( $totals );
}
这是最好的方式吗?