Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
No se debe acceder directamente a las propiedades del pedido - WooCommerce 3.0

Acabo de actualizar mi sitio web local de WooCommerce a 3.0. Todo funciona perfectamente con normalidad, pero he notado que con la depuración activada recibo cientos de los siguientes avisos:

[05-Apr-2017 12:25:00 UTC] PHP Notice: id was called <strong>incorrectly</strong>. Order properties should not be accessed directly. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.0.) in C:\xampp\htdocs\dev\wp-includes\functions.php on line 4137

Entonces parece que WooCommerce está retrocediendo para poder llamar directamente a los datos del pedido. Un ejemplo que activa este código es esta función en mi archivo functions.php:

 function eden_woocommerce_order_number($original, $order) { return 'EDN-' . str_pad($order->id, 10, 0, STR_PAD_LEFT); }

Esta función simplemente agrega "EDN" al inicio de la ID del pedido y lo completa con 10 caracteres, pero a WooCommerce no le gusta cómo llamo $order : ¿cuál sería la mejor manera de reescribir una función de este tipo que 3.0 es feliz? ¿con?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

dice "id fue llamado incorrectamente . No se debe acceder directamente a las propiedades del pedido".

Prueba $order->get_id()

about 4 years ago · Santiago Trujillo Report

0

Tal vez sea útil para otros también. Aquí hay algunas cosas relacionadas con todas las funciones de los valores a los que se accede directamente a través de la función mágica.

Esta función es de Woocommerce 3.0

 if ( 'completed_date' === $key ) { return $this->get_date_completed() ? gmdate( 'Ymd H:i:s', $this->get_date_completed()->getOffsetTimestamp() ) : ''; } elseif ( 'paid_date' === $key ) { return $this->get_date_paid() ? gmdate( 'Ymd H:i:s', $this->get_date_paid()->getOffsetTimestamp() ) : ''; } elseif ( 'modified_date' === $key ) { return $this->get_date_modified() ? gmdate( 'Ymd H:i:s', $this->get_date_modified()->getOffsetTimestamp() ) : ''; } elseif ( 'order_date' === $key ) { return $this->get_date_created() ? gmdate( 'Ymd H:i:s', $this->get_date_created()->getOffsetTimestamp() ) : ''; } elseif ( 'id' === $key ) { return $this->get_id(); } elseif ( 'post' === $key ) { return get_post( $this->get_id() ); } elseif ( 'status' === $key ) { return $this->get_status(); } elseif ( 'post_status' === $key ) { return get_post_status( $this->get_id() ); } elseif ( 'customer_message' === $key || 'customer_note' === $key ) { return $this->get_customer_note(); } elseif ( in_array( $key, array( 'user_id', 'customer_user' ) ) ) { return $this->get_customer_id(); } elseif ( 'tax_display_cart' === $key ) { return get_option( 'woocommerce_tax_display_cart' ); } elseif ( 'display_totals_ex_tax' === $key ) { return 'excl' === get_option( 'woocommerce_tax_display_cart' ); } elseif ( 'display_cart_ex_tax' === $key ) { return 'excl' === get_option( 'woocommerce_tax_display_cart' ); } elseif ( 'cart_discount' === $key ) { return $this->get_total_discount(); } elseif ( 'cart_discount_tax' === $key ) { return $this->get_discount_tax(); } elseif ( 'order_tax' === $key ) { return $this->get_cart_tax(); } elseif ( 'order_shipping_tax' === $key ) { return $this->get_shipping_tax(); } elseif ( 'order_shipping' === $key ) { return $this->get_shipping_total(); } elseif ( 'order_total' === $key ) { return $this->get_total(); } elseif ( 'order_type' === $key ) { return $this->get_type(); } elseif ( 'order_currency' === $key ) { return $this->get_currency(); } elseif ( 'order_version' === $key ) { return $this->get_version(); } elseif ( is_callable( array( $this, "get_{$key}" ) ) ) { return $this->{"get_{$key}"}(); } else { return get_post_meta( $this->get_id(), '_' . $key, true ); }
about 4 years ago · Santiago Trujillo Report

0

Deberías llamar a la función woo get. añadir get_ ()

Por ejemplo, cambie: $order->status a $order->get_status()

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!