show cart data in woocommerce code example

Example 1: how to add woocommerce cart counter

add_filter( 'woocommerce_add_to_cart_fragments', 'misha_add_to_cart_fragment' );
 
function misha_add_to_cart_fragment( $fragments ) {
 
	global $woocommerce;
 
	$fragments['.misha-cart'] = '<a href="' . wc_get_cart_url() . '" class="misha-cart">Cart (' . $woocommerce->cart->cart_contents_count . ')</a>';
 	return $fragments;
 
 }

Example 2: Woocommerce Update the Order meta with Custom Field value [Custom Field Display 1]

/**
 * Update the order meta with field value
 *
 * PHP Custom Feild Value
 * 
 * 
 */

add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ( ! empty( $_POST['store_location'] ) ) {
        update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['store_location'] ) );
    }
}

Tags:

Misc Example