'no', 'pickup_only' => 'no', 'pickup_text' => __( 'Pickup', 'dayslot' ), 'pickup_note' => __( 'free', 'dayslot' ), 'pickup_address' => '', 'pickup_date_label' => __( 'Pickup date', 'dayslot' ), 'pickup_time_label' => __( 'Pickup time', 'dayslot' ), 'pickup_price_label' => __( 'free', 'dayslot' ), ) ); } ); /** * Where the customer collects the order (Pro: the chosen pickup point). */ function dayslot_pickup_address( $location = '' ) { return (string) apply_filters( 'dayslot_pickup_address', dayslot_get_settings()['pickup_address'], $location ); } function dayslot_pickup_enabled() { return 'yes' === dayslot_get_settings()['pickup_enabled']; } /** * Does the customer choose a time for this way of getting the order? Pickup: only with Pro. */ function dayslot_mode_has_times( $mode ) { return 'pickup' !== $mode || (bool) apply_filters( 'dayslot_pickup_has_times', false ); } add_filter( 'dayslot_modes', function ( $modes ) { if ( ! dayslot_pickup_enabled() ) { return $modes; } $s = dayslot_get_settings(); if ( 'yes' === $s['pickup_only'] ) { return array( 'pickup' => $s['pickup_text'] ); } $modes['pickup'] = $s['pickup_text']; return $modes; } ); add_filter( 'dayslot_mode_note', function ( $note, $mode ) { if ( 'pickup' !== $mode ) { return $note; } $s = dayslot_get_settings(); return trim( $s['pickup_note'] . ( $s['pickup_address'] ? ' · ' . $s['pickup_address'] : '' ), ' ·' ); }, 10, 2 ); add_filter( 'dayslot_capacity_pools', function ( $pools ) { if ( dayslot_pickup_enabled() ) { $pools['pickup:'] = dayslot_ctx( array( 'mode' => 'pickup' ) ); if ( 'yes' === dayslot_get_settings()['pickup_only'] ) { unset( $pools['delivery'] ); } } return $pools; } ); // Pickup places don't count against the delivery limit (Pro sets its own pickup limit). add_filter( 'dayslot_daily_limit', function ( $limit, $ctx ) { return 'pickup' === $ctx['mode'] ? 0 : $limit; }, 5, 2 ); add_filter( 'dayslot_validate_choice', function ( $error, $choice, $ctx ) { if ( ! $error && 'delivery' === $ctx['mode'] && dayslot_pickup_enabled() && 'yes' === dayslot_get_settings()['pickup_only'] ) { return __( 'Please choose pickup.', 'dayslot' ); } return $error; }, 10, 3 ); add_filter( 'dayslot_picker_data', function ( $data ) { if ( dayslot_pickup_enabled() ) { $s = dayslot_get_settings(); $data['modeLabels'] = array( 'pickup' => array( 'date' => $s['pickup_date_label'], 'time' => $s['pickup_time_label'], ), ); if ( ! dayslot_mode_has_times( 'pickup' ) ) { $data['noTimes'] = array( 'pickup' ); } } return $data; } ); add_filter( 'dayslot_order_summary_rows', function ( $rows, $order ) { if ( 'pickup' !== $order->get_meta( DAYSLOT_MODE_META ) ) { return $rows; } $s = dayslot_get_settings(); if ( isset( $rows['dayslot_event_date'] ) ) { $rows['dayslot_event_date']['label'] = $s['pickup_date_label']; } if ( isset( $rows['dayslot_time_slot'] ) ) { $rows['dayslot_time_slot']['label'] = $s['pickup_time_label']; } $address = dayslot_pickup_address( (string) $order->get_meta( DAYSLOT_LOCATION_META ) ); if ( $address ) { $rows['dayslot_pickup'] = array( 'label' => __( 'Pickup address', 'dayslot' ), 'value' => $address, ); } return $rows; }, 10, 2 ); // Settings tab (Pro replaces it with the full one). add_filter( 'dayslot_settings_tabs', function ( $tabs ) { $tabs['pickup'] = array( 'title' => __( 'Pickup', 'dayslot' ), 'render' => 'dayslot_render_pickup_tab', 'sanitize' => 'dayslot_sanitize_pickup_tab', ); return $tabs; }, 5 ); function dayslot_sanitize_pickup_tab( $input, $out ) { foreach ( array( 'pickup_enabled', 'pickup_only' ) as $key ) { $out[ $key ] = ! empty( $input[ $key ] ) ? 'yes' : 'no'; } $out['pickup_address'] = isset( $input['pickup_address'] ) ? sanitize_text_field( $input['pickup_address'] ) : ''; return $out; } /** * The on / off switches and the address (the same in the free and the Pro tab). */ function dayslot_render_pickup_basics( $s, $note ) { ?>