Closed ole1986 closed 4 years ago
Some useful snipped
<?php
// show the custom meta data on the cart and checkout pages
add_filter( 'woocommerce_get_item_data', 'tp_get_custom_item_data', 10, 2 );
function tp_get_custom_item_data( $item_data, $cart_item ) {
if( isset( $cart_item['size'] ) ) {
$item_data[] = array( 'name' => 'Size', 'value' => $cart_item['size'] );
}
return $item_data;
}
// add custom meta to order
add_action( 'woocommerce_new_order_item', 'tp_add_custom_meta_to_order', 99, 3 );
function tp_add_custom_meta_to_order( $item_id, $item, $order_id ) {
if( ! isset( $item->legacy_values ) ) { // applies to order_item_shipping
return;
}
if( isset( $item->legacy_values['size'] ) ) {
wc_add_order_item_meta( $item_id, 'Size', $item->legacy_values['size'] );
}
}
A good place to add subscribtion section would be in action hook woocommerce_cart_contents
// add the action
add_action( 'woocommerce_cart_actions', 'action_woocommerce_cart_actions, 10, 0 );
Followed by hook woocommerce_update_cart_action_cart_updated
to save its post data
add_action( 'woocommerce_update_cart_action_cart_updated', 'on_action_cart_updated', 20, 1 );
function on_action_cart_updated( $cart_updated ){
// save some data
WC()->session->set( 'foo', 'some-data' );
// after checkout proceeded, get the data to store into WC_Order meta data
///WC()->session->get( 'foo' );
}
This PR has its primary focus on moving the subscription concept from product to orders.
Domain
meta data stored in WC_Order into its individual WC_Order_Item meta data for compatibility reason