How to change product title with custom field in the order review section on the checkout page in woocommerce [closed]

↘锁芯ラ 提交于 2020-02-23 08:26:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!