| @@ -24,16 +24,8 @@ | ||
| 24 | 24 | */ |
| 25 | 25 | class API { |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Shipping+ confirmation page and the authorization data guarding its form. | |
| 29 | - */ | |
| 30 | - public const SHIPPING_PLUS_SLUG = 'makecommerce_shipping_plus'; | |
| 31 | - public const SHIPPING_PLUS_CAPABILITY = 'manage_options'; | |
| 32 | - public const SHIPPING_PLUS_NONCE_ACTION = 'mc_shipping_plus_confirm'; | |
| 33 | - public const SHIPPING_PLUS_NONCE_FIELD = 'mc_shipping_plus_nonce'; | |
| 34 | - | |
| 35 | - /** | |
| 36 | 28 | * The ID of this plugin. |
| 37 | 29 | * |
| 38 | 30 | * @since 3.0.0 |
| 39 | 31 | * @access private |
| @@ -145,10 +137,9 @@ | ||
| 145 | 137 | */ |
| 146 | 138 | public function fill_ordersview_paymentmethod_column( $column, $post_id ) { |
| 147 | 139 | |
| 148 | 140 | if ( 'makecommerce_payment_method' === $column ) { |
| 149 | - $order = wc_get_order( $post_id ); | |
| 150 | - echo $order->get_meta( '_makecommerce_preselected_method', true ); | |
| 141 | + echo get_post_meta( $post_id, '_makecommerce_preselected_method', true ); | |
| 151 | 142 | } |
| 152 | 143 | } |
| 153 | 144 | |
| 154 | 145 | /** |
| @@ -227,18 +218,8 @@ | ||
| 227 | 218 | * Return array with fields for settings |
| 228 | 219 | */ |
| 229 | 220 | return [ |
| 230 | 221 | [ 'type' => 'title', 'desc' => \MakeCommerce::get_logo_html() ], |
| 231 | - [ | |
| 232 | - 'type' => 'title', | |
| 233 | - 'title' => __('MakeCommerce Shipping+ is now available', 'wc_makecommerce_domain'), | |
| 234 | - 'desc' => sprintf( | |
| 235 | - __('You\'re still using the legacy version — <a href="%s">click here to switch to the new module</a>', 'wc_makecommerce_domain'), | |
| 236 | - admin_url('admin.php?page=makecommerce_shipping_plus') | |
| 237 | - ), | |
| 238 | - 'id' => 'mk_api_settings' | |
| 239 | - ], | |
| 240 | - ['type' => 'sectionend', 'id' => 'mk_api_settings'], | |
| 241 | 222 | [ |
| 242 | 223 | 'type' => 'title', |
| 243 | 224 | 'title' => __('MakeCommerce API access credentials', 'wc_makecommerce_domain'), |
| 244 | 225 | 'desc' => __('To use MakeCommerce/Maksekeskus services you need to enter API credentials below here <br/> <br/>', 'wc_makecommerce_domain'). |
| @@ -373,10 +354,10 @@ | ||
| 373 | 354 | [ |
| 374 | 355 | 'id' => 'mk_transport_apt_smartpost', |
| 375 | 356 | 'type' => 'checkbox', |
| 376 | 357 | 'default' => 'yes', |
| 377 | - 'title' => __('SmartPosti Parcel Machine', 'wc_makecommerce_domain'), | |
| 378 | - 'desc' => __('enable SmartPosti 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')).')', | |
| 358 | + 'title' => __('Smartpost Parcel Machine', 'wc_makecommerce_domain'), | |
| 359 | + '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')).')', | |
| 379 | 360 | 'class' => '', |
| 380 | 361 | ], |
| 381 | 362 | [ |
| 382 | 363 | 'id' => 'mk_transport_apt_dpd', |
| @@ -410,16 +391,8 @@ | ||
| 410 | 391 | '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')).')', |
| 411 | 392 | 'class' => '', |
| 412 | 393 | ], |
| 413 | 394 | [ |
| 414 | - 'id' => 'mk_transport_courier_dpd', | |
| 415 | - 'type' => 'checkbox', | |
| 416 | - 'default' => 'yes', | |
| 417 | - 'title' => __('DPD Courier', 'wc_makecommerce_domain'), | |
| 418 | - 'desc' => __('enable DPD 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_dpd')).')', | |
| 419 | - 'class' => '', | |
| 420 | - ], | |
| 421 | - [ | |
| 422 | 395 | 'id' => 'mk_javascript_ui', |
| 423 | 396 | 'type' => 'api_javascript_ui', |
| 424 | 397 | ], |
| 425 | 398 | ['type' => 'sectionend', 'id' => 'mk_api_settings'] |
| @@ -462,136 +435,6 @@ | ||
| 462 | 435 | <?php } ?> |
| 463 | 436 | </p> |
| 464 | 437 | </div> |
| 465 | 438 | <?php |
| 466 | - } | |
| 467 | - | |
| 468 | - | |
| 469 | - public function shipping_api_notice() | |
| 470 | - { | |
| 471 | - ?> | |
| 472 | - <div class="notice notice-success"> | |
| 473 | - <p> | |
| 474 | - <strong><?php echo __('MakeCommerce Shipping+ is now available', 'wc_makecommerce_domain'); ?> </strong> <br/> | |
| 475 | - <?php echo __("You're still using the legacy version —", 'wc_makecommerce_domain'); ?> | |
| 476 | - <a href="<?php echo admin_url('admin.php?page=makecommerce_shipping_plus'); ?>"><?php echo __('click here to switch to the new module', 'wc_makecommerce_domain'); ?></a> | |
| 477 | - </p> | |
| 478 | - </div> | |
| 479 | - <?php | |
| 480 | - } | |
| 481 | - | |
| 482 | - // Separate Admin page for Shipping+ confirmation, when user checks shipping+ in old version | |
| 483 | - public function enqueue_shipping_plus_assets($hook): void | |
| 484 | - { | |
| 485 | - if ($hook !== 'admin_page_makecommerce_shipping_plus') { | |
| 486 | - return; | |
| 487 | - } | |
| 488 | - | |
| 489 | - wp_enqueue_style( | |
| 490 | - 'makecommerce-bootstrap', | |
| 491 | - plugin_dir_url(__DIR__) . 'makecommerce/assets/bootstrap.5.3.3.min.css' | |
| 492 | - ); | |
| 493 | - | |
| 494 | - wp_enqueue_style( | |
| 495 | - 'shipping-confirm', | |
| 496 | - 'https://static.maksekeskus.ee/modules/woocommerce/css/shipping-confirm.css' | |
| 497 | - ); | |
| 498 | - | |
| 499 | - wp_enqueue_script( | |
| 500 | - 'makecommerce-bootstrap', | |
| 501 | - plugin_dir_url(__DIR__) . 'makecommerce/assets/bootstrap.bundle.min.js', | |
| 502 | - [], | |
| 503 | - null, | |
| 504 | - true | |
| 505 | - ); | |
| 506 | - } | |
| 507 | - public function add_shipping_plus_admin_page() | |
| 508 | - { | |
| 509 | - add_submenu_page( | |
| 510 | - 'shipping_plus', | |
| 511 | - 'Shipping+ Confirmation', | |
| 512 | - 'Shipping+ Confirmation', | |
| 513 | - self::SHIPPING_PLUS_CAPABILITY, | |
| 514 | - self::SHIPPING_PLUS_SLUG, | |
| 515 | - [$this, 'render_shipping_plus_page'] | |
| 516 | - ); | |
| 517 | - } | |
| 518 | - | |
| 519 | - public function remove_shipping_confirm_menu(): void { | |
| 520 | - remove_submenu_page( 'shipping_plus', self::SHIPPING_PLUS_SLUG ); | |
| 521 | - } | |
| 522 | - | |
| 523 | - public function render_shipping_plus_page() | |
| 524 | - { | |
| 525 | - $file = plugin_dir_path(__FILE__) . 'templates/shipping_confirm.php'; | |
| 526 | - | |
| 527 | - if (file_exists($file)) { | |
| 528 | - include $file; | |
| 529 | - } else { | |
| 530 | - echo '<div class="wrap"><h1>Page not found</h1></div>'; | |
| 531 | - } | |
| 532 | - } | |
| 533 | - | |
| 534 | - public function hide_shipping_admin_notices(): void | |
| 535 | - { | |
| 536 | - $screen = get_current_screen(); | |
| 537 | - | |
| 538 | - if ($screen && $screen->id === 'admin_page_makecommerce_shipping_plus') { | |
| 539 | - remove_all_actions('admin_notices'); | |
| 540 | - remove_all_actions('all_admin_notices'); | |
| 541 | - } | |
| 542 | - } | |
| 543 | - | |
| 544 | - public function save_shipping_plus_confirmation(): void | |
| 545 | - { | |
| 546 | - $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; | |
| 547 | - | |
| 548 | - if ( | |
| 549 | - isset($_POST['accept_shipping']) && | |
| 550 | - $current_page === self::SHIPPING_PLUS_SLUG | |
| 551 | - ) { | |
| 552 | - // Only users who are allowed to see this page may confirm the migration | |
| 553 | - if (!current_user_can(self::SHIPPING_PLUS_CAPABILITY)) { | |
| 554 | - wp_die( | |
| 555 | - esc_html__('You do not have permission to change MakeCommerce settings.', 'wc_makecommerce_domain'), | |
| 556 | - esc_html__('Forbidden', 'wc_makecommerce_domain'), | |
| 557 | - ['response' => 403] | |
| 558 | - ); | |
| 559 | - } | |
| 560 | - | |
| 561 | - check_admin_referer(self::SHIPPING_PLUS_NONCE_ACTION, self::SHIPPING_PLUS_NONCE_FIELD); | |
| 562 | - | |
| 563 | - update_option('mc_shipping_plus_confirmed', 'yes'); | |
| 564 | - update_option('mc_shipping_plus', 'yes'); | |
| 565 | - update_option('makecommerce_install_status', 'upgrade'); | |
| 566 | - $this->mc_shipping_plus_creds_migration(); | |
| 567 | - wp_redirect(admin_url('admin.php?page=makecommerce_dashboard')); | |
| 568 | - exit; | |
| 569 | - } | |
| 570 | - } | |
| 571 | - | |
| 572 | - /** | |
| 573 | - * Run credentials migration when 'mc_shipping_plus' is turned on | |
| 574 | - * | |
| 575 | - * @return void | |
| 576 | - */ | |
| 577 | - private function mc_shipping_plus_creds_migration(): void | |
| 578 | - { | |
| 579 | - $migration_map = [ | |
| 580 | - 'mc_shop_id' => 'mk_shop_id', | |
| 581 | - 'mc_secret_key' => 'mk_private_key', | |
| 582 | - 'mc_public_key' => 'mk_public_key', | |
| 583 | - 'mc_test_shop_id' => 'mk_test_shop_id', | |
| 584 | - 'mc_test_secret_key' => 'mk_test_private_key', | |
| 585 | - 'mc_test_public_key' => 'mk_test_public_key', | |
| 586 | - 'mc_api_mode' => 'mk_api_type', | |
| 587 | - ]; | |
| 588 | - | |
| 589 | - foreach ($migration_map as $new_key => $old_key) { | |
| 590 | - $old_value = get_option($old_key, null); | |
| 591 | - | |
| 592 | - if ($old_value !== null) { | |
| 593 | - update_option($new_key, $old_value); | |
| 594 | - } | |
| 595 | - } | |
| 596 | 439 | } |
| 597 | 440 | } |