| 1 |
<?php |
| 2 |
/** |
| 3 |
* Optin post meta fields |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
// Exit if accessed directly. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* Meta Boxes setup |
| 14 |
*/ |
| 15 |
class Cartflows_Optin_Meta_Data extends Cartflows_Step_Meta_Base { |
| 16 |
|
| 17 |
|
| 18 |
/** |
| 19 |
* Instance |
| 20 |
* |
| 21 |
* @var $instance |
| 22 |
*/ |
| 23 |
private static $instance; |
| 24 |
|
| 25 |
|
| 26 |
/** |
| 27 |
* Initiator |
| 28 |
*/ |
| 29 |
public static function get_instance() { |
| 30 |
if ( ! isset( self::$instance ) ) { |
| 31 |
self::$instance = new self(); |
| 32 |
} |
| 33 |
|
| 34 |
return self::$instance; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Constructor |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
add_filter( 'cartflows_admin_optin_step_meta_fields', array( $this, 'filter_values' ), 10, 2 ); |
| 42 |
|
| 43 |
// Step API data. |
| 44 |
add_filter( 'cartflows_admin_optin_step_data', array( $this, 'add_optin_step_api_data' ), 10, 2 ); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Add required data to api. |
| 49 |
* |
| 50 |
* @param array $api_data data. |
| 51 |
* @param int $step_id step id. |
| 52 |
* @since 1.10.0 |
| 53 |
*/ |
| 54 |
public function add_optin_step_api_data( $api_data, $step_id ) { |
| 55 |
|
| 56 |
$field_data = $this->custom_fields_data( $step_id ); |
| 57 |
$api_data['custom_fields'] = $field_data; |
| 58 |
$api_data['billing_fields'] = $field_data['billing_fields']; |
| 59 |
return $api_data; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Add custom meta fields |
| 64 |
* |
| 65 |
* @param array $post_id post id. |
| 66 |
*/ |
| 67 |
public function custom_fields_data( $post_id ) { |
| 68 |
|
| 69 |
$billing_fields = $this->get_field_settings( $post_id, 'billing', '' ); |
| 70 |
|
| 71 |
$custom_fields = array( |
| 72 |
'extra_fields' => array( |
| 73 |
'fields' => array( |
| 74 |
'enable-optin-field-editor' => array( |
| 75 |
'type' => 'checkbox', |
| 76 |
'label' => __( 'Enable Custom Field Editor', 'cartflows' ), |
| 77 |
'name' => 'wcf-optin-enable-custom-fields', |
| 78 |
'is_fullwidth' => true, |
| 79 |
), |
| 80 |
), |
| 81 |
), |
| 82 |
'billing_fields' => array( |
| 83 |
'fields' => $billing_fields, |
| 84 |
), |
| 85 |
); |
| 86 |
|
| 87 |
return $custom_fields; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Add custom meta fields |
| 92 |
* |
| 93 |
* @param string $post_id post id. |
| 94 |
* @param array $fields fields. |
| 95 |
* @param array $new_fields new fields. |
| 96 |
*/ |
| 97 |
public function get_field_settings( $post_id, $fields, $new_fields ) { |
| 98 |
|
| 99 |
$ordered_billing_fields = wcf()->options->get_optin_meta_value( $post_id, 'wcf-optin-fields-billing' ); |
| 100 |
|
| 101 |
if ( isset( $ordered_billing_fields ) && ! empty( $ordered_billing_fields ) ) { |
| 102 |
$billing_fields = $ordered_billing_fields; |
| 103 |
|
| 104 |
} else { |
| 105 |
$billing_fields = Cartflows_Helper::get_optin_fields( 'billing', $post_id ); |
| 106 |
} |
| 107 |
|
| 108 |
if ( isset( $billing_fields ) && ! empty( $billing_fields ) ) { |
| 109 |
$data_array = $billing_fields; |
| 110 |
} |
| 111 |
|
| 112 |
if ( isset( $new_fields ) && ! empty( $new_fields ) && is_array( $new_fields ) ) { |
| 113 |
$data_array = $new_fields; |
| 114 |
} |
| 115 |
$field_args = array(); |
| 116 |
|
| 117 |
foreach ( $data_array as $key => $value ) { |
| 118 |
$field_args = $this->prepare_field_arguments( $key, $value, $post_id, $fields ); |
| 119 |
|
| 120 |
foreach ( $field_args as $arg_key => $arg_val ) { |
| 121 |
|
| 122 |
if ( ! in_array( $arg_key, $value, true ) ) { |
| 123 |
|
| 124 |
$data_array[ $key ][ $arg_key ] = $arg_val; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
$data_array[ $key ] = Cartflows_Helper::get_instance()->prepare_custom_field_settings( $data_array[ $key ], $key, $field_args, $fields, 'optin' ); |
| 129 |
} |
| 130 |
|
| 131 |
return $data_array; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Filter checkout values |
| 136 |
* |
| 137 |
* @param array $options options. |
| 138 |
* @param int $step_id post id. |
| 139 |
*/ |
| 140 |
public function filter_values( $options, $step_id ) { |
| 141 |
|
| 142 |
if ( ! empty( $options['wcf-optin-product'][0] ) ) { |
| 143 |
|
| 144 |
$product_id = intval( $options['wcf-optin-product'][0] ); |
| 145 |
$product_obj = wc_get_product( $product_id ); |
| 146 |
|
| 147 |
if ( $product_obj ) { |
| 148 |
$options['wcf-optin-product'] = array( |
| 149 |
'value' => $product_id, |
| 150 |
'label' => $product_obj->get_name() . ' (#' . $product_obj->get_id() . ')', |
| 151 |
'img_url' => get_the_post_thumbnail_url( $product_id ), |
| 152 |
); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if ( isset( $options['wcf-optin-fields-billing'] ) ) { |
| 157 |
$options['wcf-optin-fields-billing'] = $this->get_field_settings( $step_id, 'billing', '' ); |
| 158 |
} |
| 159 |
|
| 160 |
return $options; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Page Header Tabs |
| 165 |
* |
| 166 |
* @param int $step_id Post meta. |
| 167 |
* @param array $options options. |
| 168 |
*/ |
| 169 |
public function get_settings( $step_id, $options = array() ) { |
| 170 |
|
| 171 |
$common_tabs = $this->common_tabs(); |
| 172 |
$add_tabs = array( |
| 173 |
'products' => array( |
| 174 |
'title' => __( 'Products', 'cartflows' ), |
| 175 |
'id' => 'products', |
| 176 |
'class' => '', |
| 177 |
'icon' => 'dashicons-format-aside', |
| 178 |
'priority' => 20, |
| 179 |
), |
| 180 |
'optin_form_fields' => array( |
| 181 |
'title' => __( 'Optin Form', 'cartflows' ), |
| 182 |
'id' => 'optin_form_fields', |
| 183 |
'class' => '', |
| 184 |
'icon' => 'dashicons-format-aside', |
| 185 |
'priority' => 30, |
| 186 |
), |
| 187 |
'settings' => array( |
| 188 |
'title' => __( 'Settings', 'cartflows' ), |
| 189 |
'id' => 'settings', |
| 190 |
'class' => '', |
| 191 |
'icon' => 'dashicons-format-aside', |
| 192 |
'priority' => 70, |
| 193 |
), |
| 194 |
); |
| 195 |
|
| 196 |
$options = $this->get_data( $step_id ); |
| 197 |
|
| 198 |
$tabs = array_merge( $common_tabs, $add_tabs ); |
| 199 |
$settings = $this->get_settings_fields( $step_id ); |
| 200 |
$design_settings = $this->get_design_fields( $step_id ); |
| 201 |
|
| 202 |
$settings_data = array( |
| 203 |
'tabs' => $tabs, |
| 204 |
'settings' => $settings, |
| 205 |
'page_settings' => $this->get_page_settings( $step_id ), |
| 206 |
'design_settings' => $design_settings, |
| 207 |
); |
| 208 |
|
| 209 |
return $settings_data; |
| 210 |
} |
| 211 |
|
| 212 |
/** |
| 213 |
* Get Page Settings Options |
| 214 |
* |
| 215 |
* @param int $step_id Step ID. |
| 216 |
*/ |
| 217 |
public function get_page_settings( $step_id ) { |
| 218 |
|
| 219 |
$options = $this->get_data( $step_id ); |
| 220 |
|
| 221 |
$settings = array( |
| 222 |
'settings' => array( |
| 223 |
'product' => array( |
| 224 |
'priority' => 30, |
| 225 |
'fields' => array( |
| 226 |
'optin-doc' => array( |
| 227 |
'type' => 'doc', |
| 228 |
/* translators: %1$1s: link html start, %2$12: link html end*/ |
| 229 |
'content' => sprintf( __( 'For more information about the CartFlows Optin step please %1$sClick here.%2$s', 'cartflows' ), '<a href="https://cartflows.com/docs/introducing-cartflows-optin-feature/?utm_source=dashboard&utm_medium=free-cartflows&utm_campaign=docs" target="_blank">', '</a>' ), |
| 230 |
), |
| 231 |
), |
| 232 |
|
| 233 |
), |
| 234 |
|
| 235 |
), |
| 236 |
); |
| 237 |
|
| 238 |
return $settings; |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Get design settings data. |
| 243 |
* |
| 244 |
* @param int $step_id Post ID. |
| 245 |
*/ |
| 246 |
public function get_design_fields( $step_id ) { |
| 247 |
|
| 248 |
$options = $this->get_data( $step_id ); |
| 249 |
|
| 250 |
$settings = array( |
| 251 |
'settings' => array( |
| 252 |
'shortcode' => array( |
| 253 |
'title' => __( 'Shortcode', 'cartflows' ), |
| 254 |
'slug' => 'shortcodes', |
| 255 |
'priority' => 10, |
| 256 |
'fields' => array( |
| 257 |
'optin-shortcode' => array( |
| 258 |
'type' => 'text', |
| 259 |
'name' => 'optin-shortcode', |
| 260 |
'label' => __( 'Optin Form', 'cartflows' ), |
| 261 |
'value' => '[cartflows_optin]', |
| 262 |
'help' => esc_html__( 'Add this shortcode to your optin page', 'cartflows' ), |
| 263 |
'readonly' => true, |
| 264 |
'display_align' => 'vertical', |
| 265 |
), |
| 266 |
), |
| 267 |
), |
| 268 |
|
| 269 |
'global' => array( |
| 270 |
'title' => __( 'Global Settings', 'cartflows' ), |
| 271 |
'slug' => 'global_settings', |
| 272 |
'priority' => 20, |
| 273 |
'fields' => array( |
| 274 |
'primary-color' => array( |
| 275 |
'type' => 'color-picker', |
| 276 |
'name' => 'wcf-primary-color', |
| 277 |
'label' => __( 'Primary Color', 'cartflows' ), |
| 278 |
'value' => $options['wcf-primary-color'], |
| 279 |
'withBg' => true, |
| 280 |
), |
| 281 |
'heading-font-family' => array( |
| 282 |
'type' => 'font-family', |
| 283 |
'name' => 'wcf-base-font-family', |
| 284 |
'label' => __( 'Font Family', 'cartflows' ), |
| 285 |
'value' => $options['wcf-base-font-family'], |
| 286 |
'display_align' => 'vertical', |
| 287 |
), |
| 288 |
), |
| 289 |
), |
| 290 |
|
| 291 |
'input-fields' => array( |
| 292 |
'title' => __( 'Input Fields', 'cartflows' ), |
| 293 |
'slug' => 'input_fields', |
| 294 |
'priority' => 30, |
| 295 |
'fields' => array( |
| 296 |
'style' => array( |
| 297 |
'type' => 'select', |
| 298 |
'label' => __( 'Style', 'cartflows' ), |
| 299 |
'name' => 'wcf-input-fields-skins', |
| 300 |
'value' => $options['wcf-input-fields-skins'], |
| 301 |
'display_align' => 'vertical', |
| 302 |
'options' => array( |
| 303 |
array( |
| 304 |
'value' => 'default', |
| 305 |
'label' => esc_html__( 'Default', 'cartflows' ), |
| 306 |
), |
| 307 |
array( |
| 308 |
'value' => 'floating-labels', |
| 309 |
'label' => esc_html__( 'Floating Labels', 'cartflows' ), |
| 310 |
), |
| 311 |
), |
| 312 |
|
| 313 |
), |
| 314 |
'input-font-family' => array( |
| 315 |
'type' => 'font-family', |
| 316 |
'for' => 'wcf-input', |
| 317 |
'label' => esc_html__( 'Font Family', 'cartflows' ), |
| 318 |
'name' => 'wcf-input-font-family', |
| 319 |
'value' => $options['wcf-input-font-family'], |
| 320 |
'font_weight_name' => 'wcf-input-font-weight', |
| 321 |
'font_weight_value' => $options['wcf-input-font-weight'], |
| 322 |
'font_weight_for' => 'wcf-input', |
| 323 |
'display_align' => 'vertical', |
| 324 |
), |
| 325 |
|
| 326 |
'input-font-size' => array( |
| 327 |
'type' => 'select', |
| 328 |
'label' => __( 'Size', 'cartflows' ), |
| 329 |
'name' => 'wcf-input-field-size', |
| 330 |
'value' => $options['wcf-input-field-size'], |
| 331 |
'display_align' => 'vertical', |
| 332 |
'options' => array( |
| 333 |
array( |
| 334 |
'value' => '33px', |
| 335 |
'label' => esc_html__( 'Extra Small', 'cartflows' ), |
| 336 |
), |
| 337 |
array( |
| 338 |
'value' => '38px', |
| 339 |
'label' => esc_html__( 'Small', 'cartflows' ), |
| 340 |
), |
| 341 |
array( |
| 342 |
'value' => '44px', |
| 343 |
'label' => esc_html__( 'Medium', 'cartflows' ), |
| 344 |
), |
| 345 |
array( |
| 346 |
'value' => '58px', |
| 347 |
'label' => esc_html__( 'Large', 'cartflows' ), |
| 348 |
), |
| 349 |
array( |
| 350 |
'value' => '68px', |
| 351 |
'label' => esc_html__( 'Extra Large', 'cartflows' ), |
| 352 |
), |
| 353 |
array( |
| 354 |
'value' => 'custom', |
| 355 |
'label' => esc_html__( 'Custom', 'cartflows' ), |
| 356 |
), |
| 357 |
), |
| 358 |
), |
| 359 |
'input-bottom-space' => array( |
| 360 |
'type' => 'number', |
| 361 |
'label' => __( 'Top Bottom Spacing', 'cartflows' ), |
| 362 |
'name' => 'wcf-field-tb-padding', |
| 363 |
'value' => $options['wcf-field-tb-padding'], |
| 364 |
'display_align' => 'vertical', |
| 365 |
), |
| 366 |
'input-left-space' => array( |
| 367 |
'type' => 'number', |
| 368 |
'label' => __( 'Left Right Spacing', 'cartflows' ), |
| 369 |
'name' => 'wcf-field-lr-padding', |
| 370 |
'value' => $options['wcf-field-lr-padding'], |
| 371 |
'display_align' => 'vertical', |
| 372 |
), |
| 373 |
'input-label-color' => array( |
| 374 |
'type' => 'color-picker', |
| 375 |
'label' => __( 'Label Color', 'cartflows' ), |
| 376 |
'name' => 'wcf-field-label-color', |
| 377 |
'value' => $options['wcf-field-label-color'], |
| 378 |
'withBg' => true, |
| 379 |
), |
| 380 |
'input-text-color' => array( |
| 381 |
'type' => 'color-picker', |
| 382 |
'label' => __( 'Text / Placeholder Color', 'cartflows' ), |
| 383 |
'name' => 'wcf-field-color', |
| 384 |
'value' => $options['wcf-field-color'], |
| 385 |
'withBg' => true, |
| 386 |
), |
| 387 |
'input-bg-color' => array( |
| 388 |
'type' => 'color-picker', |
| 389 |
'label' => __( 'Background Color', 'cartflows' ), |
| 390 |
'name' => 'wcf-field-bg-color', |
| 391 |
'value' => $options['wcf-field-bg-color'], |
| 392 |
'withBg' => true, |
| 393 |
), |
| 394 |
'input-border-color' => array( |
| 395 |
'type' => 'color-picker', |
| 396 |
'label' => __( 'Border Color', 'cartflows' ), |
| 397 |
'name' => 'wcf-field-border-color', |
| 398 |
'value' => $options['wcf-field-border-color'], |
| 399 |
'withBg' => true, |
| 400 |
), |
| 401 |
|
| 402 |
), |
| 403 |
), |
| 404 |
|
| 405 |
'button-options' => array( |
| 406 |
'title' => __( 'Submit Button', 'cartflows' ), |
| 407 |
'slug' => 'button_options', |
| 408 |
'priority' => 40, |
| 409 |
'fields' => array( |
| 410 |
'button-font-size' => array( |
| 411 |
'type' => 'number', |
| 412 |
'label' => __( 'Font Size', 'cartflows' ), |
| 413 |
'name' => 'wcf-submit-font-size', |
| 414 |
'value' => $options['wcf-submit-font-size'], |
| 415 |
'display_align' => 'vertical', |
| 416 |
), |
| 417 |
'button-font-family' => array( |
| 418 |
'type' => 'font-family', |
| 419 |
'for' => 'wcf-button', |
| 420 |
'label' => esc_html__( 'Font Family', 'cartflows' ), |
| 421 |
'name' => 'wcf-button-font-family', |
| 422 |
'value' => $options['wcf-button-font-family'], |
| 423 |
'font_weight_name' => 'wcf-button-font-weight', |
| 424 |
'font_weight_value' => $options['wcf-button-font-weight'], |
| 425 |
'font_weight_for' => 'wcf-button', |
| 426 |
'display_align' => 'vertical', |
| 427 |
|
| 428 |
), |
| 429 |
|
| 430 |
'button-bottom-space' => array( |
| 431 |
'type' => 'select', |
| 432 |
'label' => __( 'Size', 'cartflows' ), |
| 433 |
'name' => 'wcf-submit-button-size', |
| 434 |
'value' => $options['wcf-submit-button-size'], |
| 435 |
'display_align' => 'vertical', |
| 436 |
'options' => array( |
| 437 |
array( |
| 438 |
'value' => '33px', |
| 439 |
'label' => esc_html__( 'Extra Small', 'cartflows' ), |
| 440 |
), |
| 441 |
array( |
| 442 |
'value' => '38px', |
| 443 |
'label' => esc_html__( 'Small', 'cartflows' ), |
| 444 |
), |
| 445 |
array( |
| 446 |
'value' => '44px', |
| 447 |
'label' => esc_html__( 'Medium', 'cartflows' ), |
| 448 |
), |
| 449 |
array( |
| 450 |
'value' => '58px', |
| 451 |
'label' => esc_html__( 'Large', 'cartflows' ), |
| 452 |
), |
| 453 |
array( |
| 454 |
'value' => '68px', |
| 455 |
'label' => esc_html__( 'Extra Large', 'cartflows' ), |
| 456 |
), |
| 457 |
array( |
| 458 |
'value' => 'custom', |
| 459 |
'label' => esc_html__( 'Custom', 'cartflows' ), |
| 460 |
), |
| 461 |
), |
| 462 |
), |
| 463 |
'button-top-space' => array( |
| 464 |
'type' => 'number', |
| 465 |
'label' => __( 'Top Bottom Spacing', 'cartflows' ), |
| 466 |
'name' => 'wcf-submit-tb-padding', |
| 467 |
'value' => $options['wcf-submit-tb-padding'], |
| 468 |
'display_align' => 'vertical', |
| 469 |
), |
| 470 |
'button-left-space' => array( |
| 471 |
'type' => 'number', |
| 472 |
'label' => __( 'Left Right Spacing', 'cartflows' ), |
| 473 |
'name' => 'wcf-submit-lr-padding', |
| 474 |
'value' => $options['wcf-submit-lr-padding'], |
| 475 |
'display_align' => 'vertical', |
| 476 |
), |
| 477 |
'button-text-position' => array( |
| 478 |
'type' => 'select', |
| 479 |
'label' => __( 'Position', 'cartflows' ), |
| 480 |
'name' => 'wcf-submit-button-position', |
| 481 |
'value' => $options['wcf-submit-button-position'], |
| 482 |
'display_align' => 'vertical', |
| 483 |
'options' => array( |
| 484 |
array( |
| 485 |
'value' => 'left', |
| 486 |
'label' => esc_html__( 'Left', 'cartflows' ), |
| 487 |
), |
| 488 |
array( |
| 489 |
'value' => 'center', |
| 490 |
'label' => esc_html__( 'Center', 'cartflows' ), |
| 491 |
), |
| 492 |
array( |
| 493 |
'value' => 'right', |
| 494 |
'label' => esc_html__( 'Right', 'cartflows' ), |
| 495 |
), |
| 496 |
), |
| 497 |
), |
| 498 |
'button-text-color' => array( |
| 499 |
'type' => 'color-picker', |
| 500 |
'label' => __( 'Text Color', 'cartflows' ), |
| 501 |
'name' => 'wcf-submit-color', |
| 502 |
'value' => $options['wcf-submit-color'], |
| 503 |
'withBg' => true, |
| 504 |
), |
| 505 |
'button-text-hover-color' => array( |
| 506 |
'type' => 'color-picker', |
| 507 |
'label' => __( 'Text Hover Color', 'cartflows' ), |
| 508 |
'name' => 'wcf-submit-hover-color', |
| 509 |
'value' => $options['wcf-submit-hover-color'], |
| 510 |
'withBg' => true, |
| 511 |
), |
| 512 |
'button-bg-color' => array( |
| 513 |
'type' => 'color-picker', |
| 514 |
'label' => __( 'Background Color', 'cartflows' ), |
| 515 |
'name' => 'wcf-submit-bg-color', |
| 516 |
'value' => $options['wcf-submit-bg-color'], |
| 517 |
'withBg' => true, |
| 518 |
), |
| 519 |
'button-bg-hover-color' => array( |
| 520 |
'type' => 'color-picker', |
| 521 |
'label' => __( 'Background Hover Color', 'cartflows' ), |
| 522 |
'name' => 'wcf-submit-bg-hover-color', |
| 523 |
'value' => $options['wcf-submit-bg-hover-color'], |
| 524 |
'withBg' => true, |
| 525 |
), |
| 526 |
'button-border-color' => array( |
| 527 |
'type' => 'color-picker', |
| 528 |
'label' => __( 'Border Color', 'cartflows' ), |
| 529 |
'name' => 'wcf-submit-border-color', |
| 530 |
'value' => $options['wcf-submit-border-color'], |
| 531 |
'withBg' => true, |
| 532 |
), |
| 533 |
'button-border-hover-color' => array( |
| 534 |
'type' => 'color-picker', |
| 535 |
'label' => __( 'Border Hover Color', 'cartflows' ), |
| 536 |
'name' => 'wcf-submit-border-hover-color', |
| 537 |
'value' => $options['wcf-submit-border-hover-color'], |
| 538 |
'withBg' => true, |
| 539 |
), |
| 540 |
), |
| 541 |
|
| 542 |
), |
| 543 |
), |
| 544 |
); |
| 545 |
|
| 546 |
return $settings; |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Get settings data. |
| 551 |
* |
| 552 |
* @param int $step_id Post ID. |
| 553 |
*/ |
| 554 |
public function get_settings_fields( $step_id ) { |
| 555 |
|
| 556 |
$options = $this->get_data( $step_id ); |
| 557 |
|
| 558 |
// Determine whether to show CodeMirror editors or the legacy textarea. |
| 559 |
$show_code_editor = \CartflowsAdmin\AdminCore\Inc\AdminHelper::should_show_code_editor(); |
| 560 |
|
| 561 |
$general_fields = array( |
| 562 |
'slug' => array( |
| 563 |
'type' => 'text', |
| 564 |
'name' => 'step_post_name', |
| 565 |
'label' => __( 'Step Slug', 'cartflows' ), |
| 566 |
'value' => get_post_field( 'post_name' ), |
| 567 |
'display_align' => 'vertical', |
| 568 |
), |
| 569 |
'wcf-disable-step-toggle' => array( |
| 570 |
'type' => 'toggle', |
| 571 |
'label' => __( 'Disable Step', 'cartflows' ), |
| 572 |
'name' => 'wcf-disable-step', |
| 573 |
'value' => $options['wcf-disable-step'], |
| 574 |
'tooltip' => __( 'Turn this on to disable the step', 'cartflows' ), |
| 575 |
'is_fullwidth' => true, |
| 576 |
), |
| 577 |
); |
| 578 |
|
| 579 |
if ( $show_code_editor ) { |
| 580 |
// Migration completed: show separate JS and CSS CodeMirror editors. |
| 581 |
$general_fields['wcf-optin-custom-js'] = array( |
| 582 |
'type' => 'code', |
| 583 |
'label' => __( 'Custom JavaScript', 'cartflows' ), |
| 584 |
'name' => 'wcf-step-custom-js', |
| 585 |
'value' => $options['wcf-step-custom-js'], |
| 586 |
'display_align' => 'vertical', |
| 587 |
'language' => 'javascript', |
| 588 |
'tooltip' => __( 'Add your own custom JavaScript code here. Do not include script tags.', 'cartflows' ), |
| 589 |
); |
| 590 |
$general_fields['wcf-optin-custom-css'] = array( |
| 591 |
'type' => 'code', |
| 592 |
'label' => __( 'Custom CSS', 'cartflows' ), |
| 593 |
'name' => 'wcf-step-custom-css', |
| 594 |
'value' => $options['wcf-step-custom-css'], |
| 595 |
'display_align' => 'vertical', |
| 596 |
'language' => 'css', |
| 597 |
'tooltip' => __( 'Add your own custom CSS code here. Do not include style tags.', 'cartflows' ), |
| 598 |
); |
| 599 |
} else { |
| 600 |
// Migration not completed: show the legacy combined textarea. |
| 601 |
$general_fields['wcf-optin-custom-script'] = array( |
| 602 |
'type' => 'textarea', |
| 603 |
'label' => __( 'Custom Script', 'cartflows' ), |
| 604 |
'name' => 'wcf-custom-script', |
| 605 |
'value' => $options['wcf-custom-script'], |
| 606 |
'tooltip' => __( 'Add your own custom code here. If you\'re adding CSS, make sure to wrap it inside <style> tags.', 'cartflows' ), |
| 607 |
'display_align' => 'vertical', |
| 608 |
); |
| 609 |
} |
| 610 |
|
| 611 |
$settings = array( |
| 612 |
'settings' => array( |
| 613 |
'general' => array( |
| 614 |
'title' => __( 'General', 'cartflows' ), |
| 615 |
'slug' => 'general', |
| 616 |
'priority' => 20, |
| 617 |
'fields' => $general_fields, |
| 618 |
), |
| 619 |
|
| 620 |
'settings' => array( |
| 621 |
'title' => __( 'Optin Settings', 'cartflows' ), |
| 622 |
'slug' => 'fields_settings', |
| 623 |
'priority' => 10, |
| 624 |
'fields' => array( |
| 625 |
'button-text' => array( |
| 626 |
'type' => 'text', |
| 627 |
'label' => __( 'Button Text', 'cartflows' ), |
| 628 |
'name' => 'wcf-submit-button-text', |
| 629 |
'value' => $options['wcf-submit-button-text'], |
| 630 |
'placeholder' => __( 'Submit', 'cartflows' ), |
| 631 |
'display_align' => 'vertical', |
| 632 |
), |
| 633 |
'optin-pass-fields' => array( |
| 634 |
'type' => 'toggle', |
| 635 |
'label' => __( 'Pass Fields as URL Parameters', 'cartflows' ), |
| 636 |
'name' => 'wcf-optin-pass-fields', |
| 637 |
'value' => $options['wcf-optin-pass-fields'], |
| 638 |
'help' => __( 'You can pass specific fields from the form to next step as URL query parameters.', 'cartflows' ), |
| 639 |
'is_fullwidth' => true, |
| 640 |
), |
| 641 |
'optin-pass-specific-fields' => array( |
| 642 |
'type' => 'text', |
| 643 |
'label' => __( 'Enter form field', 'cartflows' ), |
| 644 |
'name' => 'wcf-optin-pass-specific-fields', |
| 645 |
'value' => $options['wcf-optin-pass-specific-fields'], |
| 646 |
'help' => __( 'Enter comma seprated field name. E.g. first_name, last_name', 'cartflows' ), |
| 647 |
'placeholder' => __( 'Fields to pass, separated by commas', 'cartflows' ), |
| 648 |
/* translators: %s: link */ |
| 649 |
'desc' => sprintf( __( 'You can pass field value as a URL parameter to the next step. %1$sLearn More >>%2$s', 'cartflows' ), '<a href="https://cartflows.com/docs/pass-variable-as-query-parameters-to-url/?utm_source=dashboard&utm_medium=free-cartflows&utm_campaign=docs" target="_blank">', '</a>' ), |
| 650 |
'display_align' => 'vertical', |
| 651 |
'conditions' => array( |
| 652 |
'fields' => array( |
| 653 |
array( |
| 654 |
'name' => 'wcf-optin-pass-fields', |
| 655 |
'operator' => '===', |
| 656 |
'value' => 'yes', |
| 657 |
), |
| 658 |
), |
| 659 |
), |
| 660 |
), |
| 661 |
|
| 662 |
), |
| 663 |
), |
| 664 |
), |
| 665 |
); |
| 666 |
|
| 667 |
if ( wcf_show_deprecated_step_notes() ) { |
| 668 |
$settings['settings']['general']['fields']['step-note'] = array( |
| 669 |
'type' => 'textarea', |
| 670 |
'name' => 'wcf-step-note', |
| 671 |
'label' => __( 'Step Note', 'cartflows' ), |
| 672 |
'value' => get_post_meta( $step_id, 'wcf-step-note', true ), |
| 673 |
'rows' => 2, |
| 674 |
'cols' => 38, |
| 675 |
'display_align' => 'vertical', |
| 676 |
); |
| 677 |
} |
| 678 |
|
| 679 |
return $settings; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
/** |
| 684 |
* Fetch default width of checkout fields by key. |
| 685 |
* |
| 686 |
* @param string $field_key field key. |
| 687 |
* @return int |
| 688 |
*/ |
| 689 |
public function get_default_optin_field_width( $field_key ) { |
| 690 |
|
| 691 |
$default_width = 100; |
| 692 |
switch ( $field_key ) { |
| 693 |
case 'billing_first_name': |
| 694 |
case 'billing_last_name': |
| 695 |
$default_width = 50; |
| 696 |
break; |
| 697 |
default: |
| 698 |
$default_width = 100; |
| 699 |
break; |
| 700 |
} |
| 701 |
|
| 702 |
return $default_width; |
| 703 |
} |
| 704 |
|
| 705 |
/** |
| 706 |
* Prepare HTML data for billing and shipping fields. |
| 707 |
* |
| 708 |
* @param string $field checkout field key. |
| 709 |
* @param array $field_data checkout field object. |
| 710 |
* @param integer $post_id chcekout post id. |
| 711 |
* @param string $type checkout field type. |
| 712 |
* @return array |
| 713 |
*/ |
| 714 |
public function prepare_field_arguments( $field, $field_data, $post_id, $type ) { |
| 715 |
|
| 716 |
$field_name = ''; |
| 717 |
if ( isset( $field_data['label'] ) ) { |
| 718 |
$field_name = $field_data['label']; |
| 719 |
} |
| 720 |
|
| 721 |
if ( isset( $field_data['width'] ) ) { |
| 722 |
$width = $field_data['width']; |
| 723 |
} else { |
| 724 |
$width = $this->get_default_optin_field_width( $field ); |
| 725 |
} |
| 726 |
|
| 727 |
if ( isset( $field_data['enabled'] ) ) { |
| 728 |
$is_enabled = true === $field_data['enabled'] ? 'yes' : 'no'; |
| 729 |
} else { |
| 730 |
$is_enabled = 'yes'; |
| 731 |
} |
| 732 |
|
| 733 |
$field_args = array( |
| 734 |
'type' => ( isset( $field_data['type'] ) && ! empty( $field_data['type'] ) ) ? $field_data['type'] : '', |
| 735 |
'label' => $field_name, |
| 736 |
'name' => 'wcf-' . $field, |
| 737 |
'key' => $field, |
| 738 |
'placeholder' => isset( $field_data['placeholder'] ) ? $field_data['placeholder'] : '', |
| 739 |
'min' => isset( $field_data['min'] ) ? $field_data['min'] : '', |
| 740 |
'max' => isset( $field_data['max'] ) ? $field_data['max'] : '', |
| 741 |
'width' => $width, |
| 742 |
'enabled' => $is_enabled, |
| 743 |
'after' => 'Enable', |
| 744 |
'section' => $type, |
| 745 |
'custom' => isset( $field_data['custom'] ) ? $field_data['custom'] : false, |
| 746 |
'custom_attributes' => isset( $field_data['custom_attributes'] ) ? wc_clean( $field_data['custom_attributes'] ) : array(), |
| 747 |
'default' => isset( $field_data['default'] ) ? $field_data['default'] : '', |
| 748 |
'required' => ( isset( $field_data['required'] ) && true == $field_data['required'] ) ? 'yes' : 'no', |
| 749 |
'optimized' => ( isset( $field_data['optimized'] ) && true == $field_data['optimized'] ) ? 'yes' : 'no', |
| 750 |
'options' => ( isset( $field_data['options'] ) && ! empty( $field_data['options'] ) && is_array( $field_data['options'] ) ) ? implode( '|', $field_data['options'] ) : $field_data['options'], |
| 751 |
'show_in_email' => ( isset( $field_data['show_in_email'] ) && true == $field_data['show_in_email'] ) ? 'yes' : 'no', |
| 752 |
); |
| 753 |
|
| 754 |
return $field_args; |
| 755 |
} |
| 756 |
|
| 757 |
/** |
| 758 |
* Get data. |
| 759 |
* |
| 760 |
* @param int $step_id Post ID. |
| 761 |
*/ |
| 762 |
public function get_data( $step_id ) { |
| 763 |
|
| 764 |
$optin_data = array(); |
| 765 |
|
| 766 |
// Stored data. |
| 767 |
$stored_meta = get_post_meta( $step_id ); |
| 768 |
|
| 769 |
// Default. |
| 770 |
$default_data = self::get_meta_option( $step_id ); |
| 771 |
|
| 772 |
// Set stored and override defaults. |
| 773 |
foreach ( $default_data as $key => $value ) { |
| 774 |
if ( array_key_exists( $key, $stored_meta ) ) { |
| 775 |
$optin_data[ $key ] = ( isset( $stored_meta[ $key ][0] ) ) ? maybe_unserialize( $stored_meta[ $key ][0] ) : ''; |
| 776 |
} else { |
| 777 |
$optin_data[ $key ] = ( isset( $default_data[ $key ]['default'] ) ) ? $default_data[ $key ]['default'] : ''; |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
return $optin_data; |
| 782 |
} |
| 783 |
|
| 784 |
/** |
| 785 |
* Get meta. |
| 786 |
* |
| 787 |
* @param int $post_id Post ID. |
| 788 |
*/ |
| 789 |
public static function get_meta_option( $post_id ) { |
| 790 |
|
| 791 |
$meta_option = wcf()->options->get_optin_fields( $post_id ); |
| 792 |
|
| 793 |
return $meta_option; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
/** |
| 798 |
* Kicking this off by calling 'get_instance()' method. |
| 799 |
*/ |
| 800 |
Cartflows_Optin_Meta_Data::get_instance(); |
| 801 |
|