securetrading-a2a-settings.php
1 year ago
securetrading-api-settings.php
1 year ago
securetrading-apple-pay-settings.php
1 year ago
securetrading-google-pay-settings.php
1 year ago
securetrading-iframe-settings.php
1 year ago
securetrading-paypal-settings.php
1 year ago
securetrading-transaction-columns.php
1 year ago
securetrading-transaction-columns.php
232 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Author: Trust Payments |
| 4 | * User: Rasamee |
| 5 | * Date: 04/12/2019 |
| 6 | * @since 1.0.0 |
| 7 | */ |
| 8 | if (!defined('ABSPATH')) { |
| 9 | exit; |
| 10 | } |
| 11 | class WC_SecureTrading_Transaction_Table { |
| 12 | |
| 13 | public function __construct() |
| 14 | { |
| 15 | add_filter( 'list_table_primary_column', array($this, 'list_table_primary_column'), 10, 2 ); |
| 16 | add_filter('manage_edit-' . SECURETRADING_TRANSACTION_TYPE . '_columns', array($this, 'st_transaction_add_columns')); |
| 17 | add_action('manage_' . SECURETRADING_TRANSACTION_TYPE . '_posts_custom_column', array($this, 'st_transaction_custom_columns'), 2); |
| 18 | add_action('manage_shop_order_posts_custom_column', array($this, 'tp_gateway_transaction_custom_columns'), 2); |
| 19 | // add_filter( 'manage_edit-' . SECURETRADING_TRANSACTION_TYPE . '_sortable_columns', array($this, 'define_sortable_columns')); |
| 20 | // add_filter('post_row_actions', array($this, 'handle_row_actions'), 10, 2); |
| 21 | add_filter( 'bulk_actions-edit-' . SECURETRADING_TRANSACTION_TYPE, array( $this, 'define_bulk_actions' ) ); |
| 22 | add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 ); |
| 23 | add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 ); |
| 24 | add_action('restrict_manage_posts', array($this, 'custom_filter_transaction')); |
| 25 | add_filter('parse_query', array($this, 'custom_query_transaction')); |
| 26 | add_filter('post_row_actions', array($this, 'remove_view_row_action'), 10, 2); |
| 27 | } |
| 28 | public function list_table_primary_column($default, $screen_id ) |
| 29 | { |
| 30 | if ('edit-'.SECURETRADING_TRANSACTION_TYPE === $screen_id) { |
| 31 | return 'order_id'; |
| 32 | } |
| 33 | return $default; |
| 34 | } |
| 35 | public function st_transaction_add_columns($columns) |
| 36 | { |
| 37 | // all of your columns will be added before the actions column on the Mange Transaction page |
| 38 | $new_columns = array(); |
| 39 | $new_columns["cb"] = $columns['cb']; |
| 40 | $new_columns["order_id"] = __('Order Id', SECURETRADING_TEXT_DOMAIN); |
| 41 | $new_columns["transaction_title"] = __('Transaction Id', SECURETRADING_TEXT_DOMAIN); |
| 42 | // $new_columns["transaction_type"] = __('Transaction Type', SECURETRADING_TEXT_DOMAIN); |
| 43 | $new_columns["transaction_parent_id"] = __('Transaction Parent Id', SECURETRADING_TEXT_DOMAIN); |
| 44 | $new_columns["transaction_status"] = __('Status', SECURETRADING_TEXT_DOMAIN); |
| 45 | $new_columns["customer_email"] = __('Customer Email', SECURETRADING_TEXT_DOMAIN); |
| 46 | $new_columns ['date'] = $columns['date']; |
| 47 | |
| 48 | return $new_columns; |
| 49 | } |
| 50 | public function st_transaction_custom_columns($column) |
| 51 | { |
| 52 | global $post, $woocommerce; |
| 53 | switch ($column) { |
| 54 | case "cb" : |
| 55 | $id = get_post_meta($post->ID, 'id', true); |
| 56 | echo '<span>' . esc_html($id) . '</div>'; |
| 57 | break; |
| 58 | case "transaction_title" : |
| 59 | // echo '<span>' . esc_html(get_post_meta($post->ID, 'title', true)) . '</span></div>'; |
| 60 | echo '<strong><a class="row-title" href="'.get_admin_url().'post.php?post='.$post->ID.'&action=edit">' . esc_html( get_the_title() ) . '</a></strong></div>'; |
| 61 | break; |
| 62 | // case "transaction_type" : |
| 63 | // echo '<span>' . esc_html(get_post_meta($post->ID, 'transaction_type', true)) . '</span></div>'; |
| 64 | // break; |
| 65 | case "transaction_parent_id" : |
| 66 | $transaction_parent_id = get_post_meta($post->ID, 'transaction_parent_id', true); |
| 67 | echo '<span>' . esc_html($transaction_parent_id) . '</span></div>'; |
| 68 | break; |
| 69 | case "transaction_status" : |
| 70 | $helper = new WC_SecureTrading_Helper(); |
| 71 | $values = $helper->settle_status(); |
| 72 | $status = get_post_meta($post->ID, 'transaction_status', true); |
| 73 | if($status !== "") |
| 74 | echo '<span>' . esc_html($values[$status]) . '</span></div>'; |
| 75 | break; |
| 76 | case "order_id" : |
| 77 | echo '<span>' . esc_html(get_post_meta($post->ID, 'order_id', true)) . '</span></div>'; |
| 78 | break; |
| 79 | case "customer_email" : |
| 80 | echo '<span>' . esc_html(get_post_meta($post->ID, 'customer_email', true)) . '</span></div>'; |
| 81 | break; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Modify Grid columns. |
| 87 | * |
| 88 | * @param mixed $column Grid columns. |
| 89 | * |
| 90 | * @return mixed |
| 91 | */ |
| 92 | public function tp_gateway_transaction_custom_columns($column) { |
| 93 | $post_ID = get_the_ID(); |
| 94 | $_tp_transaction_data = json_decode(get_post_meta( $post_ID, '_tp_transaction_data', 'true' )); |
| 95 | switch ($column) { |
| 96 | case "order_id" : |
| 97 | echo get_the_ID(); |
| 98 | break; |
| 99 | case "transaction_title" : |
| 100 | $transactionreference = $_tp_transaction_data->transactionreference; |
| 101 | echo ( isset($transactionreference) && !empty($transactionreference) ) ? '<strong><a class="row-title" href="'.get_admin_url().'index.php?page=st-transaction-detail&order_id='.$post_ID.'">'.esc_html($transactionreference).'</a></strong>' : ''; |
| 102 | break; |
| 103 | case "transaction_parent_id" : |
| 104 | $parenttransactionreference = $_tp_transaction_data->parenttransactionreference; |
| 105 | echo ( isset($parenttransactionreference) && !empty($parenttransactionreference) ) ? '<span>' . esc_html($parenttransactionreference) . '</span>' : ''; |
| 106 | break; |
| 107 | case "transaction_status" : |
| 108 | $helper = new WC_SecureTrading_Helper(); |
| 109 | $values = $helper->settle_status(); |
| 110 | $status = $_tp_transaction_data->settlestatus; |
| 111 | echo '<span>' . esc_html($values[$status]) . '</span>'; |
| 112 | break; |
| 113 | case "customer_email" : |
| 114 | $_billing_email = get_post_meta( $post_ID, '_billing_email', true); |
| 115 | echo ( isset($_billing_email) && !empty($_billing_email) ) ? '<span>' . esc_html($_billing_email) . '</span>' : ''; |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | public function define_sortable_columns($columns) |
| 121 | { |
| 122 | return array( |
| 123 | 'order_id', |
| 124 | 'transaction_id' |
| 125 | ); |
| 126 | } |
| 127 | public function handle_row_actions($actions, $object) |
| 128 | { |
| 129 | if ($object->post_type == SECURETRADING_TRANSACTION_TYPE) { |
| 130 | $actions = []; |
| 131 | $id = $object->ID; |
| 132 | $action = '&action=edit'; |
| 133 | $post_type_object = get_post_type_object( $object->post_type ); |
| 134 | if ( ! $post_type_object ) { |
| 135 | return; |
| 136 | } |
| 137 | if ( $post_type_object->_edit_link ) { |
| 138 | $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $id ) ); |
| 139 | } else { |
| 140 | $link = ''; |
| 141 | } |
| 142 | $actions['view'] = sprintf( |
| 143 | '<a href="%s" aria-label="%s">%s</a>', |
| 144 | $link, |
| 145 | /* translators: %s: Post title. */ |
| 146 | esc_attr( sprintf( __( 'View “%s”' ), $id ) ), |
| 147 | __( 'View' ) |
| 148 | ); |
| 149 | } |
| 150 | return $actions; |
| 151 | } |
| 152 | public function define_bulk_actions($actions) |
| 153 | { |
| 154 | $actions = array(); |
| 155 | return $actions; |
| 156 | } |
| 157 | /** |
| 158 | * Remove bloat. |
| 159 | */ |
| 160 | public function remove_meta_boxes() { |
| 161 | remove_meta_box( 'commentsdiv', SECURETRADING_TRANSACTION_TYPE, 'normal' ); |
| 162 | remove_meta_box( 'woothemes-settings', SECURETRADING_TRANSACTION_TYPE, 'normal' ); |
| 163 | remove_meta_box( 'slugdiv', SECURETRADING_TRANSACTION_TYPE, 'normal' ); |
| 164 | remove_meta_box( 'submitdiv', SECURETRADING_TRANSACTION_TYPE, 'side' ); |
| 165 | remove_meta_box( 'postexcerpt', SECURETRADING_TRANSACTION_TYPE, 'normal' ); |
| 166 | remove_meta_box( 'commentstatusdiv', SECURETRADING_TRANSACTION_TYPE, 'side' ); |
| 167 | remove_meta_box( 'commentstatusdiv', SECURETRADING_TRANSACTION_TYPE, 'normal' ); |
| 168 | } |
| 169 | public function add_meta_boxes() |
| 170 | { |
| 171 | $screen = get_current_screen(); |
| 172 | $screen_id = $screen ? $screen->id : ''; |
| 173 | add_meta_box( 'st-transaction-detail-data', sprintf( __( '%s data', SECURETRADING_TEXT_DOMAIN ), 'ST Transaction' ), array($this, 'st_transaction_detail_data'), SECURETRADING_TRANSACTION_TYPE , 'normal', 'high' ); |
| 174 | } |
| 175 | public function st_transaction_detail_data($post) |
| 176 | { |
| 177 | global $post; |
| 178 | $template_path = SECURETRADING_PATH . 'templates/'; |
| 179 | include $template_path. 'transaction-detail.php'; |
| 180 | } |
| 181 | public function custom_filter_transaction() |
| 182 | { |
| 183 | if (isset($_GET['post_type']) && $_GET['post_type'] == SECURETRADING_TRANSACTION_TYPE) { |
| 184 | $helper = new WC_SecureTrading_Helper(); |
| 185 | $values = $helper->settle_status(); |
| 186 | ?> |
| 187 | <select name="admin_filter"> |
| 188 | <option value=""> |
| 189 | <?php _e('All Status ', SECURETRADING_TEXT_DOMAIN); ?> |
| 190 | </option> |
| 191 | <?php |
| 192 | $current_v = isset($_GET['admin_filter']) ? $_GET['admin_filter'] : ''; |
| 193 | foreach ($values as $value => $label) { |
| 194 | printf( |
| 195 | '<option value="%s"%s>%s</option>', $value, $value == $current_v ? ' selected="selected"' : '', $label |
| 196 | ); |
| 197 | } |
| 198 | ?> |
| 199 | </select> |
| 200 | <?php |
| 201 | } |
| 202 | } |
| 203 | public function custom_query_transaction($query) |
| 204 | { |
| 205 | global $pagenow; |
| 206 | $type = 'post'; |
| 207 | if (isset($_GET['post_type'])) { |
| 208 | $type = $_GET['post_type']; |
| 209 | } |
| 210 | if (SECURETRADING_TRANSACTION_TYPE == $type && is_admin() && $pagenow == 'edit.php' && isset($_GET['admin_filter']) && $_GET['admin_filter'] != '') { |
| 211 | $query->query_vars['meta_key'] = 'transaction_status'; |
| 212 | //$user_id = $_GET['admin_filter'] |
| 213 | //user_can( $user_id, 'manage_options' ) |
| 214 | $query->query_vars['meta_value'] = sanitize_text_field($_GET['admin_filter']); |
| 215 | } |
| 216 | } |
| 217 | public function remove_view_row_action($actions, $post) |
| 218 | { |
| 219 | if ( ( SECURETRADING_TRANSACTION_TYPE == $post->post_type ) || ( 'shop_order' == $post->post_type ) ) { |
| 220 | unset( $actions['view'] ); |
| 221 | unset( $actions['trash'] ); |
| 222 | unset( $actions['inline hide-if-no-js'] ); |
| 223 | } |
| 224 | |
| 225 | if ( ( 'shop_order' == $post->post_type ) ) { |
| 226 | $actions['edit'] = '<a href="'.get_admin_url().'index.php?page=st-transaction-detail&order_id='.$post->ID.'">'.__( 'Edit', SECURETRADING_TEXT_DOMAIN ).'</a>'; |
| 227 | } |
| 228 | |
| 229 | return $actions; |
| 230 | } |
| 231 | } |
| 232 | return new WC_SecureTrading_Transaction_Table(); |