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

453
Views
¿Cómo concatenar el nombre de un producto con el nombre de sus atributos después de "woocommerce_thankyou" hook fires?
$order_items = $order->get_items(); foreach ($order_items as $item_key => $item) { $product = $item->get_product(); // Get the WC_Product Object if( $product->is_type( 'variation' ) ){ $attributes = $product->get_attributes(); $variation_names = array(); if( $attributes ){ foreach ( $attributes as $key => $value) { $variation_key = end(explode('-', $key)); $variation_names[] = ucfirst($variation_key) .' : '. $value; } } echo implode( '<br>', $variation_names ); } }

La salida de este código es la siguiente:

Después del eco:

%da%86%d8%b1%d8%a8%db%8c

e incompatible con el idioma persa

Necesito que el resultado final sea algo como esto:

"Nombre del producto, color: rojo, tamaño: 85". . . . . . . . . .

Gracias a todos los amigos;

Esta es mi nueva solución y ha sido probada y funciona:

Nota : atributos $ etiqueta de valor agregado:

 //اضافه کردن نام ویژگی به اسم محصول //Add attribute label name to product name if( $product->is_type( 'variation' ) ){ $s =''; $s1 = ''; foreach ($product->get_attributes() as $taxonomy => $attribute_obj ) { // Get the attribute label $attribute_label_name = wc_attribute_label($taxonomy); //convert to array $attribute_arr = json_decode(json_encode($attribute_obj),true); $term_name = get_term_by( 'slug', $attribute_arr, $taxonomy)->name; $s = $s . $s1 .$attribute_label_name.':'.$term_name; $s1 = ', '; } $name = $name . '(' .$s. ')'; echo '<p>' . $name. '</p>'; }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar wc_attribute_label() para obtener el nombre de etiqueta adecuado del atributo y puede usar get_title() para obtener el título del producto. prueba el siguiente código.

 function display_attributes_and_name( $order_id ){ $order = wc_get_order($order_id); //<--check this line $order_items = $order->get_items(); foreach ($order_items as $item_key => $item) { $product = $item->get_product(); // Get the WC_Product Object if( $product->is_type( 'variation' ) ){ $attributes = $product->get_attributes(); $variation_names = array(); if( $attributes ){ foreach ( $attributes as $key => $value) { $variation_key = end(explode('-', $key)); $variation_names[] = wc_attribute_label( $variation_key ) .' : '. $value; } } echo $product->get_title().', '.implode( ',', $variation_names ); } } } add_action( 'woocommerce_thankyou', 'display_attributes_and_name', 10, 1 );

Probado y funciona

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

Lo que dijo @Bhautik

Más

"Incompatible con el idioma persa"

Para mí, parece que ha sido codificado (¡quizás por su navegador!), así que para decode , podríamos usar la función urldecode , así:

 $test = '%da%86%d8%b1%d8%a8%db%8c'; $decode_test = urldecode($test); echo $decode_test;

Lo que generará esto:

 چربی

¿Tiene sentido?

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!