Skip to content

Commit

Permalink
Track stock quantity for this product should be disabled when Enable …
Browse files Browse the repository at this point in the history
…stock management within settings is disabled, and enabled otherwise (#37957)

* Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise.

* Add changelog files
  • Loading branch information
mdperez86 committed Apr 24, 2023
1 parent 2ab11a7 commit fb7e68a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/js/product-editor/changelog/add-37888
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise
4 changes: 4 additions & 0 deletions packages/js/product-editor/src/blocks/toggle/block.json
Expand Up @@ -14,6 +14,10 @@
},
"property": {
"type": "string"
},
"disabled": {
"type": "boolean",
"default": false
}
},
"supports": {
Expand Down
3 changes: 2 additions & 1 deletion packages/js/product-editor/src/blocks/toggle/edit.tsx
Expand Up @@ -16,7 +16,7 @@ export function Edit( {
attributes,
}: BlockEditProps< ToggleBlockAttributes > ) {
const blockProps = useBlockProps();
const { label, property } = attributes;
const { label, property, disabled } = attributes;
const [ value, setValue ] = useEntityProp< boolean >(
'postType',
'product',
Expand All @@ -28,6 +28,7 @@ export function Edit( {
<ToggleControl
label={ label }
checked={ value }
disabled={ disabled }
onChange={ setValue }
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/js/product-editor/src/blocks/toggle/types.ts
Expand Up @@ -6,4 +6,5 @@ import { BlockAttributes } from '@wordpress/blocks';
export interface ToggleBlockAttributes extends BlockAttributes {
label: string;
property: string;
disabled?: boolean;
}
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/add-37888
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise
1 change: 1 addition & 0 deletions plugins/woocommerce/includes/class-wc-post-types.php
Expand Up @@ -625,6 +625,7 @@ public static function register_post_types() {
array(
'label' => __( 'Track stock quantity for this product', 'woocommerce' ),
'property' => 'manage_stock',
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
),
),
array(
Expand Down

0 comments on commit fb7e68a

Please sign in to comment.