/** * Adds variation attributes to the product name in vouchers. * * @param string $name the product name for the voucher * @param \WC_Voucher $voucher voucher instance * @return string updated product name */ function sv_wc_pdf_voucher_product_name($name, $voucher) { $item_data = $voucher->get_item(); // use the variation name instead of product name if available if (isset($item_data['variation_id']) && ($variation = wc_get_product($item_data['variation_id']))) { return $variation->get_title() . ' - ' . implode(', ', $variation->get_variation_attributes()); } return $name; }
/** * Admin voucher download, which will work regardless of the download * permissions/current user, and will not count towards the download * count * * @since 2.1 */ public function download_voucher() { if (isset($_GET['post']) && isset($_GET['product_id']) && isset($_GET['item_id']) && isset($_GET['action']) && 'download' == $_GET['action'] && $_GET['voucher_id']) { $order = wc_get_order($_GET['post']); $items = $order->get_items(); $voucher = new WC_Voucher($_GET['voucher_id'], $_GET['post'], $items[$_GET['item_id']], $_GET['item_id']); $download_handler = new WC_Download_Handler(); $file_path = $voucher->get_voucher_full_filename(WC_PDF_Product_Vouchers::get_uploads_path()); if ('redirect' === get_option('woocommerce_file_download_method')) { $file_path = $voucher->convert_path_to_url($file_path); } $download_handler->download($file_path, $_GET['product_id']); exit; } }
/** * 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; } }
/** * Voucher data meta box * * @since 1.2 */ public function data_meta_box($post) { wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); $voucher = new WC_Voucher($post->ID); $default_fonts = array('Helvetica' => 'Helvetica', 'Courier' => 'Courier', 'Times' => 'Times', 'Roboto' => 'Roboto', 'Merriweather' => 'Merriweather'); $available_fonts = array_merge(array('' => ''), $default_fonts); // since this little snippet of css applies only to the voucher post page, it's easier to have inline here ?> <style type="text/css"> #misc-publishing-actions { display:none; } #edit-slug-box { display:none } .imgareaselect-outer { cursor: crosshair; } </style> <div id="voucher_options" class="panel woocommerce_options_panel"> <div class="options_group"> <?php // Text color echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher', 'label' => __('Default Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $default_fonts, 'font_size_default' => 11)); woocommerce_wp_text_input(array('id' => '_voucher_font_color', 'label' => __('Default Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'default' => '#000000', 'description' => __('The default text color for the voucher.', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'class' => 'colorpick')); woocommerce_wp_select(array('id' => '_voucher_text_align', 'label' => __('Default Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The default text alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => array('L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Product name position echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'product_name_pos', 'label' => __('Product Name Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('product_name')), 'description' => __('Optional position of the product name', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_product_name_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('product_name')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_product_name', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_product_name_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_name']['font']['color']) ? $voucher->voucher_fields['product_name']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_select(array('id' => '_product_name_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_name']['text_align']) ? $voucher->voucher_fields['product_name']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // SKU position echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'product_sku_pos', 'label' => __('SKU Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('product_sku')), 'description' => __('Optional position of the product SKU', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_product_sku_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('product_sku')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_product_sku', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_product_sku_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_sku']['font']['color']) ? $voucher->voucher_fields['product_sku']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_select(array('id' => '_product_sku_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['product_sku']['text_align']) ? $voucher->voucher_fields['product_sku']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Voucher number position echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'voucher_number_pos', 'label' => __('Voucher Number Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('voucher_number')), 'description' => __('Optional position of the voucher number', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_voucher_number_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('voucher_number')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher_number', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_voucher_number_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_number']['font']['color']) ? $voucher->voucher_fields['voucher_number']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_select(array('id' => '_voucher_number_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_number']['text_align']) ? $voucher->voucher_fields['voucher_number']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Product price echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'voucher_product_price_pos', 'label' => __('Product Price Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('voucher_product_price')), 'description' => __('Optional position of the product price', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_voucher_product_price_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('voucher_product_price')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_voucher_product_price', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_voucher_product_price_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_product_price']['font']['color']) ? $voucher->voucher_fields['voucher_product_price']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_select(array('id' => '_voucher_product_price_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['voucher_product_price']['text_align']) ? $voucher->voucher_fields['voucher_product_price']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Days to expiration echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'expiration_date_pos', 'label' => __('Expiration Date Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('expiration_date')), 'description' => __('Optional position of the voucher expiration date', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_expiration_date_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('expiration_date')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_expiration_date', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_expiration_date_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['expiration_date']['font']['color']) ? $voucher->voucher_fields['expiration_date']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_text_input(array('id' => '_days_to_expiry', 'label' => __('Days to Expiration', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Optional number of days after purchase until the voucher expires', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('days', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_expiry())); woocommerce_wp_select(array('id' => '_expiration_date_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['expiration_date']['text_align']) ? $voucher->voucher_fields['expiration_date']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Voucher recipient position echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'recipient_name_pos', 'label' => __('Recipient Name Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('recipient_name')), 'description' => __('Optional position of the name of the receiving party.', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_recipient_name_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('recipient_name')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_recipient_name', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_recipient_name_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['font']['color']) ? $voucher->voucher_fields['recipient_name']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_text_input(array('id' => '_recipient_name_max_length', 'label' => __('Max Length', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The maximum length of the recipient name field', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('No Limit', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_user_input_field_max_length('recipient_name'))); woocommerce_wp_text_input(array('id' => '_recipient_name_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['label']) ? $voucher->voucher_fields['recipient_name']['label'] : 'Recipient Name')); woocommerce_wp_checkbox(array('id' => '_recipient_name_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the Recipient Name option without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('recipient_name') ? 'yes' : 'no')); woocommerce_wp_checkbox(array('id' => '_recipient_name_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('recipient_name') ? 'yes' : 'no')); woocommerce_wp_select(array('id' => '_recipient_name_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_name']['text_align']) ? $voucher->voucher_fields['recipient_name']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Voucher recipient email option echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'recipient_email_pos', 'label' => __('Recipient Email Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('recipient_email_pos')), 'description' => __('Optional position of the user-supplied recipient email', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_recipient_email_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('recipient_email_pos')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_recipient_email', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_recipient_email_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_email']['font']['color']) ? $voucher->voucher_fields['recipient_email']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_text_input(array('id' => '_recipient_email_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['recipient_email']['label']) ? $voucher->voucher_fields['recipient_email']['label'] : 'Recipient Email')); woocommerce_wp_checkbox(array('id' => '_recipient_email_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the Recipient Email option without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('recipient_email') ? 'yes' : 'no')); woocommerce_wp_checkbox(array('id' => '_recipient_email_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('recipient_email') ? 'yes' : 'no')); woocommerce_wp_select(array('id' => '_message_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['text_align']) ? $voucher->voucher_fields['message']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; // Voucher message position echo '<div class="options_group">'; WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_position_picker(array('id' => 'message_pos', 'label' => __('Message Position', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => implode(',', $voucher->get_field_position('message')), 'description' => __('Optional position of the user-supplied message', WC_PDF_Product_Vouchers::TEXT_DOMAIN))); woocommerce_wp_hidden_input(array('id' => '_message_pos', 'class' => 'field_pos', 'value' => implode(',', $voucher->get_field_position('message')))); WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_font_select(array('id' => '_message', 'label' => __('Font', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'options' => $available_fonts)); woocommerce_wp_text_input(array('id' => '_message_font_color', 'label' => __('Font color', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['font']['color']) ? $voucher->voucher_fields['message']['font']['color'] : '', 'class' => 'colorpick')); woocommerce_wp_text_input(array('id' => '_message_label', 'label' => __('Label', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The field label to show on the frontend/emails', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['label']) ? $voucher->voucher_fields['message']['label'] : 'Message to Recipient')); woocommerce_wp_text_input(array('id' => '_message_max_length', 'label' => __('Max Length', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('The maximum length of the message field', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'placeholder' => __('No Limit', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->get_user_input_field_max_length('message'))); woocommerce_wp_checkbox(array('id' => '_message_is_enabled', 'label' => __('Enabled', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Display this field on the product page (useful if you want the customer to be able to add a personalized message that will be included in the recipient email without printing it to the voucher)', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_enabled('message') ? 'yes' : 'no')); woocommerce_wp_checkbox(array('id' => '_message_is_required', 'label' => __('Required', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'description' => __('Make this field required in order to add a voucher product to the cart', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => $voucher->user_input_field_is_required('message') ? 'yes' : 'no')); woocommerce_wp_select(array('id' => '_message_text_align', 'label' => __('Text Alignment', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'value' => isset($voucher->voucher_fields['message']['text_align']) ? $voucher->voucher_fields['message']['text_align'] : '', 'options' => array('' => '', 'L' => _x('Left', 'left justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'C' => _x('Center', 'center justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN), 'R' => _x('Right', 'right justified', WC_PDF_Product_Vouchers::TEXT_DOMAIN)))); echo '</div>'; ?> </div> </div> <?php WC_PDF_Product_Vouchers_Admin_Vouchers::wc_vouchers_wp_color_picker_js(); }
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 */ /** * The template for displaying voucher previews. This isn't a page template in * the regular sense, instead it streams the voucher PDF to the client. The * voucher is created with placeholder field data. The voucher primary image * at least must be set. * * @since 1.0 */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly global $post; $voucher = new WC_Voucher($post->ID); $lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu risus et sapien imperdiet ornare. Mauris eget libero at lorem tempor faucibus. Donec convallis auctor nibh, at laoreet ante iaculis eget. Sed scelerisque, dolor non porttitor ultrices, nisi risus blandit tortor, vel commodo est turpis eu lorem. Aliquam at orci lectus. Aenean tincidunt neque id nunc volutpat tincidunt. Integer mattis, lectus non aliquet dictum, nisl purus facilisis justo, quis malesuada magna orci venenatis diam. Nulla sem erat, pretium ultricies vestibulum posuere, semper eget elit. Maecenas lobortis bibendum odio, nec aliquet dolor dignissim ac. Fusce dapibus pharetra mauris sed placerat. Aliquam vitae est dolor. Vestibulum fermentum libero felis, non rhoncus orci. Maecenas fringilla, felis eget sodales ultricies, quam tortor consectetur est, vitae rhoncus lacus est cursus neque."; if ($voucher->get_image_id()) { // if there is at least a voucher image set, set default values for all positioned fields // ie, the field 'product_name' will have the value 'Product Name' set foreach ($voucher->voucher_fields as $field_name => $field) { if (isset($field['position']) && $field['position']) { $value_set = false; $value = ucwords(str_replace('_', ' ', $field_name)); if (isset($field['max_length']) && $field['max_length']) { while (strlen($value) < $field['max_length']) { $value .= " " . substr($lorem_ipsum, 0, $field['max_length'] - strlen($value) + 1); } } if (isset($field['days_to_expiry']) && $field['days_to_expiry']) { // if there's an expiration date set provie some dummy data
/** * Dispatch the email(s) * * @since 1.2 * @param int $order_id order identifier */ public function trigger($order_id) { // nothingtodohere if (!$order_id || !$this->is_enabled()) { return; } // only dispatch the voucher recipient email once, unless we're being called from the Voucher Recipient email order action if (get_post_meta($order_id, '_wc_pdf_product_vouchers_voucher_recipient_email_sent', true) && !(isset($_POST['wc_order_action']) && 'send_email_wc_pdf_product_vouchers_voucher_recipient' == $_POST['wc_order_action'])) { return; } $order = wc_get_order($order_id); $this->find[] = '{billing_first_name}'; $this->replace[] = $order->billing_first_name; $this->find[] = '{billing_last_name}'; $this->replace[] = $order->billing_last_name; // foreach voucher item in this order, if it contains a recipient email, // add the voucher to those being sent to that recipient. // foreach voucher recipient, send an email with any and all vouchers $recipient_emails = array(); $order_items = $order->get_items(); if (count($order_items) > 0) { foreach ($order_items as $order_item_id => $item) { if ($item['product_id'] > 0 && isset($item['voucher_id']) && $item['voucher_id']) { $voucher = new WC_Voucher($item['voucher_id'], $order->id, $item, $order_item_id); if ($voucher->get_recipient_email() && $voucher->file_exists(wc_pdf_product_vouchers()->get_uploads_path())) { if (!isset($recipient_emails[$voucher->get_recipient_email()])) { $recipient_emails[$voucher->get_recipient_email()] = array('count' => 0, 'message' => '', 'recipient_name' => $voucher->get_recipient_name()); } $recipient_emails[$voucher->get_recipient_email()]['count']++; // message to the recipient? if ($voucher->get_message()) { if ('' === $recipient_emails[$voucher->get_recipient_email()]['message']) { $recipient_emails[$voucher->get_recipient_email()]['message'] = $voucher->get_message(); } elseif ($recipient_emails[$voucher->get_recipient_email()]['message'] != $voucher->get_message()) { // guard against the admitedly edge case of multiple vouchers with different messages // being sent to the same recipient, by just not displaying a message. Cause it would // probably look odd to have a bunch of different messages in the same email $recipient_emails[$voucher->get_recipient_email()]['message'] = null; } } } } } } foreach ($recipient_emails as $recipient_email => $data) { $this->object = array('order' => $order, 'recipient_email' => $recipient_email, 'voucher_count' => $data['count']); $this->message = $data['message']; $this->recipient_name = $data['recipient_name']; $this->recipient = $recipient_email; $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); } // record the fact that the vouchers have been sent update_post_meta($order_id, '_wc_pdf_product_vouchers_voucher_recipient_email_sent', true); }
/** * Make sure the user-input voucher fields are persisted to the database in the * order item meta. This is called during the checkout process for each * cart item added to the order. Requires WooCommerce 2.0+ * * @since 1.2 * @param int $item_id item identifier * @param array $values array of data representing a cart item */ public function add_order_item_meta($item_id, $values) { // is this a voucher product? if (isset($values['voucher_id'])) { $voucher = new WC_Voucher($values['voucher_id']); wc_add_order_item_meta($item_id, '_voucher_image_id', $values['voucher_image_id']); wc_add_order_item_meta($item_id, '_voucher_id', $values['voucher_id']); wc_add_order_item_meta($item_id, '_voucher_redeem', array_pad(array(), $values['quantity'], null)); wc_add_order_item_meta($item_id, '_voucher_number', WC_PDF_Product_Vouchers_Voucher::generate_voucher_number()); // set any user-input fields to the order item meta data (which can be displayed on the frontend) // ie recipient_name, message if (isset($values['voucher_item_meta_data'])) { foreach ($values['voucher_item_meta_data'] as $name => $value) { if ($voucher->is_user_input_type_field($name) && $value) { // make sure any max length rules are imposed if ($voucher->get_user_input_field_max_length($name)) { $value = substr($value, 0, $voucher->get_user_input_field_max_length($name)); } wc_add_order_item_meta($item_id, __($voucher->get_field_label($name), WC_PDF_Product_Vouchers::TEXT_DOMAIN), $value); } } } } }
/** * 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 }
/** * Add the voucher number to the order items table of admin * * @since 2.3.0 * @param int $item_id The item ID * @param array $item The order item * @param WC_Order $order The order object */ public function add_voucher_number_to_email_order_item_meta($item_id, $item, $order) { if ($item['product_id'] > 0 && isset($item['voucher_id']) && $item['voucher_id']) { $voucher = new WC_Voucher($item['voucher_id'], $order->id, $item); echo '<br/><small>' . __('Voucher Number: ', WC_PDF_Product_Vouchers::TEXT_DOMAIN) . $voucher->get_voucher_number() . '</small>'; } }