私はこのクラスを持っています。それは複数のことを行いますが、これは単純化されたバージョンであるため、私の問題が何であるかがわかります。
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?
編集:
質問の変数の名前にタイプミスがありましたが、それは私のコードの問題ではありません。