| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Helper; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
|
| 8 |
class WooLatepoint { |
| 9 |
protected static $instance = null; |
| 10 |
public static function getInstance() { |
| 11 |
if ( null == self::$instance ) { |
| 12 |
self::$instance = new self(); |
| 13 |
} |
| 14 |
return self::$instance; |
| 15 |
} |
| 16 |
private function __construct() {} |
| 17 |
public static function wooLatepointBookingDetail( $args, $order, $sent_to_admin ) { |
| 18 |
if ( null === $order ) { |
| 19 |
ob_start(); |
| 20 |
$path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/LatePoint/SampleTemplate/latepoint-booking-detail.php'; |
| 21 |
include $path; |
| 22 |
$html = ob_get_contents(); |
| 23 |
ob_end_clean(); |
| 24 |
return $html; |
| 25 |
} else { |
| 26 |
if ( method_exists( $order, 'get_items' ) ) { |
| 27 |
$order_items = $order->get_items(); |
| 28 |
ob_start(); |
| 29 |
$path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/LatePoint/latepoint-booking-detail.php'; |
| 30 |
include $path; |
| 31 |
$html = ob_get_contents(); |
| 32 |
ob_end_clean(); |
| 33 |
return $html; |
| 34 |
} else { |
| 35 |
// Handle error: $order object doesn't have get_items() method |
| 36 |
return null; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public static function wooLatepointCalendarStartDate( $args, $order, $sent_to_admin ) { |
| 42 |
if ( null === $order ) { |
| 43 |
$list_calendar_start_date = '<ul class="yaymail-woo-latepoint-list-calendar-start-date">'; |
| 44 |
$list_calendar_start_date .= '<li>' . date_i18n( wc_date_format(), current_time( 'Y-m-d' ) ) . '</li>'; |
| 45 |
$list_calendar_start_date .= '</ul>'; |
| 46 |
return $list_calendar_start_date; |
| 47 |
} else { |
| 48 |
if ( method_exists( $order, 'get_items' ) ) { |
| 49 |
$order_items = $order->get_items(); |
| 50 |
$list_calendar_start_date = '<ul class="yaymail-woo-latepoint-list-calendar-start-date">'; |
| 51 |
foreach ( $order_items as $item ) { |
| 52 |
$data = wc_get_order_item_meta( $item->get_id(), TECHXELA_WOOCOMMERCE_LATEPOINT_ORDER_ITEM_META_KEY ); |
| 53 |
$calendar_start_date = isset( $data['restrictions']['calendar_start_date'] ) ? $data['restrictions']['calendar_start_date'] : null; |
| 54 |
if ( empty( $calendar_start_date ) ) { |
| 55 |
return null; |
| 56 |
} |
| 57 |
$list_calendar_start_date .= '<li>' . date_i18n( wc_date_format(), strtotime( $calendar_start_date ) ) . '</li>'; |
| 58 |
} |
| 59 |
$list_calendar_start_date .= '</ul>'; |
| 60 |
return $list_calendar_start_date; |
| 61 |
} else { |
| 62 |
// Handle error: $order object doesn't have get_items() method |
| 63 |
return null; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
//WooCommerce for LatePoint |
| 69 |
public static function wooLatepointSelectedTotalAttendees( $args, $order, $sent_to_admin ) { |
| 70 |
if ( null === $order ) { |
| 71 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_total_attendies">'; |
| 72 |
$list_attributes .= '<li>' . 5 . '</li>'; |
| 73 |
$list_attributes .= '</ul>'; |
| 74 |
return $list_attributes; |
| 75 |
} else { |
| 76 |
if ( method_exists( $order, 'get_items' ) ) { |
| 77 |
$order_items = $order->get_items(); |
| 78 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_total_attendies' ); |
| 79 |
return $valueRestrictionsAttributes; |
| 80 |
} else { |
| 81 |
// Handle error: $order object doesn't have get_items() method |
| 82 |
return null; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
public static function wooLatepointCaption( $args, $order, $sent_to_admin ) { |
| 88 |
if ( null === $order ) { |
| 89 |
$list_attributes = '<ul class="yaymail-woo-latepoint-caption">'; |
| 90 |
$list_attributes .= '<li>caption</li>'; |
| 91 |
$list_attributes .= '</ul>'; |
| 92 |
return $list_attributes; |
| 93 |
} else { |
| 94 |
if ( method_exists( $order, 'get_items' ) ) { |
| 95 |
$order_items = $order->get_items(); |
| 96 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'caption' ); |
| 97 |
return $valueRestrictionsAttributes; |
| 98 |
} else { |
| 99 |
// Handle error: $order object doesn't have get_items() method |
| 100 |
return null; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
public static function wooLatepointBgColor( $args, $order, $sent_to_admin ) { |
| 106 |
if ( null === $order ) { |
| 107 |
$list_attributes = '<ul class="yaymail-woo-latepoint-bg_color">'; |
| 108 |
$list_attributes .= '<li>bg_color</li>'; |
| 109 |
$list_attributes .= '</ul>'; |
| 110 |
return $list_attributes; |
| 111 |
} else { |
| 112 |
if ( method_exists( $order, 'get_items' ) ) { |
| 113 |
$order_items = $order->get_items(); |
| 114 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'bg_color' ); |
| 115 |
return $valueRestrictionsAttributes; |
| 116 |
} else { |
| 117 |
// Handle error: $order object doesn't have get_items() method |
| 118 |
return null; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
public static function wooLatepointTextColor( $args, $order, $sent_to_admin ) { |
| 123 |
if ( null === $order ) { |
| 124 |
$list_attributes = '<ul class="yaymail-woo-latepoint-text_color">'; |
| 125 |
$list_attributes .= '<li>text_color</li>'; |
| 126 |
$list_attributes .= '</ul>'; |
| 127 |
return $list_attributes; |
| 128 |
} else { |
| 129 |
if ( method_exists( $order, 'get_items' ) ) { |
| 130 |
$order_items = $order->get_items(); |
| 131 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'text_color' ); |
| 132 |
return $valueRestrictionsAttributes; |
| 133 |
} else { |
| 134 |
// Handle error: $order object doesn't have get_items() method |
| 135 |
return null; |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
public static function wooLatepointFontSize( $args, $order, $sent_to_admin ) { |
| 140 |
if ( null === $order ) { |
| 141 |
$list_attributes = '<ul class="yaymail-woo-latepoint-font_size">'; |
| 142 |
$list_attributes .= '<li>font_size</li>'; |
| 143 |
$list_attributes .= '</ul>'; |
| 144 |
return $list_attributes; |
| 145 |
} else { |
| 146 |
if ( method_exists( $order, 'get_items' ) ) { |
| 147 |
$order_items = $order->get_items(); |
| 148 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'font_size' ); |
| 149 |
return $valueRestrictionsAttributes; |
| 150 |
} else { |
| 151 |
// Handle error: $order object doesn't have get_items() method |
| 152 |
return null; |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
public static function wooLatepointBorder( $args, $order, $sent_to_admin ) { |
| 157 |
if ( null === $order ) { |
| 158 |
$list_attributes = '<ul class="yaymail-woo-latepoint-border">'; |
| 159 |
$list_attributes .= '<li>border</li>'; |
| 160 |
$list_attributes .= '</ul>'; |
| 161 |
return $list_attributes; |
| 162 |
} else { |
| 163 |
if ( method_exists( $order, 'get_items' ) ) { |
| 164 |
$order_items = $order->get_items(); |
| 165 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'border' ); |
| 166 |
return $valueRestrictionsAttributes; |
| 167 |
} else { |
| 168 |
// Handle error: $order object doesn't have get_items() method |
| 169 |
return null; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
public static function wooLatepointBorderRadius( $args, $order, $sent_to_admin ) { |
| 174 |
if ( null === $order ) { |
| 175 |
$list_attributes = '<ul class="yaymail-woo-latepoint-border_radius">'; |
| 176 |
$list_attributes .= '<li>border_radius</li>'; |
| 177 |
$list_attributes .= '</ul>'; |
| 178 |
return $list_attributes; |
| 179 |
} else { |
| 180 |
if ( method_exists( $order, 'get_items' ) ) { |
| 181 |
$order_items = $order->get_items(); |
| 182 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'border_radius' ); |
| 183 |
return $valueRestrictionsAttributes; |
| 184 |
} else { |
| 185 |
// Handle error: $order object doesn't have get_items() method |
| 186 |
return null; |
| 187 |
} |
| 188 |
} |
| 189 |
} |
| 190 |
public static function wooLatepointMargin( $args, $order, $sent_to_admin ) { |
| 191 |
if ( null === $order ) { |
| 192 |
$list_attributes = '<ul class="yaymail-woo-latepoint-margin">'; |
| 193 |
$list_attributes .= '<li>margin</li>'; |
| 194 |
$list_attributes .= '</ul>'; |
| 195 |
return $list_attributes; |
| 196 |
} else { |
| 197 |
if ( method_exists( $order, 'get_items' ) ) { |
| 198 |
$order_items = $order->get_items(); |
| 199 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'margin' ); |
| 200 |
return $valueRestrictionsAttributes; |
| 201 |
} else { |
| 202 |
// Handle error: $order object doesn't have get_items() method |
| 203 |
return null; |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
public static function wooLatepointPaddings( $args, $order, $sent_to_admin ) { |
| 208 |
if ( null === $order ) { |
| 209 |
$list_attributes = '<ul class="yaymail-woo-latepoint-padding">'; |
| 210 |
$list_attributes .= '<li>padding</li>'; |
| 211 |
$list_attributes .= '</ul>'; |
| 212 |
return $list_attributes; |
| 213 |
} else { |
| 214 |
if ( method_exists( $order, 'get_items' ) ) { |
| 215 |
$order_items = $order->get_items(); |
| 216 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'padding' ); |
| 217 |
return $valueRestrictionsAttributes; |
| 218 |
} else { |
| 219 |
// Handle error: $order object doesn't have get_items() method |
| 220 |
return null; |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
public static function wooLatepointCss( $args, $order, $sent_to_admin ) { |
| 225 |
if ( null === $order ) { |
| 226 |
$list_attributes = '<ul class="yaymail-woo-latepoint-css">'; |
| 227 |
$list_attributes .= '<li>css</li>'; |
| 228 |
$list_attributes .= '</ul>'; |
| 229 |
return $list_attributes; |
| 230 |
} else { |
| 231 |
if ( method_exists( $order, 'get_items' ) ) { |
| 232 |
$order_items = $order->get_items(); |
| 233 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'css' ); |
| 234 |
return $valueRestrictionsAttributes; |
| 235 |
} else { |
| 236 |
// Handle error: $order object doesn't have get_items() method |
| 237 |
return null; |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
public static function wooLatepointShowLocations( $args, $order, $sent_to_admin ) { |
| 242 |
if ( null === $order ) { |
| 243 |
$list_attributes = '<ul class="yaymail-woo-latepoint-show_locations">'; |
| 244 |
$list_attributes .= '<li>show_locations</li>'; |
| 245 |
$list_attributes .= '</ul>'; |
| 246 |
return $list_attributes; |
| 247 |
} else { |
| 248 |
if ( method_exists( $order, 'get_items' ) ) { |
| 249 |
$order_items = $order->get_items(); |
| 250 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'show_locations' ); |
| 251 |
return $valueRestrictionsAttributes; |
| 252 |
} else { |
| 253 |
// Handle error: $order object doesn't have get_items() method |
| 254 |
return null; |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
public static function wooLatepointShowAgents( $args, $order, $sent_to_admin ) { |
| 259 |
if ( null === $order ) { |
| 260 |
$list_attributes = '<ul class="yaymail-woo-latepoint-show_agents">'; |
| 261 |
$list_attributes .= '<li>show_agents</li>'; |
| 262 |
$list_attributes .= '</ul>'; |
| 263 |
return $list_attributes; |
| 264 |
} else { |
| 265 |
if ( method_exists( $order, 'get_items' ) ) { |
| 266 |
$order_items = $order->get_items(); |
| 267 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'show_agents' ); |
| 268 |
return $valueRestrictionsAttributes; |
| 269 |
} else { |
| 270 |
// Handle error: $order object doesn't have get_items() method |
| 271 |
return null; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
public static function wooLatepointShowServices( $args, $order, $sent_to_admin ) { |
| 276 |
if ( null === $order ) { |
| 277 |
$list_attributes = '<ul class="yaymail-woo-latepoint-show_services">'; |
| 278 |
$list_attributes .= '<li>show_services</li>'; |
| 279 |
$list_attributes .= '</ul>'; |
| 280 |
return $list_attributes; |
| 281 |
} else { |
| 282 |
if ( method_exists( $order, 'get_items' ) ) { |
| 283 |
$order_items = $order->get_items(); |
| 284 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'show_services' ); |
| 285 |
return $valueRestrictionsAttributes; |
| 286 |
} else { |
| 287 |
// Handle error: $order object doesn't have get_items() method |
| 288 |
return null; |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
public static function wooLatepointShowServiceCategories( $args, $order, $sent_to_admin ) { |
| 293 |
if ( null === $order ) { |
| 294 |
$list_attributes = '<ul class="yaymail-woo-latepoint-show_service_categories">'; |
| 295 |
$list_attributes .= '<li>show_service_categories</li>'; |
| 296 |
$list_attributes .= '</ul>'; |
| 297 |
return $list_attributes; |
| 298 |
} else { |
| 299 |
if ( method_exists( $order, 'get_items' ) ) { |
| 300 |
$order_items = $order->get_items(); |
| 301 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'show_service_categories' ); |
| 302 |
return $valueRestrictionsAttributes; |
| 303 |
} else { |
| 304 |
// Handle error: $order object doesn't have get_items() method |
| 305 |
return null; |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
public static function wooLatepointSelectedLocation( $args, $order, $sent_to_admin ) { |
| 310 |
if ( null === $order ) { |
| 311 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_location">'; |
| 312 |
$list_attributes .= '<li>selected_location</li>'; |
| 313 |
$list_attributes .= '</ul>'; |
| 314 |
return $list_attributes; |
| 315 |
} else { |
| 316 |
if ( method_exists( $order, 'get_items' ) ) { |
| 317 |
$order_items = $order->get_items(); |
| 318 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_location' ); |
| 319 |
return $valueRestrictionsAttributes; |
| 320 |
} else { |
| 321 |
// Handle error: $order object doesn't have get_items() method |
| 322 |
return null; |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
public static function wooLatepointSelectedAgent( $args, $order, $sent_to_admin ) { |
| 327 |
if ( null === $order ) { |
| 328 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_agent">'; |
| 329 |
$list_attributes .= '<li>selected_agent</li>'; |
| 330 |
$list_attributes .= '</ul>'; |
| 331 |
return $list_attributes; |
| 332 |
} else { |
| 333 |
if ( method_exists( $order, 'get_items' ) ) { |
| 334 |
$order_items = $order->get_items(); |
| 335 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_agent' ); |
| 336 |
return $valueRestrictionsAttributes; |
| 337 |
} else { |
| 338 |
// Handle error: $order object doesn't have get_items() method |
| 339 |
return null; |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
public static function wooLatepointSelectedService( $args, $order, $sent_to_admin ) { |
| 344 |
if ( null === $order ) { |
| 345 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_service">'; |
| 346 |
$list_attributes .= '<li>' . 5 . '</li>'; |
| 347 |
$list_attributes .= '</ul>'; |
| 348 |
return $list_attributes; |
| 349 |
} else { |
| 350 |
if ( method_exists( $order, 'get_items' ) ) { |
| 351 |
$order_items = $order->get_items(); |
| 352 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_service' ); |
| 353 |
return $valueRestrictionsAttributes; |
| 354 |
} else { |
| 355 |
// Handle error: $order object doesn't have get_items() method |
| 356 |
return null; |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
public static function wooLatepointSelectedServiceCategory( $args, $order, $sent_to_admin ) { |
| 361 |
if ( null === $order ) { |
| 362 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_service_category">'; |
| 363 |
$list_attributes .= '<li>' . 5 . '</li>'; |
| 364 |
$list_attributes .= '</ul>'; |
| 365 |
return $list_attributes; |
| 366 |
} else { |
| 367 |
if ( method_exists( $order, 'get_items' ) ) { |
| 368 |
$order_items = $order->get_items(); |
| 369 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_service_category' ); |
| 370 |
return $valueRestrictionsAttributes; |
| 371 |
} else { |
| 372 |
// Handle error: $order object doesn't have get_items() method |
| 373 |
return null; |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
public static function wooLatepointSelectedDuration( $args, $order, $sent_to_admin ) { |
| 378 |
if ( null === $order ) { |
| 379 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected_duration">'; |
| 380 |
$list_attributes .= '<li>' . 5 . '</li>'; |
| 381 |
$list_attributes .= '</ul>'; |
| 382 |
return $list_attributes; |
| 383 |
} else { |
| 384 |
if ( method_exists( $order, 'get_items' ) ) { |
| 385 |
$order_items = $order->get_items(); |
| 386 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'selected_duration' ); |
| 387 |
return $valueRestrictionsAttributes; |
| 388 |
} else { |
| 389 |
// Handle error: $order object doesn't have get_items() method |
| 390 |
return null; |
| 391 |
} |
| 392 |
} |
| 393 |
} |
| 394 |
public static function wooLatepointHideSidePanel( $args, $order, $sent_to_admin ) { |
| 395 |
if ( null === $order ) { |
| 396 |
$list_attributes = '<ul class="yaymail-woo-latepoint-hide_side_panel">'; |
| 397 |
$list_attributes .= '<li>hide_side_panel</li>'; |
| 398 |
$list_attributes .= '</ul>'; |
| 399 |
return $list_attributes; |
| 400 |
} else { |
| 401 |
if ( method_exists( $order, 'get_items' ) ) { |
| 402 |
$order_items = $order->get_items(); |
| 403 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'hide_side_panel' ); |
| 404 |
return $valueRestrictionsAttributes; |
| 405 |
} else { |
| 406 |
// Handle error: $order object doesn't have get_items() method |
| 407 |
return null; |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
public static function wooLatepointHideSummary( $args, $order, $sent_to_admin ) { |
| 412 |
if ( null === $order ) { |
| 413 |
$list_attributes = '<ul class="yaymail-woo-latepoint-hide_summary">'; |
| 414 |
$list_attributes .= '<li>hide_summary</li>'; |
| 415 |
$list_attributes .= '</ul>'; |
| 416 |
return $list_attributes; |
| 417 |
} else { |
| 418 |
if ( method_exists( $order, 'get_items' ) ) { |
| 419 |
$order_items = $order->get_items(); |
| 420 |
$valueRestrictionsAttributes = self::getRestrictionsAttributes( $order_items, 'hide_summary' ); |
| 421 |
return $valueRestrictionsAttributes; |
| 422 |
} else { |
| 423 |
// Handle error: $order object doesn't have get_items() method |
| 424 |
return null; |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
/** |
| 429 |
* It takes the order items and the value of the attribute you want to display, and returns a list of |
| 430 |
* the attributes |
| 431 |
* |
| 432 |
* @param order_items This is the array of order items. |
| 433 |
* @param value The name of the attribute you want to display. |
| 434 |
* |
| 435 |
* @return A list of attributes. |
| 436 |
*/ |
| 437 |
public static function getRestrictionsAttributes( $order_items, $value ) { |
| 438 |
$list_attributes = '<ul class="yaymail-woo-latepoint-selected-' . $value . '">'; |
| 439 |
$attributes = $value; |
| 440 |
foreach ( $order_items as $item ) { |
| 441 |
$data = wc_get_order_item_meta( $item->get_id(), TECHXELA_WOOCOMMERCE_LATEPOINT_ORDER_ITEM_META_KEY ); |
| 442 |
$data_attributes = isset( $data['restrictions'][ $attributes ] ) ? $data['restrictions'][ $attributes ] : null; |
| 443 |
if ( empty( $data_attributes ) ) { |
| 444 |
return null; |
| 445 |
} |
| 446 |
$list_attributes .= '<li>' . $data_attributes . '</li>'; |
| 447 |
} |
| 448 |
$list_attributes .= '</ul>'; |
| 449 |
return $list_attributes; |
| 450 |
} |
| 451 |
} |
| 452 |
|