mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-04-30 11:42:22 +08:00
https://stackoverflow.com/questions/77969312/change-specific-product-cart-item-name-in-woocommerce
15 lines
564 B
Text
15 lines
564 B
Text
add_action( 'woocommerce_before_calculate_totals', 'change_specific_cart_item_name' );
|
|
function change_specific_cart_item_name( $cart ) {
|
|
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
|
|
return;
|
|
|
|
$targeted_id = 134443; // HERE set the targeted product ID
|
|
$new_name = "The new product name"; // HERE set the desired new product name
|
|
|
|
// Loop through cart items
|
|
foreach ( $cart->get_cart() as $cart_item ) {
|
|
if ( $cart_item['product_id'] == $targeted_id ) {
|
|
$cart_item['data']->set_name($new_name);
|
|
}
|
|
}
|
|
}
|