Skip to content

Commit

Permalink
Disable or make GTIN field readonly depending on when GLA was install…
Browse files Browse the repository at this point in the history
…ed and what version of WC is installed
  • Loading branch information
martynmjones committed Sep 20, 2024
1 parent 2893750 commit 37edb29
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Admin/Product/Attributes/Input/GTINInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
class GTINInput extends Text {

/**
* @var string
*/
private $disabled_from = '2024-09-20';

/**
* GTINInput constructor.
*/
Expand All @@ -24,5 +29,29 @@ public function __construct() {

$this->set_label( __( 'Global Trade Item Number (GTIN)', 'google-listings-and-ads' ) );
$this->set_description( __( 'Global Trade Item Number (GTIN) for your item. These identifiers include UPC (in North America), EAN (in Europe), JAN (in Japan), and ISBN (for books)', 'google-listings-and-ads' ) );

$this->conditionally_restrict();
}

/**
* If Google for WooCommerce was installed after $this->disabled_from then
* this field will be disabled and not added to the product form.
*
* If Google for WooCommerce was installed before $this->disabled_from and
* WooCommerce version 9.2 or higher is installed then it will be readonly
*
* @since x.x.x
* @return void
*/
public function conditionally_restrict(): void {
if ( $this->gla_installed_after( $this->disabled_from ) ) {
$this->set_disabled( true );
return;
}

if ( version_compare( WC_VERSION, '9.2', '>=' ) ) {
$this->set_readonly( true );
$this->set_description( __( 'The Global Trade Item Number (GTIN) for your item can now be entered on the "Inventory" tab', 'google-listings-and-ads' ) );
}
}
}

0 comments on commit 37edb29

Please sign in to comment.