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

188
Views
Mostrar la nota de compra y el atributo en el carrito y la página de pago en WooCommerce

El siguiente código funciona y agrega la nota de compra a los artículos del carrito.

 add_filter( 'woocommerce_get_item_data', 'wc_test', 10, 2 ); function wc_test ( $other_data, $cart_item ){ $post_data = get_post( $cart_item['product_id'] ); $other_data[] = array( 'name' => $post_data->_purchase_note ); return $other_data; }

Sin embargo, siempre obtengo ":" como resultado, para productos que no tienen una nota.

También necesito agregar un atributo específico debajo de la nota.

¿Algún consejo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  • Los dos puntos se agregan automáticamente a la clave. Debido a que solo usa el nombre, este se agregará al final.
  • Puedes usar get_purchase_note()

Entonces obtienes:

 // Display on cart & checkout pages function filter_woocommerce_get_item_data( $item_data, $cart_item ) { // Get an instance of the WC_Product object $product = $cart_item['data']; // Get purchase_note $purchase_note = $product->get_purchase_note(); // Get the product attribute value (adjust if desired) $attribute = $product->get_attribute( 'pa_color' ); // When empty if ( empty ( $attribute ) ) { $attribute = ''; } // NOT empty if ( ! empty( $purchase_note ) ) { $item_data[] = array( 'key' => __( 'Note', 'woocommerce' ), 'value' => $purchase_note . $attribute, 'display' => $purchase_note . $attribute, ); } return $item_data; } add_filter( 'woocommerce_get_item_data', 'filter_woocommerce_get_item_data', 10, 2 );
over 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!