import React from 'react'; import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; import { CheckboxControl, RadioControl, TextareaControl, TextControl, __experimentalNumberControl as NumberControl } from '@wordpress/components'; import ProductsAndVariationsCompleter from './ProductsAndVariationsCompleter'; import SelectWithLabel from '../SelectWithLabel'; import withMetaboxValidation from './withMetaboxValidation'; import { OrderBumpsMeta, ValidationRules } from '../../Types/ValidationRules'; const getValidationRules: ( meta: OrderBumpsMeta ) => ValidationRules = ( meta ) => ( { cfw_ob_offer_quantity: { required() { return meta.cfw_ob_upsell === 'yes'; }, number: true, }, cfw_ob_offer_product_v9: { required: true, error: 'You must select an offer product.', }, } ); const OrderBumpsOfferPanel = ( { meta, handleFieldChange } ) => ( { handleFieldChange( 'cfw_ob_offer_product_v9', newValues ); } } /> { handleFieldChange( 'cfw_ob_auto_add', newValue ? 'yes' : 'no' ); } } /> {meta.cfw_ob_upsell !== 'yes' && (

Add offer product to the cart with the same variable configuration as the product below.

Only applies when Auto Match Cart Product and Offer Product are variable products with matching variation attributes (Size, Color, etc)

Leave unchecked to have customers to select variation options in a modal window.

If offer product is not variable, this option is ignored.

) } checked={ meta.cfw_ob_enable_auto_match === 'yes' } onChange={ ( newValue: boolean ) => { handleFieldChange( 'cfw_ob_enable_auto_match', newValue ? 'yes' : 'no' ); } } /> ) } {meta.cfw_ob_upsell !== 'yes' && meta.cfw_ob_enable_auto_match === 'yes' && ( The product in the cart to match the Order Bump variations to. ) } onChange={ ( newValues: any ) => { handleFieldChange( 'cfw_ob_variation_match_product', newValues ); } } /> )} {meta.cfw_ob_upsell !== 'yes' && <> { handleFieldChange( 'cfw_ob_match_offer_product_quantity', newValue ? 'yes' : 'no' ); } } /> } {meta.cfw_ob_match_offer_product_quantity === 'yes' && ( The product in the cart to match the Order Bump quantity to. ) } onChange={ ( newValues: any ) => { handleFieldChange( 'cfw_ob_quantity_match_product', newValues ); } } /> )} { ( meta.cfw_ob_upsell !== 'yes' && meta.cfw_ob_match_offer_product_quantity !== 'yes' ) && <> { handleFieldChange( 'cfw_ob_offer_quantity', newValue ); } } /> { handleFieldChange( 'cfw_ob_enable_quantity_updates', newValue ? 'yes' : 'no' ); } } /> }
); export default withMetaboxValidation( OrderBumpsOfferPanel, getValidationRules );