/**
 * Define our custom columns shown in admin.
 * @param  string $column
 *
 */
function rf_custom_columns($column)
{
    global $post, $woocommerce;
    switch ($column) {
        case "coupon_type":
            echo esc_html(wc_get_coupon_type(get_post_meta($post->ID, 'rf_coupon_type', true)));
            break;
        case "coupon_amount":
            echo esc_html(get_post_meta($post->ID, 'rf_coupon_amount', true));
            break;
        case "description":
            echo esc_html(get_post_meta($post->ID, 'rf_description', true));
            break;
        case "product_id":
            echo esc_html(get_post_meta($post->ID, 'rf_product_id', true));
            break;
        case "usage_limit":
            echo esc_html(get_post_meta($post->ID, 'rf_usage', true) . ' / ' . get_post_meta($post->ID, 'rf_limit', true));
            break;
        case "expiry_date":
            echo esc_html(get_post_meta($post->ID, 'rf_expiry_date', true));
            break;
        case "type":
            echo esc_html(get_post_meta($post->ID, 'rf_type', true) == 1 ? 'Refered by email' : 'Refered by share link');
            break;
    }
}
 /**
  * Output custom columns for coupons
  *
  * @param string $column
  */
 public function render_shop_coupon_columns($column)
 {
     global $post, $woocommerce;
     switch ($column) {
         case 'coupon_code':
             $edit_link = get_edit_post_link($post->ID);
             $title = _draft_or_post_title();
             echo '<strong><a href="' . esc_attr($edit_link) . '" class="row-title">' . esc_html($title) . '</a></strong>';
             _post_states($post);
             $this->_render_shop_coupon_row_actions($post, $title);
             break;
         case 'type':
             echo esc_html(wc_get_coupon_type(get_post_meta($post->ID, 'discount_type', true)));
             break;
         case 'amount':
             echo esc_html(get_post_meta($post->ID, 'coupon_amount', true));
             break;
         case 'products':
             $product_ids = get_post_meta($post->ID, 'product_ids', true);
             $product_ids = $product_ids ? array_map('absint', explode(',', $product_ids)) : array();
             if (sizeof($product_ids) > 0) {
                 echo esc_html(implode(', ', $product_ids));
             } else {
                 echo '&ndash;';
             }
             break;
         case 'usage_limit':
             $usage_limit = get_post_meta($post->ID, 'usage_limit', true);
             if ($usage_limit) {
                 echo esc_html($usage_limit);
             } else {
                 echo '&ndash;';
             }
             break;
         case 'usage':
             $usage_count = absint(get_post_meta($post->ID, 'usage_count', true));
             $usage_limit = esc_html(get_post_meta($post->ID, 'usage_limit', true));
             $usage_url = sprintf('<a href="%s">%s</a>', admin_url(sprintf('edit.php?s=%s&post_status=all&post_type=shop_order', esc_html($post->post_title))), $usage_count);
             if ($usage_limit) {
                 printf(__('%s / %s', 'woocommerce'), $usage_url, $usage_limit);
             } else {
                 printf(__('%s / &infin;', 'woocommerce'), $usage_url);
             }
             break;
         case 'expiry_date':
             $expiry_date = get_post_meta($post->ID, 'expiry_date', true);
             if ($expiry_date) {
                 echo esc_html(date_i18n('F j, Y', strtotime($expiry_date)));
             } else {
                 echo '&ndash;';
             }
             break;
         case 'description':
             echo wp_kses_post($post->post_excerpt);
             break;
     }
 }
 /**
  * Output custom columns for coupons
  * @param  string $column
  */
 public function render_shop_coupon_columns($column)
 {
     global $post, $woocommerce;
     switch ($column) {
         case 'coupon_code':
             $edit_link = get_edit_post_link($post->ID);
             $title = _draft_or_post_title();
             $post_type_object = get_post_type_object($post->post_type);
             echo '<a href="' . esc_attr($edit_link) . '">' . esc_html($title) . '</a>';
             _post_states($post);
             // Get actions
             $actions = array();
             if (current_user_can($post_type_object->cap->edit_post, $post->ID)) {
                 $actions['edit'] = '<a href="' . admin_url(sprintf($post_type_object->_edit_link . '&amp;action=edit', $post->ID)) . '">' . __('Edit', 'woocommerce') . '</a>';
             }
             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', 'woocommerce')) . "' href='" . wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&amp;action=untrash', $post->ID)), 'untrash-post_' . $post->ID) . "'>" . __('Restore', 'woocommerce') . "</a>";
                 } elseif (EMPTY_TRASH_DAYS) {
                     $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this item to the Trash', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash', 'woocommerce') . "</a>";
                 }
                 if ('trash' == $post->post_status || !EMPTY_TRASH_DAYS) {
                     $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this item permanently', 'woocommerce')) . "' href='" . get_delete_post_link($post->ID, '', true) . "'>" . __('Delete Permanently', 'woocommerce') . "</a>";
                 }
             }
             $actions = apply_filters('post_row_actions', $actions, $post);
             echo '<div class="row-actions">';
             $i = 0;
             $action_count = sizeof($actions);
             foreach ($actions as $action => $link) {
                 ++$i;
                 $i == $action_count ? $sep = '' : ($sep = ' | ');
                 echo "<span class='{$action}'>{$link}{$sep}</span>";
             }
             echo '</div>';
             break;
         case 'type':
             echo esc_html(wc_get_coupon_type(get_post_meta($post->ID, 'discount_type', true)));
             break;
         case 'amount':
             echo esc_html(get_post_meta($post->ID, 'coupon_amount', true));
             break;
         case 'products':
             $product_ids = get_post_meta($post->ID, 'product_ids', true);
             $product_ids = $product_ids ? array_map('absint', explode(',', $product_ids)) : array();
             if (sizeof($product_ids) > 0) {
                 echo esc_html(implode(', ', $product_ids));
             } else {
                 echo '&ndash;';
             }
             break;
         case 'usage_limit':
             $usage_limit = get_post_meta($post->ID, 'usage_limit', true);
             if ($usage_limit) {
                 echo esc_html($usage_limit);
             } else {
                 echo '&ndash;';
             }
             break;
         case 'usage':
             $usage_count = absint(get_post_meta($post->ID, 'usage_count', true));
             $usage_limit = esc_html(get_post_meta($post->ID, 'usage_limit', true));
             $usage_url = sprintf('<a href="%s">%s</a>', admin_url(sprintf('edit.php?s=%s&post_status=all&post_type=shop_order', esc_html($post->post_title))), $usage_count);
             if ($usage_limit) {
                 printf(__('%s / %s', 'woocommerce'), $usage_url, $usage_limit);
             } else {
                 printf(__('%s / &infin;', 'woocommerce'), $usage_url);
             }
             break;
         case 'expiry_date':
             $expiry_date = get_post_meta($post->ID, 'expiry_date', true);
             if ($expiry_date) {
                 echo esc_html(date_i18n('F j, Y', strtotime($expiry_date)));
             } else {
                 echo '&ndash;';
             }
             break;
         case 'description':
             echo wp_kses_post($post->post_excerpt);
             break;
     }
 }
Exemple #4
0
 /**
  * Test wc_get_coupon_type().
  *
  * @since 2.2
  */
 public function test_wc_get_coupon_type()
 {
     $this->assertEquals('Cart Discount', wc_get_coupon_type('fixed_cart'));
     $this->assertEmpty(wc_get_coupon_type('bogus_type'));
 }
Exemple #5
0
 /**
  * @deprecated 2.1.0
  * @param string $type
  * @return string
  */
 public function get_coupon_discount_type($type = '')
 {
     _deprecated_function('Woocommerce->get_coupon_discount_type', '2.1', 'wc_get_coupon_type');
     return wc_get_coupon_type($type);
 }
 /**
  * Backwards compatible method of getting a discount type
  *
  * @param string $type
  * @return string
  */
 public static function get_discount_type($type)
 {
     return function_exists('wc_get_coupon_type') ? wc_get_coupon_type($type) : WC()->get_coupon_discount_type($type);
 }
 public static function get_discount_type($type)
 {
     global $woocommerce;
     return function_exists('wc_get_coupon_type') ? wc_get_coupon_type($type) : $woocommerce->get_coupon_discount_type($type);
 }