| @@ -1,30 +1,41 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: MakeCommerce for WooCommerce |
| 4 | 4 | Description: Adds MakeCommerce payment gateway and Itella/Omniva parcel machine shipping methods to Woocommerce checkout |
| 5 | - Version: 2.1.3 | |
| 5 | + Version: 2.6.2 | |
| 6 | 6 | Author: Maksekeskus AS |
| 7 | 7 | Author URI: https://MakeCommerce.net/ |
| 8 | 8 | Text Domain: wc_makecommerce_domain |
| 9 | + WC requires at least: 3.0 | |
| 10 | + WC tested up to: 4.5.1 | |
| 9 | 11 | */ |
| 10 | 12 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 13 | +if (!defined('ABSPATH')) { | |
| 12 | 14 | exit; // Exit if accessed directly. |
| 13 | 15 | } |
| 14 | 16 | |
| 15 | -if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| 17 | +include_once(ABSPATH.'wp-admin/includes/plugin.php'); | |
| 18 | +if (is_plugin_active('woocommerce/woocommerce.php')) { | |
| 16 | 19 | |
| 17 | - | |
| 18 | 20 | define('WC_MC_VERSION', 2.0); |
| 19 | 21 | |
| 20 | - $enable_experimental = get_option('mk_experimental_features', false); | |
| 21 | - if ($enable_experimental && $enable_experimental !== 'no') { | |
| 22 | + $enable_experimental = get_option('mk_checkout_sco', 'no'); | |
| 23 | + if ($enable_experimental === 'yes') { | |
| 22 | 24 | require_once(__DIR__.'/makecommerce-simplecheckout.php'); |
| 23 | 25 | } |
| 24 | 26 | require_once(__DIR__.'/makecommerce-transport.php'); |
| 25 | 27 | require_once(__DIR__.'/makecommerce-payment.php'); |
| 26 | 28 | |
| 29 | + if (is_admin() && !extension_loaded('curl')) { | |
| 30 | + add_action('admin_notices', function(){ | |
| 31 | + $class = 'notice notice-error'; | |
| 32 | + $message = __( 'You have enabled MakeCommerce module but it seems that you don\'t have CURL enabled. This way MakeCommerce unfortunately does not work!', 'wc_makecommerce_domain'); | |
| 33 | + printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); | |
| 34 | + }); | |
| 35 | + } | |
| 36 | + | |
| 37 | + | |
| 27 | 38 | global $mkDbTable; |
| 28 | 39 | $mkDbTable = 'mc_banklinks'; |
| 29 | 40 | |
| 30 | 41 | function mc_install() { |
| @@ -40,8 +51,11 @@ | ||
| 40 | 51 | type varchar(10) NOT NULL, |
| 41 | 52 | country char(2) NOT NULL, |
| 42 | 53 | name varchar(25) NOT NULL, |
| 43 | 54 | url varchar(250) NOT NULL, |
| 55 | + logo_url varchar(250), | |
| 56 | + min_amount mediumint(9), | |
| 57 | + max_amount mediumint(9), | |
| 44 | 58 | UNIQUE KEY id (id) |
| 45 | 59 | ) $charset;"; |
| 46 | 60 | |
| 47 | 61 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| @@ -64,9 +78,9 @@ | ||
| 64 | 78 | // Assign schedule if not set, update compatible no need to reactivate, format('U') php 5.2 compatible |
| 65 | 79 | // Assigns task at 23.59.59 by local time, task runs if time has passed and somebody navigates the site |
| 66 | 80 | if (! wp_next_scheduled ( 'mc_banklinks_update_cron' )) { |
| 67 | 81 | $date = new DateTime(); |
| 68 | - $date->setTime(04,10,00); | |
| 82 | + $date->setTime(rand(0,23),rand(0,59),00); | |
| 69 | 83 | $timestamp = intval($date->format('U')); |
| 70 | 84 | //$local = 3600 * intval(get_option('gmt_offset')); |
| 71 | 85 | //wp_schedule_event($timestamp - $local, 'twicedaily', 'mc_banklinks_update_cron'); |
| 72 | 86 | wp_schedule_event($timestamp, 'twicedaily', 'mc_banklinks_update_cron'); |
| @@ -76,13 +90,36 @@ | ||
| 76 | 90 | require_once('includes/vendor/autoload.php'); |
| 77 | 91 | require_once('includes/Maksekeskus.php'); |
| 78 | 92 | } |
| 79 | 93 | |
| 80 | - function mk_check_payment() { | |
| 94 | + function mk_check_payment() { | |
| 81 | 95 | |
| 82 | 96 | global $woocommerce; |
| 83 | 97 | $api = mk_get_api(); |
| 84 | 98 | |
| 99 | + //set the correct language | |
| 100 | + if (isset($_GET["lang1"])) { | |
| 101 | + //set polylang language | |
| 102 | + if (function_exists('pll_current_language')) { | |
| 103 | + //get the correct locale name from polylang | |
| 104 | + $polylangLangs = pll_the_languages(array('raw' => 1)); | |
| 105 | + if (isset($polylangLangs[$_GET["lang1"]])) { | |
| 106 | + $locale = str_replace("-", "_", $polylangLangs[$_GET["lang1"]]["locale"]); | |
| 107 | + } | |
| 108 | + | |
| 109 | + //first change WP language, this triggers some polylang hooks | |
| 110 | + switch_to_locale($locale); | |
| 111 | + | |
| 112 | + //second, change WPML language?!?! this ensures the correct landingpage (works with polylang) | |
| 113 | + do_action('wpml_switch_language', $_GET["lang1"]); | |
| 114 | + } else { | |
| 115 | + if (function_exists('icl_object_id')) { //weirdly enough icl_object ID exists in this point of the request. It doesn't in other locations... | |
| 116 | + //set wpml language | |
| 117 | + do_action('wpml_switch_language', $_GET["lang1"]); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | + | |
| 85 | 122 | $returnUrl = home_url(); |
| 86 | 123 | |
| 87 | 124 | $request = stripslashes_deep($_POST); |
| 88 | 125 | if ($api->verifyMac($request)) { |
| @@ -119,9 +156,9 @@ | ||
| 119 | 156 | $paymentStatus = $transaction->status; |
| 120 | 157 | |
| 121 | 158 | if ($paymentStatus == 'PENDING') { |
| 122 | 159 | $paymentRequest = array( |
| 123 | - 'amount' => $transaction->amount, | |
| 160 | + 'amount' => (string)sprintf("%.2f", $transaction->amount), | |
| 124 | 161 | 'currency' => $transaction->currency, |
| 125 | 162 | 'token' => $data['token']['id'] |
| 126 | 163 | ); |
| 127 | 164 | $payment = $api->createPayment($transactionId, $paymentRequest); |
| @@ -141,31 +178,57 @@ | ||
| 141 | 178 | if (!$reference) { return $returnUrl; } |
| 142 | 179 | |
| 143 | 180 | $order = new WC_Order($reference); |
| 144 | 181 | // if we din't find the Order, we send user to shop landing-page. TODO: could be improved |
| 145 | - if (!$order->id) { return $returnUrl; } | |
| 182 | + if (!$order->get_id()) { return $returnUrl; } | |
| 146 | 183 | |
| 147 | 184 | $returnUrl = $order->get_checkout_order_received_url(); |
| 148 | 185 | |
| 186 | + if ($paymentStatus == 'CANCELLED' || $paymentStatus == 'COMPLETED') { | |
| 187 | + //get transaction to update the payment method. | |
| 188 | + $transaction = $api->getTransaction($transactionId); | |
| 189 | + | |
| 190 | + //make sure the payment method is the same for simplecheckout and normal version. | |
| 191 | + $paymentMethod = ""; | |
| 192 | + if (isset($transaction->type) && isset($transaction->method)) { | |
| 193 | + if ($transaction->type == "card") { | |
| 194 | + $paymentMethod = "card_".$transaction->method; | |
| 195 | + } else { | |
| 196 | + if (isset($transaction->country)) { | |
| 197 | + $paymentMethod = $transaction->country."_".$transaction->method; | |
| 198 | + } | |
| 199 | + } | |
| 200 | + } | |
| 201 | + | |
| 202 | + //update _makecommerce_preselected_method | |
| 203 | + update_post_meta($order->get_id(), '_makecommerce_preselected_method', $paymentMethod); | |
| 204 | + } | |
| 205 | + | |
| 149 | 206 | switch($paymentStatus) { |
| 150 | 207 | |
| 151 | 208 | case 'CANCELLED': |
| 152 | 209 | $order->update_status( 'cancelled' ); |
| 153 | 210 | wc_add_notice(__('Payment transaction cancelled', 'wc_makecommerce_domain'), 'error'); |
| 154 | - $returnUrl = $woocommerce->cart->get_cart_url(); | |
| 211 | + $returnUrl = wc_get_cart_url(); | |
| 155 | 212 | break; |
| 156 | 213 | |
| 157 | 214 | case 'COMPLETED': |
| 158 | 215 | $orderNote = array(); |
| 159 | 216 | $orderNote[] = __('Transaction ID', 'wc_makecommerce_domain') . ': <a target=_blank href="'.$api->getEnvUrls()->merchantUrl.'/merchant/shop/deals/detail.html?id='. $transactionId .'">'.$transactionId.'</a>'; |
| 160 | - $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->id, '_makecommerce_preselected_method', true); | |
| 217 | + $orderNote[] = __('Payment option', 'wc_makecommerce_domain') . ': ' . get_post_meta($order->get_id(), '_makecommerce_preselected_method', true); | |
| 161 | 218 | $order->add_order_note(implode("\r\n", $orderNote)); |
| 219 | + if (!empty($data['token']) && !empty($data['token']['multiuse'])) { | |
| 220 | + update_post_meta($order->get_id(), '_makecommerce_payment_token', $data['token']['id']); | |
| 221 | + update_post_meta($order->get_id(), '_makecommerce_payment_token_valid_until', $data['token']['valid_until']); | |
| 222 | + } | |
| 162 | 223 | |
| 163 | - $order->payment_complete(); | |
| 164 | - $order->update_status( 'processing' ); | |
| 224 | + if (isset($_GET['lang1'])) { | |
| 225 | + $order->update_meta_data('wpml_language', $_GET["lang1"]); | |
| 226 | + } | |
| 227 | + | |
| 228 | + $order->payment_complete( $transactionId ); | |
| 165 | 229 | $woocommerce->cart->empty_cart(); |
| 166 | 230 | break; |
| 167 | - | |
| 168 | 231 | } |
| 169 | 232 | |
| 170 | 233 | return $returnUrl; |
| 171 | 234 | } |
| @@ -253,9 +316,9 @@ | ||
| 253 | 316 | add_action('wp_login', 'mk_admin_login_update', 10, 2); |
| 254 | 317 | |
| 255 | 318 | |
| 256 | 319 | |
| 257 | - function mk_admin_add_api_settings($sections) { | |
| 320 | + function mk_admin_add_api_settings($sections) { | |
| 258 | 321 | $sections['mk_api'] = __('MakeCommerce API access', 'wc_makecommerce_domain'); |
| 259 | 322 | return $sections; |
| 260 | 323 | } |
| 261 | 324 | |
| @@ -269,15 +332,9 @@ | ||
| 269 | 332 | array( |
| 270 | 333 | 'type' => 'title', |
| 271 | 334 | 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'), |
| 272 | 335 | 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain'). |
| 273 | - sprintf( __('To further configure the Payment methods please go to <a href="%s">MakeCommerce Checkout Options</a><br>', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout§ion=makecommerce'). | |
| 274 | - sprintf( __('To use also Ominva or Itella SmartPOST integration please configure these API accesses: <a href="%s">Omniva Parcel Machine API access</a> | '. | |
| 275 | - '<a href="%s">SmartPOST API access</a> | <a href="%s">Omniva Courier API access</a><br/>','wc_makecommerce_domain'), | |
| 276 | - 'admin.php?page=wc-settings&tab=-shipping§ion=parcelmachine_omniva', | |
| 277 | - 'admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost', | |
| 278 | - 'admin.php?page=wc-settings&tab=shipping§ion=courier_omniva' | |
| 279 | - ), | |
| 336 | + sprintf( __('To further configure the Payment methods please go to <a href=."%s">MakeCommerce Checkout Options</a>, links to settings of our Shipment methods are listed below', 'wc_makecommerce_domain'), 'admin.php?page=wc-settings&tab=checkout§ion=makecommerce'), | |
| 280 | 337 | 'id' => 'mk_api_settings' |
| 281 | 338 | ), |
| 282 | 339 | array( |
| 283 | 340 | 'type' => 'select', |
| @@ -330,15 +387,75 @@ | ||
| 330 | 387 | 'title' => __('Publishable key (test)', 'wc_makecommerce_domain'), |
| 331 | 388 | 'default' => '7Hog41ci2mKkmtviMycWxpNx14pNP70m', |
| 332 | 389 | 'class' => 'input-text regular-input', |
| 333 | 390 | ), |
| 391 | + array('type' => 'sectionend', 'id' => 'mk_api_settings'), | |
| 392 | + array( | |
| 393 | + 'type' => 'title', | |
| 394 | + 'desc' => '<br><hr><br>', | |
| 395 | + ), | |
| 396 | + array( | |
| 397 | + 'id' => 'mk_module_title', | |
| 398 | + 'type' => 'title', | |
| 399 | + 'title' => __('Makecommerce modules', 'wc_makecommerce_domain'), | |
| 400 | + 'desc' => __('Our plugin adds several modules to your shop. Here you can switch off modules that are not important for you, they will disappear from Woocommerce settings menus.<br> Each active module have their own settings dialog, where they must also be Enabled before use.', 'wc_makecommerce_domain'), | |
| 401 | + 'class' => '', | |
| 402 | + ), | |
| 334 | 403 | array( |
| 335 | - 'id' => 'mk_experimental_features', | |
| 404 | + 'id' => 'mk_transport_apt_omniva', | |
| 336 | 405 | 'type' => 'checkbox', |
| 337 | - 'title' => __('Enable experimental features', 'wc_makecommerce_domain'), | |
| 406 | + 'default' => 'yes', | |
| 407 | + 'title' => __('Omniva Parcel Machine', 'wc_makecommerce_domain'), | |
| 408 | + 'desc' => __('enable Omniva parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_omniva')).')', | |
| 338 | 409 | 'class' => '', |
| 339 | 410 | ), |
| 340 | 411 | array( |
| 412 | + 'id' => 'mk_transport_apt_smartpost', | |
| 413 | + 'type' => 'checkbox', | |
| 414 | + 'default' => 'yes', | |
| 415 | + 'title' => __('SmartPOST Parcel Machine', 'wc_makecommerce_domain'), | |
| 416 | + 'desc' => __('enable SmartPOST parcel machines shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_smartpost')).')', | |
| 417 | + 'class' => '', | |
| 418 | + ), | |
| 419 | + array( | |
| 420 | + 'id' => 'mk_transport_apt_dpd', | |
| 421 | + 'type' => 'checkbox', | |
| 422 | + 'default' => 'no', | |
| 423 | + 'title' => __('DPD', 'wc_makecommerce_domain') . ' ' . __('parcel machine', 'wc_makecommerce_domain'), | |
| 424 | + 'desc' => __('enable DPD parcel machine shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=parcelmachine_dpd')).')', | |
| 425 | + 'class' => '', | |
| 426 | + ), | |
| 427 | + array( | |
| 428 | + 'id' => 'mk_transport_courier_omniva', | |
| 429 | + 'type' => 'checkbox', | |
| 430 | + 'default' => 'yes', | |
| 431 | + 'title' => __('Omniva Courier', 'wc_makecommerce_domain'), | |
| 432 | + 'desc' => __('enable Omniva courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=courier_omniva')).')', | |
| 433 | + 'class' => '', | |
| 434 | + ), | |
| 435 | + array( | |
| 436 | + 'id' => 'mk_transport_courier_smartpost', | |
| 437 | + 'type' => 'checkbox', | |
| 438 | + 'default' => 'yes', | |
| 439 | + 'title' => __('SmartPOST Courier', 'wc_makecommerce_domain'), | |
| 440 | + 'desc' => __('enable SmartPOST courier shipping method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=shipping§ion=courier_smartpost')).')', | |
| 441 | + 'class' => '', | |
| 442 | + ), | |
| 443 | + array( | |
| 444 | + 'id' => 'mk_checkout_sco', | |
| 445 | + 'type' => 'checkbox', | |
| 446 | + 'title' => __('SimpleCheckout', 'wc_makecommerce_domain'), | |
| 447 | + 'desc' => __('enable SimpleCheckout™ Checkout method', 'wc_makecommerce_domain').' ('. sprintf(__('<a href="%s">module settings</a>', 'wc_makecommerce_domain'), admin_url('admin.php?page=wc-settings&tab=checkout§ion=makecommerce_sc')).')', | |
| 448 | + 'class' => '', | |
| 449 | + ), | |
| 450 | + array( | |
| 451 | + 'id' => 'mk_product_slice', | |
| 452 | + 'type' => 'checkbox', | |
| 453 | + 'title' => __('Indivy Slice 3 information in product view', 'wc_makecommerce_domain'), | |
| 454 | + 'desc' => __('enable Indivy Slice 3 in product view', 'wc_makecommerce_domain'), | |
| 455 | + 'class' => '', | |
| 456 | + ), | |
| 457 | + array( | |
| 341 | 458 | 'id' => 'mk_javascript_ui', |
| 342 | 459 | 'type' => 'api_javascript_ui', |
| 343 | 460 | ), |
| 344 | 461 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| @@ -344,8 +461,17 @@ | ||
| 344 | 461 | array('type' => 'sectionend', 'id' => 'mk_api_settings') |
| 345 | 462 | ); |
| 346 | 463 | } |
| 347 | 464 | |
| 465 | + function mk_wc_version($version) { | |
| 466 | + global $woocommerce; | |
| 467 | + if ( version_compare( $woocommerce->version, "3.4.0", ">=" ) ) { | |
| 468 | + return true; | |
| 469 | + } else { | |
| 470 | + return false; | |
| 471 | + } | |
| 472 | + } | |
| 473 | + | |
| 348 | 474 | function mk_admin_save_api_settings() { |
| 349 | 475 | // reload banklinks |
| 350 | 476 | global $current_section; |
| 351 | 477 | if ($current_section !== 'mk_api') { |
| @@ -353,17 +479,55 @@ | ||
| 353 | 479 | } |
| 354 | 480 | update_mc_banklinks(); |
| 355 | 481 | } |
| 356 | 482 | |
| 357 | - function mk_admin_plugin_settings_link($links) { | |
| 358 | - $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; | |
| 359 | - array_unshift($links, $settings_link); | |
| 360 | - return $links; | |
| 483 | + function mk_admin_plugin_settings_link($links) { | |
| 484 | + if (mk_wc_version("3.4.0")) | |
| 485 | + $settings_link = '<a href="admin.php?page=wc-settings&tab=advanced§ion=mk_api">API '.__('Settings').'</a>'; | |
| 486 | + else | |
| 487 | + $settings_link = '<a href="admin.php?page=wc-settings&tab=api§ion=mk_api">API '.__('Settings').'</a>'; | |
| 488 | + array_unshift($links, $settings_link); | |
| 489 | + return $links; | |
| 361 | 490 | } |
| 491 | + | |
| 492 | + function wc_mc_shop_slice_button() { | |
| 493 | + if (get_option('mk_product_slice', 'no') == 'yes') { | |
| 494 | + global $product; | |
| 495 | + // $price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT | |
| 496 | + $price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT | |
| 497 | + global $wpdb; | |
| 498 | + global $mkDbTable; | |
| 499 | + $tableName = $wpdb->prefix . $mkDbTable; | |
| 500 | + $methods = $wpdb->get_results('SELECT * FROM '.$tableName); | |
| 501 | + $slice = false; | |
| 502 | + if(count($methods)) { | |
| 503 | + foreach ($methods as $method) { | |
| 504 | + if ($method->name =="slice") { | |
| 505 | + if ( $price_incl_tax >= $method->min_amount ) { | |
| 506 | + if ( $price_incl_tax <= $method->max_amount ) { | |
| 507 | + $slice = true; | |
| 508 | + } | |
| 509 | + } | |
| 510 | + } | |
| 511 | + } | |
| 512 | + } | |
| 513 | + if ($slice == true) { | |
| 514 | + echo '<div style="width:100%; margin-top: 20px; margin-bottom: auto;"><img src="'.plugins_url('/images/slice_logo_dark_176x62.svg', __FILE__).'" width="88" weight="31"/> Osta kohe, maksa hiljem. Kolmes võrdses osas 3 x '.sprintf("%.2f",$price_incl_tax/3).' €</div>'; // sprintf("%.2f",$price_incl_tax/3).' in month | |
| 515 | + } | |
| 516 | + } | |
| 517 | + } | |
| 518 | + // Slice Promo 1 | |
| 519 | + add_action( 'woocommerce_after_add_to_cart_button', 'wc_mc_shop_slice_button', 20 ); | |
| 520 | + | |
| 521 | + // if (mk_wc_version("3.4.0")) { | |
| 522 | + add_filter('woocommerce_get_settings_advanced', 'mk_admin_api_settings', 10, 2); | |
| 523 | + add_action('woocommerce_get_sections_advanced', 'mk_admin_add_api_settings'); | |
| 362 | 524 | add_filter('woocommerce_get_settings_api', 'mk_admin_api_settings', 10, 2); |
| 525 | + // } else { | |
| 363 | 526 | add_action('woocommerce_get_sections_api', 'mk_admin_add_api_settings'); |
| 364 | 527 | add_action('woocommerce_settings_saved', 'mk_admin_save_api_settings', 30, 0); |
| 365 | 528 | add_filter("plugin_action_links_".plugin_basename(__FILE__), 'mk_admin_plugin_settings_link' ); |
| 529 | + // } | |
| 366 | 530 | |
| 367 | 531 | function __get_logo_html() { |
| 368 | 532 | return '<div class="makecommerce-info">'. |
| 369 | 533 | '<div class="makecommerce-logo">'. |
| @@ -375,5 +539,34 @@ | ||
| 375 | 539 | '<div class="makecommerce-link"><a target="_blank" href="http://maksekeskus.ee">maksekeskus.ee</a></div>'. |
| 376 | 540 | '</div>'. |
| 377 | 541 | '</div>'; |
| 378 | 542 | } |
| 543 | + | |
| 544 | + /* add new column (makecommerce_payment_method) to orders list */ | |
| 545 | + function wc_makecommerce_payment_method_order_column($columns) | |
| 546 | + { | |
| 547 | + $columns['makecommerce_payment_method'] = __('Payment method (MC)'); | |
| 548 | + return $columns; | |
| 549 | + } | |
| 550 | + | |
| 551 | + add_filter('manage_edit-shop_order_columns', 'wc_makecommerce_payment_method_order_column'); | |
| 552 | + | |
| 553 | + // Make custom column sortable | |
| 554 | + add_filter( "manage_edit-shop_order_sortable_columns", 'makecommerce_payment_method_sortable' ); | |
| 555 | + function makecommerce_payment_method_sortable($columns) | |
| 556 | + { | |
| 557 | + $meta_key = 'makecommerce_payment_method'; | |
| 558 | + return wp_parse_args(array('makecommerce_payment_method' => $meta_key), $columns); | |
| 559 | + } | |
| 560 | + | |
| 561 | + /* fill content for makecommerce_payment_method */ | |
| 562 | + function wc_makecommerce_payment_method_order_column_content($column) | |
| 563 | + { | |
| 564 | + global $post; | |
| 565 | + | |
| 566 | + if ('makecommerce_payment_method' === $column) { | |
| 567 | + echo get_post_meta($post->ID, '_makecommerce_preselected_method', true); | |
| 568 | + } | |
| 569 | + } | |
| 570 | + | |
| 571 | + add_action('manage_shop_order_posts_custom_column', 'wc_makecommerce_payment_method_order_column_content'); | |
| 379 | 572 | } |