问题
How to change product title with a custom field in the order review section on the checkout page in woocommerce. i have an advanced custom field stock_number i want to change the product title with stock_number field in the product review on the checkout page.
回答1:
function woocommerce_update_product_title($title, $cart_item){
if( is_checkout() || is_cart() ) : //Check Checkout or Cart Page
$stock_number = get_post_meta($cart_item['product_id'], 'stock_number',true);
return !empty( $stock_number ) ? $stock_number : $title;
endif;
return $title;
}
add_filter('woocommerce_cart_item_name', 'woocommerce_update_product_title', 10, 2);
Please try this code which could help you
回答2:
To have full control over this, you can directly edit the template files and alter the product title.
Copy the template file from the path of your website and paste it inside your themes folder.
Copy the file from:
wp-content/plugins/woocommerce/templates/checkout/review-order.php
Paste it to:
wp-content/themes/themename/woocommerce/checkout/review-order.php
Replace the below code:
<th class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
New Code:
<?php $stock_number = get_field('stock_number', $product_id); ?>
<th class="product-name"><?php echo $stock_number; ?></th>
来源:https://stackoverflow.com/questions/60188986/how-to-change-product-title-with-custom-field-in-the-order-review-section-on-the