Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
Display purchase note and attribute on cart and checkout page in WooCommerce

The following code works and adds the purchase note to the cart items.

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;
}

However, I always get ":" as result, for products that don't have a note.

I also need to add a specific attribute aswell under the note.

Any advice?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  • The colon is automatically added to the key. Because you only use name, this will be added at the end.
  • You can use get_purchase_note()

So you get:

// 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda