/** * Custom Column values for Vouchers page * * @since 1.2 * @param string $column column identifier */ public function custom_voucher_columns($column) { global $post; $voucher = new WC_Voucher($post->ID); switch ($column) { case 'thumb': $edit_link = get_edit_post_link($post->ID); echo '<a href="' . $edit_link . '">' . $voucher->get_image() . '</a>'; break; case 'name': $edit_link = get_edit_post_link($post->ID); $title = _draft_or_post_title(); $post_type_object = get_post_type_object($post->post_type); $can_edit_post = current_user_can($post_type_object->cap->edit_post, $post->ID); echo '<strong><a class="row-title" href="' . $edit_link . '">' . $title . '</a>'; // display post states a little more selectively than _post_states( $post ); if ('draft' == $post->post_status) { echo " - <span class='post-state'>" . __('Draft', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . '</span>'; } echo '</strong>'; // Get actions $actions = array(); $actions['id'] = 'ID: ' . $post->ID; if (current_user_can($post_type_object->cap->delete_post, $post->ID)) { if ('trash' == $post->post_status) { $actions['untrash'] = "<a title='" . esc_attr(__('Restore this item from the Trash', WC_PDF_Product_Vouchers::TEXT_DOMAIN)) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $post->ID)), 'untrash-' . $post->post_type . '_' . $post->ID) . "'>" . __('Restore', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . "</a>"; } elseif (EMPTY_TRASH_DAYS) { $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash', WC_PDF_Product_Vouchers::TEXT_DOMAIN)) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . "</a>"; } if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently', WC_PDF_Product_Vouchers::TEXT_DOMAIN)) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . "</a>"; } } // TODO: add a duplicate voucher action? $actions = apply_filters('post_row_actions', $actions, $post); echo '<div class="row-actions">'; $i = 0; $action_count = count($actions); foreach ($actions as $action => $link) { $action_count - 1 == $i ? $sep = '' : ($sep = ' | '); echo '<span class="' . $action . '">' . $link . $sep . '</span>'; $i++; } echo '</div>'; break; case "days_to_expiry": echo $voucher->get_expiry(); break; } }
/** * Order vouchers meta box * * Displays the order vouchers meta box - for showing and modifying * individual vouchers attached to the order * * @since 1.2 */ public function vouchers_meta_box($post) { $order = wc_get_order($post->ID); $order_items = $order->get_items(); ?> <div class="woocommerce_order_vouchers_wrapper"> <table cellpadding="0" cellspacing="0" class="woocommerce_order_vouchers"> <thead> <tr> <th class="thumb" width="1%"><?php _e('Voucher', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="voucher_number"><?php _e('Number', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="sku"><?php _e('SKU', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="data"><?php _e('Data', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="expires"><?php _e('Expires', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="qty"><?php _e('Qty', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </th> <th class="redeem" style="white-space:nowrap;"><?php _e('Mark Redeemed', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> <a class="tips" data-tip="<?php _e('Mark the dates that any vouchers are redeemed. Marking all vouchers redeemed will complete the order.', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> " href="#">[?]</a></th> </tr> </thead> <tbody id="order_vouchers_list"> <?php if (count($order_items) > 0) { foreach ($order_items as $item_id => $item) { // only voucher items if (!isset($item['voucher_id'])) { continue; } $item['voucher_redeem'] = maybe_unserialize($item['voucher_redeem']); $voucher = new WC_Voucher($item['voucher_id'], $post->ID, $item, $item_id); if (isset($item['variation_id']) && $item['variation_id'] > 0) { $_product = wc_get_product($item['variation_id']); } else { $_product = wc_get_product($item['product_id']); } // get any user-supplied voucher data (this includes product variation data and user-entered fields like recipient or message) $voucher_data = array(); if (isset($_product->variation_data)) { $voucher_data = $_product->variation_data; } $voucher_data = array_merge($voucher_data, $voucher->get_user_input_data()); ?> <tr class="item" rel="<?php echo $item_id; ?> "> <td class="thumb"> <a href="<?php echo esc_url(admin_url('post.php?post=' . $voucher->id . '&action=edit')); ?> " class="tips" data-tip="<?php echo '<strong>' . __('Voucher ID:', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . '</strong> ' . $voucher->id; ?> "><?php echo $voucher->get_image(); ?> </a> <?php if ($voucher->file_exists(WC_PDF_Product_Vouchers::get_uploads_path())) { ?> <a href="<?php echo esc_url(add_query_arg(array('action' => 'download', 'product_id' => $item['product_id'], 'item_id' => $item_id, 'voucher_id' => $item['voucher_id']))); ?> "><?php esc_html_e('Download', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </a> <?php } ?> </td> <td class="voucher_number" width="1%"> <?php echo $voucher->get_voucher_number(); ?> </td> <td class="sku" width="1%"> <?php if ($_product->sku) { echo $_product->sku; } else { echo '-'; } ?> </td> <td class="data"> <?php echo $item['name']; ?> <?php if (!empty($voucher_data)) { echo '<br/>' . wc_get_formatted_variation($voucher_data, true); } ?> </td> <td class="expires" style="width:auto;"> <input type="text" name="voucher_expiration[<?php echo $item_id; ?> ]" id="voucher_expiration_<?php echo $item_id; ?> " maxlength="10" value="<?php echo $voucher->expiration_date ? date("Y-m-d", $voucher->expiration_date) : ''; ?> " class="date-picker-field" /> </td> <td class="qty" width="1%"> <?php echo $item['qty']; ?> </td> <td class="redeem" width="1%"> <?php foreach ($item['voucher_redeem'] as $i => $redeem) { ?> <input type="text" name="voucher_redeem[<?php echo $item_id; ?> ][<?php echo $i; ?> ]" id="voucher_redeem_<?php echo $item_id . '_' . $i; ?> " class="voucher_redeem date-picker-field" maxlength="10" style="width:85px;" value="<?php echo $redeem; ?> " class="date-picker-field" /> <?php } ?> </td> </tr> <?php } } ?> </tbody> </table> </div> <p class="buttons buttons-alt"> <button type="button" class="button redeem_all_vouchers"><?php _e('Redeem All ↑', WC_PDF_Product_Vouchers::TEXT_DOMAIN); ?> </button> </p> <div class="clear"></div> <?php }