2022-11-11 16:17:49 +00:00
/ * *
* External dependencies
* /
2024-04-10 13:17:14 +00:00
import { __ , _x } from '@wordpress/i18n' ;
2022-12-07 15:52:02 +00:00
import { createInterpolateElement , useState } from '@wordpress/element' ;
2023-04-22 09:10:11 +00:00
import { ADMIN_URL , getSetting } from '@woocommerce/settings' ;
2022-11-11 16:17:49 +00:00
import { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings' ;
import {
CheckboxControl ,
SelectControl ,
TextControl ,
ExternalLink ,
2022-12-07 15:52:02 +00:00
Notice ,
2022-11-11 16:17:49 +00:00
} from '@wordpress/components' ;
2022-12-07 15:52:02 +00:00
import styled from '@emotion/styled' ;
2022-11-11 16:17:49 +00:00
/ * *
* Internal dependencies
* /
import { SettingsCard , SettingsSection } from '../shared-components' ;
import { useSettingsContext } from './settings-context' ;
const GeneralSettingsDescription = ( ) = > (
< >
2024-04-10 13:17:14 +00:00
< h2 > { _x ( 'General' , 'Admin settings' , 'woocommerce' ) } < / h2 >
2022-11-11 16:17:49 +00:00
< p >
{ __ (
2022-12-07 13:39:13 +00:00
'Enable or disable local pickup on your store, and define costs. Local pickup is only available from the block checkout.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
< / p >
< ExternalLink
href = { ` ${ ADMIN_URL } post.php?post= ${ CHECKOUT_PAGE_ID } &action=edit ` }
>
2023-12-12 22:12:36 +00:00
{ __ ( 'View checkout page' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
< / ExternalLink >
< / >
) ;
2022-12-07 15:52:02 +00:00
const StyledNotice = styled ( Notice ) `
margin - left : 0 ;
margin - right : 0 ;
` ;
2022-11-11 16:17:49 +00:00
const GeneralSettings = ( ) = > {
2022-12-07 15:52:02 +00:00
const { settings , setSettingField , readOnlySettings } =
useSettingsContext ( ) ;
2022-11-11 16:17:49 +00:00
const [ showCosts , setShowCosts ] = useState ( ! ! settings . cost ) ;
2023-04-22 09:10:11 +00:00
const shippingCostRequiresAddress = getSetting < boolean > (
'shippingCostRequiresAddress' ,
false
) ;
2022-11-11 16:17:49 +00:00
return (
< SettingsSection Description = { GeneralSettingsDescription } >
< SettingsCard >
2022-12-07 15:52:02 +00:00
{ readOnlySettings . hasLegacyPickup && (
< StyledNotice status = "warning" isDismissible = { false } >
{ createInterpolateElement (
__ (
2024-03-20 14:54:12 +00:00
"By enabling Local Pickup with more valuable features for your store, it's recommended that you remove the legacy Local Pickup option from your <a>shipping zones</a>." ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-12-07 15:52:02 +00:00
) ,
{
a : (
// eslint-disable-next-line jsx-a11y/anchor-has-content
< a
href = { ` ${ ADMIN_URL } admin.php?page=wc-settings&tab=shipping ` }
/ >
) ,
}
) }
< / StyledNotice >
) }
2022-11-11 16:17:49 +00:00
< CheckboxControl
checked = { settings . enabled }
name = "local_pickup_enabled"
onChange = { setSettingField ( 'enabled' ) }
2023-12-12 23:05:20 +00:00
label = { __ ( 'Enable local pickup' , 'woocommerce' ) }
2023-04-22 09:10:11 +00:00
help = {
< span >
{ __ (
'When enabled, local pickup will appear as an option on the block based checkout.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2023-04-22 09:10:11 +00:00
) }
{ shippingCostRequiresAddress ? (
< >
< br / >
{ __ (
'If local pickup is enabled, the "Hide shipping costs until an address is entered" setting will be ignored.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2023-04-22 09:10:11 +00:00
) }
< / >
) : null }
< / span >
}
2022-11-11 16:17:49 +00:00
/ >
< TextControl
2023-12-12 22:12:36 +00:00
label = { __ ( 'Title' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
name = "local_pickup_title"
help = { __ (
'This is the shipping method title shown to customers.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
2024-04-30 12:59:03 +00:00
placeholder = { __ ( 'Pickup' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
value = { settings . title }
onChange = { setSettingField ( 'title' ) }
disabled = { false }
autoComplete = "off"
2022-12-22 13:36:25 +00:00
required = { true }
2022-12-23 12:59:55 +00:00
onInvalid = { (
event : React.InvalidEvent < HTMLInputElement >
) = > {
event . target . setCustomValidity (
__ (
'Local pickup title is required' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-12-23 12:59:55 +00:00
)
) ;
} }
onInput = { (
event : React.ChangeEvent < HTMLInputElement >
) = > {
event . target . setCustomValidity ( '' ) ;
} }
2022-11-11 16:17:49 +00:00
/ >
< CheckboxControl
checked = { showCosts }
onChange = { ( ) = > {
setShowCosts ( ! showCosts ) ;
setSettingField ( 'cost' ) ( '' ) ;
} }
label = { __ (
'Add a price for customers who choose local pickup' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
help = { __ (
'By default, the local pickup shipping method is free.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
/ >
{ showCosts ? (
< >
< TextControl
2023-12-12 23:05:20 +00:00
label = { __ ( 'Cost' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
name = "local_pickup_cost"
help = { __ (
'Optional cost to charge for local pickup.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
2023-12-12 23:05:20 +00:00
placeholder = { __ ( 'Free' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
type = "number"
2022-12-23 12:14:56 +00:00
pattern = "[0-9]+\.?[0-9]*"
2022-12-26 13:42:08 +00:00
min = { 0 }
2022-11-11 16:17:49 +00:00
value = { settings . cost }
onChange = { setSettingField ( 'cost' ) }
disabled = { false }
autoComplete = "off"
/ >
< SelectControl
2023-12-12 23:05:20 +00:00
label = { __ ( 'Taxes' , 'woocommerce' ) }
2022-11-11 16:17:49 +00:00
name = "local_pickup_tax_status"
help = { __ (
'If a cost is defined, this controls if taxes are applied to that cost.' ,
2023-12-12 22:12:36 +00:00
'woocommerce'
2022-11-11 16:17:49 +00:00
) }
options = { [
{
2023-12-12 23:05:20 +00:00
label : __ ( 'Taxable' , 'woocommerce' ) ,
2022-11-11 16:17:49 +00:00
value : 'taxable' ,
} ,
{
2023-12-12 23:05:20 +00:00
label : __ ( 'Not taxable' , 'woocommerce' ) ,
2022-11-11 16:17:49 +00:00
value : 'none' ,
} ,
] }
value = { settings . tax_status }
onChange = { setSettingField ( 'tax_status' ) }
disabled = { false }
/ >
< / >
) : null }
< / SettingsCard >
< / SettingsSection >
) ;
} ;
export default GeneralSettings ;