1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
<?php
include_once( 'prdd-common.php' );
if ( !class_exists( 'prdd_admin_deliveries' ) ) {
class prdd_admin_deliveries {
public function __construct() {
add_action( 'woocommerce_admin_order_item_headers', array( $this, 'prdd_link_header' ) );
add_action( 'woocommerce_admin_order_item_values', array( $this, 'prdd_link' ), 10, 3 );
}
function prdd_link_header() {
?><th> </th><?php
}
function prdd_link( $_product, $item, $item_id ) {
global $wpdb;
if ( isset( $_product ) && !empty( $_product ) ) {
$product_id = $_product->get_id();
$product_type = $_product->get_type();
if( $product_type == 'variation' ) {
if( version_compare( get_option( 'woocommerce_version ' ), '3.0.0', ">=" ) ) {
$product_id = $_product->get_parent_id();
} else {
$product_id = $_product->parent_id;
}
}
$prdd_settings = get_post_meta( $product_id, 'woocommerce_prdd_settings', true );
$query_order_id = "SELECT order_id FROM `". $wpdb->prefix."woocommerce_order_items`
WHERE order_item_id = %d";
$get_order_id = $wpdb->get_results( $wpdb->prepare( $query_order_id, $item_id ) );
$order_id = 0;
if ( isset( $get_order_id ) && is_array( $get_order_id ) && count( $get_order_id ) > 0 ) {
$order_id = $get_order_id[0]->order_id;
}
$order = new WC_Order ( $order_id );
if ( isset( $prdd_settings[ 'prdd_enable_date' ] ) && $prdd_settings[ 'prdd_enable_date' ] == 'on' ) {
echo "<td>";
$prdd_details = array(
'date' => '',
'hidden_date' => '',
'price' => '' );
foreach ( $item->get_meta_data() as $meta_index => $meta ) {
if ( $meta->key === get_option( 'delivery_item-meta-date' ) ) {
$prdd_details[ 'date' ] = $meta->value;
} elseif ( $meta->key === '_prdd_date' ) {
$hidden_date = explode( '-', $meta->value );
$prdd_details[ 'hidden_date' ] = $hidden_date[2] . '-' . $hidden_date[1] . '-' . $hidden_date[0];
} elseif ( $meta->key === get_option( 'delivery_item-meta-time' ) ){
$prdd_details[ 'time_slot' ] = $meta->value;
}
}
if( $prdd_details[ 'date' ] != '' ) {
printf( '<a href="javascript:void(0)" onclick="prdd_edit_delivery_class.prdd_edit_deliveries(%d,%s)">%s</a>', $item->get_product_id( 'view' ), $item_id, __( 'Edit Delivery', 'woocommerce-prdd' ) );
do_action( 'prdd_woo_order_item_values', $_product, $item, $item_id );
$localized_array = array(
'prdd_delivery_params' => $prdd_details,
'prdd_cart_item' => $item,
'prdd_cart_item_key' => $item_id,
'prdd_order_id' => $order->get_id(),
'prdd_page_type' => 'view-order'
);
prdd_edit_deliveries_class::prdd_load_template(
$prdd_details,
$item->get_product(),
$item->get_product_id( 'view' ),
$localized_array,
$item_id,
$item->get_variation_id( 'view' ) );
}
echo "</td>";
} else {
echo '<td></td>';
}
} else {
echo '<td></td>';
}
}
}
}
$prdd_admin_deliveries = new prdd_admin_deliveries();
?>