Skip to content

Instantly share code, notes, and snippets.

@anisur2805
Created February 8, 2024 09:09
Show Gist options
  • Select an option

  • Save anisur2805/7720844cb73f13826d303c1b93811628 to your computer and use it in GitHub Desktop.

Select an option

Save anisur2805/7720844cb73f13826d303c1b93811628 to your computer and use it in GitHub Desktop.
Customize the product titles displayed on the WooCommerce Cart page by incorporating additional custom elements.
<?php
/*
Preview image: https://i.imgur.com/5FxW6x3.png
This is for modify the product name in cart page.
*/
add_filter( 'woocommerce_product_title', 'cart_product_title', 20, 2 );
function cart_product_title( $title, $values ) {
return $title . ' extra cheese burger';
}
/*
This code is responsible for add the extra content after description in cart page.
*/
add_filter( 'woocommerce_get_item_data', 'customizing_cart_item_data', 10, 2 );
function customizing_cart_item_data( $cart_data, $cart_item ) {
global $product;
$post_id = $cart_item['product_id'];
$description = $cart_item['data']->get_description();
$meal_available_date = get_post_meta( $post_id, 'meal_available_date_dp_field_alt', true );
if ( $cart_item['variation_id'] > 0 && empty( $description ) ) {
$parent_product = wc_get_product( $cart_item['product_id'] );
$description = $parent_product->get_description();
}
if ( ! empty( $description ) ) {
$cart_data[] = array(
'key' => __( 'Delivery date', 'woocommerce' ),
'value' => $meal_available_date,
'display' => $meal_available_date,
);
}
return $cart_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment