custom field in order
-
Hi,
I have added a custom field in the order called “Cashback” https://prnt.sc/107369f as you can see here https://prnt.sc/107351n and here https://prnt.sc/10735dm using the following snippet:
function kia_add_cart_item_data( $cart_item, $product_id ){
if(get_post_meta($product_id,’cashback_’,true) != ”) {
$cart_item[‘Cashback’] = get_post_meta($product_id,’cashback_’,true);
}
return $cart_item;
}add_filter( ‘woocommerce_add_cart_item_data’, ‘kia_add_cart_item_data’, 10, 2 );
function kia_get_cart_item_from_session( $cart_item, $values ) {
if ( isset( $values[‘Cashback’] ) ){
$cart_item[‘Cashback’] = $values[‘Cashback’];
}
return $cart_item;
}add_filter( ‘woocommerce_get_cart_item_from_session’, ‘kia_get_cart_item_from_session’, 20, 2 ); function kia_add_order_item_meta( $item_id, $values ) {
if ( ! empty( $values[‘Cashback’] ) ) {
wc_add_order_item_meta( $item_id, ‘Cashback’, $values[‘Cashback’] );
}
}add_action( ‘woocommerce_add_order_item_meta’, ‘kia_add_order_item_meta’, 10, 2 ); function kia_get_item_data( $other_data, $cart_item ) {
if ( isset( $cart_item[‘Cashback’] ) ){
$other_data[] = array( ‘key’ => __( ‘Cashback’, ‘kia-plugin-textdomain’ ), ‘display’ => sanitize_text_field( $cart_item[‘Cashback’] ) );
}
return $other_data;
}add_filter( ‘woocommerce_get_item_data’, ‘kia_get_item_data’, 10, 2 ); function kia_order_item_product( $product, $order_item ){
if( $order_item->get_meta( ‘Cashback’ ) ){
$product->add_meta_data( ‘Cashback’, $order_item->get_meta( ‘Cashback’ ), true );
}
return $product;
}add_filter( ‘woocommerce_order_item_product’, ‘kia_order_item_product’, 10, 2 );`
I am trying to also add the field “Costo de envio” https://prnt.sc/1073828 but if i try to use thesame snippet i get an error saying that Cannot redeclare the kia_add_cart_item_data function.
I dont know much about coding. Can you please tell me what i need to change so i can add the second custom field value
- The topic ‘custom field in order’ is closed to new replies.