0
votes

I am trying to display some custom data before my product name in cart page and checkout page. Means my cart will be like this

  1. customfield + originalproductname $150 $150

I have seen some links like Display Custom Field's Value in Woocommerce Cart & Checkout items But in the solution I have also seen some $cart_data and $cart item. Is it the cart data received from $cart = WC()->cart->get_cart();

Anyone please help. Am new to word-press and filters

1

1 Answers

1
votes

Option 1: Override the template files You can do some Template Overriding, Copy cart.php from templates cart folder and review-order.php from checkout folder and put them in your theme's directory with the same directory structure as you copied them and do the changes you wish to the copied files.

Option 2: Use filters:

You can use filters, i found the woocommerce_cart_item_name which changes the title in cart and checkout page as you want

add_filter('woocommerce_cart_item_name', function($title, $cart_item){
  $my_field = get_post_meta($cart_item['product_id'], 'my_custom_field_key', true);


  return sprintf( '<a href="%s">%s - %s</a>', esc_url( get_permalink($cart_item['product_id']) ), $my_field, get_the_title($cart_item['product_id']) );
}, 10, 2);

you can look for more filters and actions by reading the template files in woocommerce plugin's templates directory