mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/68073029/woocommerce-display-custom-text-under-products-on-checkout-page-based-on-shippi
21 lines
798 B
Text
21 lines
798 B
Text
add_filter( 'woocommerce_cart_item_name', 'bks_custom_text_cart_item_name', 10, 3 );
|
|
function bks_custom_text_cart_item_name( $item_name, $cart_item, $cart_item_key ) {
|
|
|
|
if( ! ( is_cart() || is_checkout()) ) // CHANGE HERE
|
|
return $item_name;
|
|
|
|
|
|
$shipping_class_1 = '5-gallon';
|
|
$shipping_class_2 = '10-gallon';
|
|
|
|
$shipping_class = $cart_item['data']->get_shipping_class();
|
|
|
|
if( $shipping_class === $shipping_class_1 ) {
|
|
$item_name .= '<br /><div class="item-shipping-class">' . __("Please call confirm shipping rates", "woocommerce") . '</div>';
|
|
}
|
|
elseif( $shipping_class === $shipping_class_2 ) {
|
|
$item_name .= '<br /><div class="item-shipping-class">' . __("Some different message…", "woocommerce") . '</div>';
|
|
}
|
|
|
|
return $item_name;
|
|
}
|