1

私はこのクラスを持っています。それは複数のことを行いますが、これは単純化されたバージョンであるため、私の問題が何であるかがわかります。

class WC_Product_Variation extends WC_Product {

    public $cliente_a="";

    public function __construct( $variation, $args = array() ) {

        //does some stuff to other variables

        if ( isset( $this->product_custom_fields['_cliente_a'][0] ) ) {
            $this->variation_has_cliente_a = true;
            $this->cliente_a               = $this->product_custom_fields['_cliente_a'][0];
        }
    }
    public function clientPrice($c){
        $aum=0;
        if($c=='customer'){$aum=$this->$cliente_a;}
        /*This should do more stuff but since 
        the basics aren't working I simplified to this*/
        return $aum;
    }
}

このクラスは Woocommerce からのものです。何か変更があれば、Wordpress で使用していますが、基本的に私がやっていることは次のとおりです。

 echo $_product->clientPrice('customer');

そして、それは何も返しません。0 ですらありません。

 echo $_product->cliente_a;

私は 20 という適切な値を取得します。wtf?

編集:

質問の変数の名前にタイプミスがありましたが、それは私のコードの問題ではありません。

4

3 に答える 3

3

次のようにメンバー変数にアクセスします。

$this->cliente_c

これではありません$this->$cliente_c

于 2013-08-02T07:51:54.373 に答える
1

clientPrice が返されたようcliente_cで、他の呼び出しが返されますcliente_a。それらは非常に異なる可能性があります

 $aum=$this->$cliente_c;

どちらかであるべき

$aum=$this->cliente_c;

また

$aum=$this->cliente_a;
于 2013-08-02T07:52:00.043 に答える
0

関数clientPriceは戻る$this->cliente_cため、と同じではありません$_product->cliente_a

于 2013-08-02T07:54:38.830 に答える