Force cart and block-cart button loctions when AXO is active (3091)

This commit is contained in:
Daniel Dudzic 2024-05-15 14:42:40 +02:00
parent 2aeeb78a16
commit 41ac4197ee
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
6 changed files with 94 additions and 2 deletions

View file

@ -61,8 +61,13 @@ $background-ident-color: #fbfbfb;
border: 1px solid #c3c4c7;
border-left-width: 4px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
margin: 5px 15px 2px;
margin: 5px 15px 2px 0;
padding: 1px 12px;
p, .form-table td & p {
margin-top: 4px;
margin-bottom: 4px;
}
}
.ppcp-notice-warning {

View file

@ -60,6 +60,16 @@ return function ( ContainerInterface $container, array $fields ): array {
'</a>'
),
),
'smart_button_locations_notice' => array(
'heading' => '',
'html' => $container->get( 'axo.smart-button-location-notice' ),
'type' => 'ppcp-html',
'classes' => array(),
'class' => array(),
'screens' => array( State::STATE_START, State::STATE_ONBOARDED ),
'requirements' => array(),
'gateway' => 'paypal',
),
'smart_button_locations' => array(
'title' => __( 'Smart Button Locations', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-multiselect',

View file

@ -729,4 +729,28 @@ class SettingsListener {
}
}
/**
* Filter settings based on a condition.
*
* @param bool $condition The condition.
* @param string $setting_slug The setting slug.
* @param callable $filter_function The filter function.
* @param bool $persist Whether to persist the settings.
*/
public function filter_settings( bool $condition, string $setting_slug, callable $filter_function, bool $persist = true ): void {
if ( ! $this->is_valid_site_request() || State::STATE_ONBOARDED !== $this->state->current_state() ) {
return;
}
$existing_setting_value = $this->settings->has( $setting_slug ) ? $this->settings->get( $setting_slug ) : null;
if ( $condition ) {
$new_setting_value = $filter_function( $existing_setting_value );
$this->settings->set( $setting_slug, $new_setting_value );
if ( $persist ) {
$this->settings->persist();
}
}
}
}