class-wc-shipping-legacy-international-delivery.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Class WC_Shipping_Legacy_International_Delivery file.
  4. *
  5. * @package WooCommerce\Shipping
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit;
  9. }
  10. /**
  11. * International Delivery - Based on the Flat Rate Shipping Method.
  12. *
  13. * This class is here for backwards compatibility for methods existing before zones existed.
  14. *
  15. * @deprecated 2.6.0
  16. * @version 2.4.0
  17. * @package WooCommerce/Classes/Shipping
  18. */
  19. class WC_Shipping_Legacy_International_Delivery extends WC_Shipping_Legacy_Flat_Rate {
  20. /**
  21. * Constructor.
  22. */
  23. public function __construct() {
  24. $this->id = 'legacy_international_delivery';
  25. $this->method_title = __( 'International flat rate (legacy)', 'woocommerce' );
  26. /* translators: %s: Admin shipping settings URL */
  27. $this->method_description = '<strong>' . sprintf( __( 'This method is deprecated in 2.6.0 and will be removed in future versions - we recommend disabling it and instead setting up a new rate within your <a href="%s">Shipping zones</a>.', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=shipping' ) ) . '</strong>';
  28. $this->init();
  29. add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
  30. }
  31. /**
  32. * Return the name of the option in the WP DB.
  33. *
  34. * @since 2.6.0
  35. * @return string
  36. */
  37. public function get_option_key() {
  38. return $this->plugin_id . 'international_delivery_settings';
  39. }
  40. /**
  41. * Initialise settings form fields.
  42. */
  43. public function init_form_fields() {
  44. parent::init_form_fields();
  45. $this->form_fields['availability'] = array(
  46. 'title' => __( 'Availability', 'woocommerce' ),
  47. 'type' => 'select',
  48. 'class' => 'wc-enhanced-select',
  49. 'description' => '',
  50. 'default' => 'including',
  51. 'options' => array(
  52. 'including' => __( 'Selected countries', 'woocommerce' ),
  53. 'excluding' => __( 'Excluding selected countries', 'woocommerce' ),
  54. ),
  55. );
  56. }
  57. /**
  58. * Check if package is available.
  59. *
  60. * @param array $package Package information.
  61. * @return bool
  62. */
  63. public function is_available( $package ) {
  64. if ( 'no' === $this->enabled ) {
  65. return false;
  66. }
  67. if ( 'including' === $this->availability ) {
  68. if ( is_array( $this->countries ) && ! in_array( $package['destination']['country'], $this->countries, true ) ) {
  69. return false;
  70. }
  71. } else {
  72. if ( is_array( $this->countries ) && ( in_array( $package['destination']['country'], $this->countries, true ) || ! $package['destination']['country'] ) ) {
  73. return false;
  74. }
  75. }
  76. return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true, $package, $this );
  77. }
  78. }