Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add student data to cart item.
- *
- * @param array $cart_item_data
- * @param int $product_id
- * @param int $variation_id
- *
- * @return array
- */
- function bsc_add_student_data_to_cart_item( $cart_item_data, $product_id, $variation_id ) {
- $booking_student = filter_input( INPUT_POST, 'booking-student' );
- if ( empty( $booking_student ) ) {
- return $cart_item_data;
- }
- $cart_item_data['booking-student'] = $booking_student;
- return $cart_item_data;
- }
- add_filter( 'woocommerce_add_cart_item_data', 'bsc_add_student_data_to_cart_item', 10, 3 );
- /**
- * Display student data text in the cart.
- *
- * @param array $item_data
- * @param array $cart_item
- *
- * @return array
- */
- function bsc_display_student_booking_data_in_cart( $item_data, $cart_item ) {
- if ( empty( $cart_item['booking-student'] ) ) {
- return $item_data;
- }
- $student_object = get_post( $cart_item['booking-student'] );
- $item_data[] = array(
- 'key' => __( 'Student', 'bsc-translation' ),
- 'value' => wc_clean($student_object->post_title),
- 'display' => '',
- );
- return $item_data;
- }
- add_filter( 'woocommerce_get_item_data', 'bsc_display_student_booking_data_in_cart', 10, 2 );
- /**
- * Add engraving text to order.
- *
- * @param WC_Order_Item_Product $item
- * @param string $cart_item_key
- * @param array $values
- * @param WC_Order $order
- */
- function bsc_add_student_date_to_order_items( $item, $cart_item_key, $values, $order ) {
- if ( empty( $values['booking-student'] ) ) {
- return;
- }
- $item->add_meta_data( __( 'booking-student', 'bsc-translation' ), $values['booking-student'] );
- }
- add_action( 'woocommerce_checkout_create_order_line_item', 'bsc_add_student_date_to_order_items', 10, 4 );
- /*
- * OUTPUT STUDENT NAME INSTEADOF ID IN ITEM DETAILS
- */
- function filter_woocommerce_order_item_display_meta_value( $meta_value ) {
- // make filter magic happen here...
- if ( get_post_status ( $meta_value ) ) {
- //return 'test';
- $student = get_post($meta_value);
- if($student->post_type == 'students'){
- $meta_value = $student->post_title;
- return $meta_value;
- } else {
- return $meta_value;
- }
- } else {
- return $meta_value;
- }
- };
- // add the filter
- add_filter( 'woocommerce_order_item_display_meta_value', 'filter_woocommerce_order_item_display_meta_value', 10, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement