php - wordpress function breaks wp-admin -


i've created function in custom woocommerce site. works great on frontend, wp-admin breaks. wp-admin shows http-500 error.

this function:

// set currency based on visitor country  function geo_client_currency($client_currency) {         $country = wc()->customer->get_shipping_country();            switch ($country) {             case 'gb': return 'gbp'; break;             default: return 'eur'; break;         }  } add_filter('wcml_client_currency','geo_client_currency'); 

i've set wp-debug on true , throw message:

fatal error: uncaught error: call member function get_shipping_country() on null in 

so has with: $country = wc()->customer->get_shipping_country(); can't find it. maybe can me this.

thanks in advanced.

the customer property isn't set instance of wc_customer in backend can't call get_shipping_country() method.

check customer isn't null (default) before using it.

function geo_client_currency( $client_currency ) {     if ( wc()->customer ) {         $country = wc()->customer->get_shipping_country();          /**          * assuming more going added otherwise switch overkill.          * short example: $client_currency = ( 'gb' === $country ) ? 'gbp' : 'eur';          */         switch ( $country ) {             case 'gb':                  $client_currency = 'gbp';                  break;              default:                  $client_currency = 'eur';         }     }      return $client_currency; } add_filter( 'wcml_client_currency', 'geo_client_currency' ); 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -