| 1 |
<?php |
| 2 |
namespace YayMail\Elements; |
| 3 |
|
| 4 |
use YayMail\Abstracts\BaseElement; |
| 5 |
use YayMail\Constants\AttributesData; |
| 6 |
use YayMail\Utils\SingletonTrait; |
| 7 |
|
| 8 |
/** |
| 9 |
* OrderDetails Elements |
| 10 |
*/ |
| 11 |
class OrderDetails extends BaseElement { |
| 12 |
|
| 13 |
use SingletonTrait; |
| 14 |
|
| 15 |
protected static $type = 'order_details'; |
| 16 |
|
| 17 |
public $available_email_ids = [ YAYMAIL_WITH_ORDER_EMAILS ]; |
| 18 |
|
| 19 |
public static function get_data( $attributes = [] ) { |
| 20 |
$is_email_improvements_enabled = get_option( 'woocommerce_feature_email_improvements_enabled', 'no' ) === 'yes'; |
| 21 |
$layout_type = $is_email_improvements_enabled ? 'modern' : 'legacy'; |
| 22 |
|
| 23 |
self::$icon = '<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 20 20"> |
| 24 |
<path d="M17.5,2.5v15H2.5V2.5h15M18,1H2c-.55,0-1,.45-1,1v16c0,.55.45,1,1,1h16c.55,0,1-.45,1-1V2c0-.55-.45-1-1-1h0Z"/> |
| 25 |
<path d="M18.05,8.1H1.82c-.41,0-.75-.34-.75-.75s.34-.75.75-.75h16.23c.41,0,.75.34.75.75s-.34.75-.75.75Z"/> |
| 26 |
<path d="M18.05,13.55H1.82c-.41,0-.75-.34-.75-.75s.34-.75.75-.75h16.23c.41,0,.75.34.75.75s-.34.75-.75.75Z"/> |
| 27 |
<path d="M18.05,18.99H1.82c-.41,0-.75-.34-.75-.75s.34-.75.75-.75h16.23c.41,0,.75.34.75.75s-.34.75-.75.75Z"/> |
| 28 |
<path d="M12.75,18.8c-.41,0-.75-.34-.75-.75V1.82c0-.41.34-.75.75-.75s.75.34.75.75v16.23c0,.41-.34.75-.75.75Z"/> |
| 29 |
<path d="M7.27,18.8c-.41,0-.75-.34-.75-.75V1.82c0-.41.34-.75.75-.75s.75.34.75.75v16.23c0,.41-.34.75-.75.75Z"/> |
| 30 |
</svg>'; |
| 31 |
|
| 32 |
$title_conditions = [ |
| 33 |
[ |
| 34 |
'value' => true, |
| 35 |
'attribute' => 'show_table_header', |
| 36 |
'operator' => 'or', |
| 37 |
], |
| 38 |
[ |
| 39 |
'value' => '', |
| 40 |
'attribute' => 'show_table_header', |
| 41 |
'operator' => 'or', |
| 42 |
], |
| 43 |
]; |
| 44 |
|
| 45 |
return [ |
| 46 |
'id' => uniqid(), |
| 47 |
'type' => self::$type, |
| 48 |
'name' => __( 'Order Details', 'yaymail' ), |
| 49 |
'icon' => self::$icon, |
| 50 |
'group' => 'woocommerce', |
| 51 |
'available' => true, |
| 52 |
'position' => 190, |
| 53 |
'data' => [ |
| 54 |
'rich_text' => [ |
| 55 |
'value_path' => 'rich_text', |
| 56 |
'component' => '', |
| 57 |
'title' => __( 'Content', 'yaymail' ), |
| 58 |
'default_value' => $attributes['rich_text'] ?? '[yaymail_order_details]', |
| 59 |
'type' => 'content', |
| 60 |
], |
| 61 |
'payment_instructions' => [ |
| 62 |
'value_path' => 'payment_instructions', |
| 63 |
'component' => '', |
| 64 |
'title' => __( 'Payment instructions', 'yaymail' ), |
| 65 |
'default_value' => '[yaymail_payment_instructions]', |
| 66 |
'type' => 'content', |
| 67 |
], |
| 68 |
'container_group_definition' => [ |
| 69 |
'component' => 'GroupDefinition', |
| 70 |
'title' => __( 'Container settings', 'yaymail' ), |
| 71 |
'description' => __( 'Handle container layout settings', 'yaymail' ), |
| 72 |
], |
| 73 |
'padding' => [ |
| 74 |
'value_path' => 'padding', |
| 75 |
'component' => 'Spacing', |
| 76 |
'title' => __( 'Padding', 'yaymail' ), |
| 77 |
'default_value' => isset( $attributes['padding'] ) ? $attributes['padding'] : [ |
| 78 |
'top' => '15', |
| 79 |
'right' => '50', |
| 80 |
'bottom' => '15', |
| 81 |
'left' => '50', |
| 82 |
], |
| 83 |
'type' => 'style', |
| 84 |
], |
| 85 |
'background_color' => [ |
| 86 |
'value_path' => 'background_color', |
| 87 |
'component' => 'Color', |
| 88 |
'title' => __( 'Background color', 'yaymail' ), |
| 89 |
'default_value' => isset( $attributes['background_color'] ) ? $attributes['background_color'] : '#fff', |
| 90 |
'type' => 'style', |
| 91 |
], |
| 92 |
'border' => [ |
| 93 |
'value_path' => 'border', |
| 94 |
'component' => 'Border', |
| 95 |
'title' => __( 'Border', 'yaymail' ), |
| 96 |
'default_value' => isset( $attributes['border'] ) ? $attributes['border'] : AttributesData::BORDER_DEFAULT, |
| 97 |
'type' => 'style', |
| 98 |
], |
| 99 |
'table_setting_breaker' => [ |
| 100 |
'component' => 'LineBreaker', |
| 101 |
], |
| 102 |
'table_group_definition' => [ |
| 103 |
'component' => 'GroupDefinition', |
| 104 |
'title' => __( 'Table settings', 'yaymail' ), |
| 105 |
'description' => __( 'Handle table settings', 'yaymail' ), |
| 106 |
], |
| 107 |
'layout_type' => [ |
| 108 |
'value_path' => 'layout_type', |
| 109 |
'component' => 'Selector', |
| 110 |
'title' => __( 'Layout type', 'yaymail' ), |
| 111 |
'default_value' => isset( $attributes['layout_type'] ) ? $attributes['layout_type'] : $layout_type, |
| 112 |
'options' => [ |
| 113 |
[ |
| 114 |
'label' => __( 'Legacy', 'yaymail' ), |
| 115 |
'value' => 'legacy', |
| 116 |
], |
| 117 |
[ |
| 118 |
'label' => __( 'Modern', 'yaymail' ), |
| 119 |
'value' => 'modern', |
| 120 |
], |
| 121 |
], |
| 122 |
'type' => 'content', |
| 123 |
], |
| 124 |
'title' => [ |
| 125 |
'value_path' => 'title', |
| 126 |
'component' => 'RichTextEditor', |
| 127 |
'title' => __( 'Title', 'yaymail' ), |
| 128 |
'default_value' => isset( $attributes['title'] ) ? $attributes['title'] : '<span style="font-size: 20px;">Order #[yaymail_order_number] <b>([yaymail_order_date])</b></span>', |
| 129 |
'type' => 'content', |
| 130 |
], |
| 131 |
'title_color' => [ |
| 132 |
'value_path' => 'title_color', |
| 133 |
'component' => 'Color', |
| 134 |
'title' => __( 'Title color', 'yaymail' ), |
| 135 |
'default_value' => isset( $attributes['title_color'] ) ? $attributes['title_color'] : YAYMAIL_COLOR_WC_DEFAULT, |
| 136 |
'type' => 'style', |
| 137 |
], |
| 138 |
'text_color' => [ |
| 139 |
'value_path' => 'text_color', |
| 140 |
'component' => 'Color', |
| 141 |
'title' => __( 'Text color', 'yaymail' ), |
| 142 |
'default_value' => isset( $attributes['text_color'] ) ? $attributes['text_color'] : YAYMAIL_COLOR_TEXT_DEFAULT, |
| 143 |
'type' => 'style', |
| 144 |
], |
| 145 |
'border_color' => [ |
| 146 |
'value_path' => 'border_color', |
| 147 |
'component' => 'Color', |
| 148 |
'title' => __( 'Border color', 'yaymail' ), |
| 149 |
'default_value' => isset( $attributes['border_color'] ) ? $attributes['border_color'] : YAYMAIL_COLOR_BORDER_DEFAULT, |
| 150 |
'type' => 'style', |
| 151 |
], |
| 152 |
'font_family' => [ |
| 153 |
'value_path' => 'font_family', |
| 154 |
'component' => 'FontFamilySelector', |
| 155 |
'title' => __( 'Font family', 'yaymail' ), |
| 156 |
'default_value' => isset( $attributes['font_family'] ) ? $attributes['font_family'] : YAYMAIL_DEFAULT_FAMILY, |
| 157 |
'type' => 'style', |
| 158 |
], |
| 159 |
'table_content_font_size' => [ |
| 160 |
'value_path' => 'table_content_font_size', |
| 161 |
'component' => 'Dimension', |
| 162 |
'title' => __( 'Table content font size', 'yaymail' ), |
| 163 |
'default_value' => isset( $attributes['table_content_font_size'] ) ? $attributes['table_content_font_size'] : '14', |
| 164 |
'type' => 'style', |
| 165 |
'min' => 8, |
| 166 |
'max' => 25, |
| 167 |
'unit' => 'px', |
| 168 |
], |
| 169 |
'table_heading_line_breaker' => [ |
| 170 |
'component' => 'LineBreaker', |
| 171 |
], |
| 172 |
'table_heading_group_definition' => [ |
| 173 |
'component' => 'GroupDefinition', |
| 174 |
'title' => __( 'Table heading settings', 'yaymail' ), |
| 175 |
'description' => __( 'Handle table heading settings', 'yaymail' ), |
| 176 |
], |
| 177 |
'table_heading_font_size' => [ |
| 178 |
'value_path' => 'table_heading_font_size', |
| 179 |
'component' => 'Dimension', |
| 180 |
'title' => __( 'Table heading font size', 'yaymail' ), |
| 181 |
'default_value' => isset( $attributes['table_heading_font_size'] ) ? $attributes['table_heading_font_size'] : '14', |
| 182 |
'type' => 'style', |
| 183 |
'min' => 8, |
| 184 |
'max' => 25, |
| 185 |
'unit' => 'px', |
| 186 |
], |
| 187 |
'show_table_header' => [ |
| 188 |
'value_path' => 'show_table_header', |
| 189 |
'component' => 'Switcher', |
| 190 |
'title' => __( 'Show table header', 'yaymail' ), |
| 191 |
'default_value' => isset( $attributes['show_table_header'] ) ? $attributes['show_table_header'] : true, |
| 192 |
'type' => 'content', |
| 193 |
], |
| 194 |
'product_title' => [ |
| 195 |
'value_path' => 'product_title', |
| 196 |
'component' => 'TextInput', |
| 197 |
'title' => __( 'Product', 'yaymail' ), |
| 198 |
'default_value' => esc_html__( 'Product', 'woocommerce' ), |
| 199 |
'type' => 'content', |
| 200 |
'conditions' => $title_conditions, |
| 201 |
], |
| 202 |
'cost_title' => [ |
| 203 |
'value_path' => 'cost_title', |
| 204 |
'component' => 'TextInput', |
| 205 |
'title' => __( 'Cost', 'yaymail' ), |
| 206 |
'default_value' => esc_html__( 'Cost', 'woocommerce' ), |
| 207 |
'type' => 'content', |
| 208 |
'conditions' => $title_conditions, |
| 209 |
], |
| 210 |
'quantity_title' => [ |
| 211 |
'value_path' => 'quantity_title', |
| 212 |
'component' => 'TextInput', |
| 213 |
'title' => __( 'Quantity', 'yaymail' ), |
| 214 |
'default_value' => esc_html__( 'Quantity', 'woocommerce' ), |
| 215 |
'type' => 'content', |
| 216 |
'conditions' => $title_conditions, |
| 217 |
], |
| 218 |
'price_title' => [ |
| 219 |
'value_path' => 'price_title', |
| 220 |
'component' => 'TextInput', |
| 221 |
'title' => __( 'Price', 'yaymail' ), |
| 222 |
'default_value' => esc_html__( 'Price', 'woocommerce' ), |
| 223 |
'type' => 'content', |
| 224 |
'conditions' => $title_conditions, |
| 225 |
], |
| 226 |
'cart_subtotal_title' => [ |
| 227 |
'value_path' => 'cart_subtotal_title', |
| 228 |
'component' => 'TextInput', |
| 229 |
'title' => __( 'Subtotal', 'yaymail' ), |
| 230 |
'default_value' => esc_html__( 'Subtotal:', 'woocommerce' ), |
| 231 |
'type' => 'content', |
| 232 |
], |
| 233 |
'payment_method_title' => [ |
| 234 |
'value_path' => 'payment_method_title', |
| 235 |
'component' => 'TextInput', |
| 236 |
'title' => __( 'Payment method', 'yaymail' ), |
| 237 |
'default_value' => esc_html__( 'Payment method:', 'woocommerce' ), |
| 238 |
'type' => 'content', |
| 239 |
], |
| 240 |
'order_total_title' => [ |
| 241 |
'value_path' => 'order_total_title', |
| 242 |
'component' => 'TextInput', |
| 243 |
'title' => __( 'Total', 'yaymail' ), |
| 244 |
'default_value' => esc_html__( 'Total:', 'woocommerce' ), |
| 245 |
'type' => 'content', |
| 246 |
], |
| 247 |
'order_note_title' => [ |
| 248 |
'value_path' => 'order_note_title', |
| 249 |
'component' => 'TextInput', |
| 250 |
'title' => __( 'Note', 'yaymail' ), |
| 251 |
'default_value' => esc_html__( 'Note:', 'woocommerce' ), |
| 252 |
'type' => 'content', |
| 253 |
], |
| 254 |
'shipping_title' => [ |
| 255 |
'value_path' => 'shipping_title', |
| 256 |
'component' => 'TextInput', |
| 257 |
'title' => __( 'Shipping', 'yaymail' ), |
| 258 |
'default_value' => esc_html__( 'Shipping:', 'woocommerce' ) . ' [yaymail_shipping_method]', |
| 259 |
'type' => 'content', |
| 260 |
], |
| 261 |
'discount_title' => [ |
| 262 |
'value_path' => 'discount_title', |
| 263 |
'component' => 'TextInput', |
| 264 |
'title' => __( 'Discount', 'yaymail' ), |
| 265 |
'default_value' => esc_html__( 'Discount:', 'woocommerce' ), |
| 266 |
'type' => 'content', |
| 267 |
], |
| 268 |
'custom_footer_rows_breaker' => [ |
| 269 |
'component' => 'LineBreaker', |
| 270 |
], |
| 271 |
'custom_footer_rows_group' => [ |
| 272 |
'component' => 'GroupDefinition', |
| 273 |
'title' => __( 'Custom Footer Rows', 'yaymail' ), |
| 274 |
'description' => __( 'Add custom rows to the order totals footer', 'yaymail' ), |
| 275 |
], |
| 276 |
'custom_footer_rows' => [ |
| 277 |
'value_path' => 'custom_footer_rows', |
| 278 |
'component' => 'CustomFooterRowsEditor', |
| 279 |
'title' => __( 'Custom Footer Rows', 'yaymail' ), |
| 280 |
'default_value' => isset( $attributes['custom_footer_rows'] ) ? $attributes['custom_footer_rows'] : [], |
| 281 |
'type' => 'content', |
| 282 |
], |
| 283 |
], |
| 284 |
]; |
| 285 |
} |
| 286 |
} |
| 287 |
|