Add a notice to "track inventory" toggle (#40011)

* Add notice to "track inventory" toggle

* Add changelogs

* Remove console.logs

* Fix link URL
This commit is contained in:
Fernando Marichal 2023-09-05 08:35:38 -03:00 committed by GitHub
parent bbe053e16e
commit ccb72125e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Add notice to "track inventory" toggle #40011

View File

@ -19,3 +19,4 @@
@import 'variation-items/editor.scss';
@import 'variation-options/editor.scss';
@import 'taxonomy/editor.scss';
@import 'toggle/editor.scss';

View File

@ -18,6 +18,10 @@
"disabled": {
"type": "boolean",
"default": false
},
"disabledCopy": {
"type": "string",
"__experimentalRole": "content"
}
},
"supports": {

View File

@ -11,12 +11,13 @@ import { ToggleControl } from '@wordpress/components';
* Internal dependencies
*/
import { ToggleBlockAttributes } from './types';
import { sanitizeHTML } from '../../utils/sanitize-html';
export function Edit( {
attributes,
}: BlockEditProps< ToggleBlockAttributes > ) {
const blockProps = useBlockProps();
const { label, property, disabled } = attributes;
const { label, property, disabled, disabledCopy } = attributes;
const [ value, setValue ] = useEntityProp< boolean >(
'postType',
'product',
@ -31,6 +32,12 @@ export function Edit( {
disabled={ disabled }
onChange={ setValue }
/>
{ disabled && (
<p
className="wp-block-woocommerce-product-toggle__disable-copy"
dangerouslySetInnerHTML={ sanitizeHTML( disabledCopy ) }
/>
) }
</div>
);
}

View File

@ -0,0 +1,6 @@
.wp-block-woocommerce-product-toggle__disable-copy {
margin: $gap-small 0 0;
font-size: 12px;
color: $gray-700;
line-height: 1.5;
}

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Add notice to "track inventory" toggle #40011

View File

@ -552,6 +552,12 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
'label' => __( 'Track stock quantity for this product', 'woocommerce' ),
'property' => 'manage_stock',
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
'disabledCopy' => sprintf(
/* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/
__( 'Per your %1$sstore settings%2$s, inventory management is <strong>disabled</strong>.', 'woocommerce' ),
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products&section=inventory' ) . '" target="_blank" rel="noreferrer">',
'</a>'
),
],
]
);