| 1 |
<?php |
| 2 |
/** |
| 3 |
* Merchant - Product Labels |
| 4 |
*/ |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly |
| 8 |
} |
| 9 |
|
| 10 |
$position = Merchant_Admin_Options::get( Merchant_Product_Labels::MODULE_ID, 'label_position', 'top-left' ); |
| 11 |
$margin_y_label = ( $position === 'top-left' || $position === 'top-right' ) ? esc_html__( 'Margin Top', 'merchant' ) : esc_html__( 'Margin Bottom', 'merchant' ); |
| 12 |
$margin_x_label = ( $position === 'top-left' || $position === 'bottom-left' ) ? esc_html__( 'Margin Left', 'merchant' ) : esc_html__( 'Margin Right', 'merchant' ); |
| 13 |
|
| 14 |
$text_shapes = array(); |
| 15 |
$image_shapes = array(); |
| 16 |
|
| 17 |
for ( $i = 1; $i <= 24; $i++ ) { |
| 18 |
if ( $i <= 8 ) { |
| 19 |
$text_shapes[ 'text-shape-' . $i ] = MERCHANT_URI . 'assets/images/icons/product-labels/text-shape-' . $i . '.svg'; |
| 20 |
} |
| 21 |
|
| 22 |
$image_shapes[ 'image-shape-' . $i ] = MERCHANT_URI . 'assets/images/icons/product-labels/image-shape-' . $i . '.svg'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Settings |
| 27 |
*/ |
| 28 |
Merchant_Admin_Options::create( array( |
| 29 |
'title' => esc_html__( 'Settings', 'merchant' ), |
| 30 |
'module' => Merchant_Product_Labels::MODULE_ID, |
| 31 |
'fields' => array( |
| 32 |
array( |
| 33 |
'id' => 'labels', |
| 34 |
'type' => 'flexible_content', |
| 35 |
'sorting' => true, |
| 36 |
'accordion' => true, |
| 37 |
'style' => Merchant_Product_Labels::MODULE_ID . '-style default', |
| 38 |
'button_label' => esc_html__( 'Add New Label', 'merchant' ), |
| 39 |
'layouts' => array( |
| 40 |
'single-label' => array( |
| 41 |
'title' => esc_html__( 'Product label', 'merchant' ), |
| 42 |
'title-field' => 'label-title', |
| 43 |
'fields' => array( |
| 44 |
array( |
| 45 |
'id' => 'label-title', |
| 46 |
'title' => esc_html__( 'Label name', 'merchant' ), |
| 47 |
'desc' => esc_html__( 'Internal label name. This is not visible to customers.', 'merchant' ), |
| 48 |
'type' => 'text', |
| 49 |
'default' => esc_html__( 'Product label', 'merchant' ), |
| 50 |
), |
| 51 |
|
| 52 |
array( |
| 53 |
'id' => 'label_type', |
| 54 |
'type' => 'buttons_content', |
| 55 |
'title' => '', |
| 56 |
'desc' => '', |
| 57 |
'options' => array( |
| 58 |
'text' => array( |
| 59 |
'title' => esc_html__( 'Text', 'merchant' ), |
| 60 |
'desc' => esc_html__( 'Add text label', 'merchant' ), |
| 61 |
'icon' => MERCHANT_URI . 'assets/images/icons/product-labels/text-icon.svg', |
| 62 |
), |
| 63 |
'image' => array( |
| 64 |
'title' => esc_html__( 'Image', 'merchant' ), |
| 65 |
'desc' => esc_html__( 'Add image label', 'merchant' ), |
| 66 |
'icon' => MERCHANT_URI . 'assets/images/icons/product-labels/image-icon.svg', |
| 67 |
), |
| 68 |
), |
| 69 |
'default' => 'text', |
| 70 |
), |
| 71 |
|
| 72 |
array( |
| 73 |
'id' => 'label', |
| 74 |
'title' => esc_html__( 'Label content', 'merchant' ), |
| 75 |
'type' => 'text', |
| 76 |
'default' => esc_html__( 'SALE', 'merchant' ), |
| 77 |
'desc' => __( 'You can use these codes in the content.', 'merchant' ), |
| 78 |
'hidden_desc' => sprintf( |
| 79 |
/* Translators: %1$s: Discount percentage, %2$s: Discount amount, %3$s: In Stock, %4$s: Total quantity */ |
| 80 |
__( |
| 81 |
'<strong>%1$s:</strong> to show discount percentage<br><strong>%2$s:</strong> to show discount amount<br><strong>%3$s:</strong> to show In Stock, Sold Out<br><strong>%4$s:</strong> to show total quantity in inventory', |
| 82 |
'merchant' |
| 83 |
), |
| 84 |
'{sale}', |
| 85 |
'{sale_amount}', |
| 86 |
'{inventory}', |
| 87 |
'{inventory_quantity}' |
| 88 |
), |
| 89 |
'condition' => array( 'label_type', '==', 'text' ), |
| 90 |
), |
| 91 |
|
| 92 |
array( |
| 93 |
'id' => 'label_text_shape', |
| 94 |
'type' => 'choices', |
| 95 |
'title' => esc_html__( 'Label shape', 'merchant' ), |
| 96 |
'options' => $text_shapes, |
| 97 |
'default' => 'text-shape-1', |
| 98 |
'condition' => array( 'label_type', '==', 'text' ), |
| 99 |
), |
| 100 |
|
| 101 |
array( |
| 102 |
'id' => 'label_image_shape', |
| 103 |
'type' => 'choices', |
| 104 |
'title' => esc_html__( 'Image label', 'merchant' ), |
| 105 |
'options' => $image_shapes, |
| 106 |
'default' => 'image-shape-1', |
| 107 |
'condition' => array( 'label_type', '==', 'image' ), |
| 108 |
), |
| 109 |
|
| 110 |
array( |
| 111 |
'id' => 'label_image_shape_custom', |
| 112 |
'type' => 'upload', |
| 113 |
'drag_drop' => true, |
| 114 |
'title' => esc_html__( 'Upload custom image label', 'merchant' ), |
| 115 |
'label' => esc_html__( 'Click to upload or drag and drop', 'merchant' ), |
| 116 |
'condition' => array( 'label_type', '==', 'image' ), |
| 117 |
), |
| 118 |
|
| 119 |
array( |
| 120 |
'id' => 'label_position', |
| 121 |
'type' => 'select', |
| 122 |
'title' => esc_html__( 'Position', 'merchant' ), |
| 123 |
'options' => array( |
| 124 |
'top-left' => esc_html__( 'Top left', 'merchant' ), |
| 125 |
'top-right' => esc_html__( 'Top right', 'merchant' ), |
| 126 |
), |
| 127 |
'default' => 'top-left', |
| 128 |
), |
| 129 |
|
| 130 |
array( |
| 131 |
'id' => 'margin_y', |
| 132 |
'type' => 'range', |
| 133 |
'title' => $margin_y_label, |
| 134 |
'min' => 0, |
| 135 |
'max' => 250, |
| 136 |
'step' => 1, |
| 137 |
'default' => 10, |
| 138 |
'unit' => 'px', |
| 139 |
), |
| 140 |
|
| 141 |
array( |
| 142 |
'id' => 'margin_x', |
| 143 |
'type' => 'range', |
| 144 |
'title' => $margin_x_label, |
| 145 |
'min' => 0, |
| 146 |
'max' => 250, |
| 147 |
'step' => 1, |
| 148 |
'default' => 10, |
| 149 |
'unit' => 'px', |
| 150 |
), |
| 151 |
|
| 152 |
array( |
| 153 |
'id' => 'label_width', |
| 154 |
'type' => 'range', |
| 155 |
'title' => esc_html__( 'Label width', 'merchant' ), |
| 156 |
'min' => 1, |
| 157 |
'max' => 1000, |
| 158 |
'step' => 1, |
| 159 |
'default' => 50, |
| 160 |
'unit' => 'px', |
| 161 |
), |
| 162 |
array( |
| 163 |
'id' => 'label_height', |
| 164 |
'type' => 'range', |
| 165 |
'title' => esc_html__( 'Label height', 'merchant' ), |
| 166 |
'min' => 1, |
| 167 |
'max' => 250, |
| 168 |
'step' => 1, |
| 169 |
'default' => 50, |
| 170 |
'unit' => 'px', |
| 171 |
), |
| 172 |
|
| 173 |
array( |
| 174 |
'id' => 'background_color', |
| 175 |
'type' => 'color', |
| 176 |
'title' => esc_html__( 'Background color', 'merchant' ), |
| 177 |
'default' => '#212121', |
| 178 |
'condition' => array( 'label_type', '==', 'text' ), |
| 179 |
), |
| 180 |
|
| 181 |
array( |
| 182 |
'id' => 'shape_radius', |
| 183 |
'type' => 'range', |
| 184 |
'title' => esc_html__( 'Shape radius', 'merchant' ), |
| 185 |
'min' => 0, |
| 186 |
'max' => 250, |
| 187 |
'step' => 1, |
| 188 |
'unit' => 'px', |
| 189 |
'default' => 5, |
| 190 |
'condition' => array( 'label_type', '==', 'text' ), |
| 191 |
), |
| 192 |
|
| 193 |
array( |
| 194 |
'id' => 'font_size', |
| 195 |
'type' => 'range', |
| 196 |
'title' => esc_html__( 'Font size', 'merchant' ), |
| 197 |
'min' => 0, |
| 198 |
'max' => 250, |
| 199 |
'step' => 1, |
| 200 |
'unit' => 'px', |
| 201 |
'default' => 14, |
| 202 |
'condition' => array( 'label_type', '==', 'text' ), |
| 203 |
), |
| 204 |
|
| 205 |
array( |
| 206 |
'id' => 'font_style', |
| 207 |
'type' => 'select', |
| 208 |
'title' => esc_html__( 'Font style', 'merchant' ), |
| 209 |
'options' => array( |
| 210 |
'normal' => esc_html__( 'Normal', 'merchant' ), |
| 211 |
'italic' => esc_html__( 'Italic', 'merchant' ), |
| 212 |
'bold' => esc_html__( 'Bold', 'merchant' ), |
| 213 |
'bold_italic' => esc_html__( 'Bold Italic', 'merchant' ), |
| 214 |
), |
| 215 |
'default' => 'normal', |
| 216 |
'condition' => array( 'label_type', '==', 'text' ), |
| 217 |
), |
| 218 |
|
| 219 |
array( |
| 220 |
'id' => 'text_color', |
| 221 |
'type' => 'color', |
| 222 |
'title' => esc_html__( 'Font color', 'merchant' ), |
| 223 |
'default' => '#ffffff', |
| 224 |
'condition' => array( 'label_type', '==', 'text' ), |
| 225 |
), |
| 226 |
|
| 227 |
array( |
| 228 |
'id' => 'display_rules', |
| 229 |
'type' => 'select', |
| 230 |
'title' => esc_html__( 'Product trigger', 'merchant' ), |
| 231 |
'options' => array( |
| 232 |
'featured_products' => esc_html__( 'Featured Products', 'merchant' ), |
| 233 |
'products_on_sale' => esc_html__( 'Products on Sale', 'merchant' ), |
| 234 |
'new_products' => esc_html__( 'New Products', 'merchant' ), |
| 235 |
'out_of_stock' => esc_html__( 'Out of Stock Products', 'merchant' ), |
| 236 |
'all_products' => esc_html__( 'All Products', 'merchant' ), |
| 237 |
'specific_products' => esc_html__( 'Specific Products', 'merchant' ), |
| 238 |
'by_category' => esc_html__( 'Specific Categories', 'merchant' ), |
| 239 |
), |
| 240 |
'default' => 'products_on_sale', |
| 241 |
), |
| 242 |
|
| 243 |
array( |
| 244 |
'id' => 'new_products_days', |
| 245 |
'type' => 'number', |
| 246 |
'min' => 0, |
| 247 |
'step' => 1, |
| 248 |
'title' => esc_html__( 'How long counts as new', 'merchant' ), |
| 249 |
'desc' => esc_html__( 'Set the number of days the product will be marked as ‘New’ after it has been created', 'merchant' ), |
| 250 |
'default' => 3, |
| 251 |
'condition' => array( 'display_rules', '==', 'new_products' ), |
| 252 |
), |
| 253 |
|
| 254 |
array( |
| 255 |
'id' => 'product_cats', |
| 256 |
'type' => 'select_ajax', |
| 257 |
'title' => esc_html__( 'Categories', 'merchant' ), |
| 258 |
'source' => 'options', |
| 259 |
'multiple' => true, |
| 260 |
'options' => Merchant_Admin_Options::get_category_select2_choices(), |
| 261 |
'placeholder' => esc_html__( 'Select categories', 'merchant' ), |
| 262 |
'desc' => esc_html__( 'Select the product categories that will show the label.', 'merchant' ), |
| 263 |
'condition' => array( 'display_rules', '==', 'by_category' ), |
| 264 |
), |
| 265 |
|
| 266 |
array( |
| 267 |
'id' => 'product_ids', |
| 268 |
'type' => 'products_selector', |
| 269 |
'multiple' => true, |
| 270 |
'desc' => esc_html__( 'Select the products that will show the layel.', 'merchant' ), |
| 271 |
'allowed_types' => array( 'simple', 'variable' ), |
| 272 |
'condition' => array( 'display_rules', '==', 'specific_products' ), |
| 273 |
), |
| 274 |
|
| 275 |
array( |
| 276 |
'id' => 'excluded_products', |
| 277 |
'type' => 'products_selector', |
| 278 |
'title' => esc_html__( 'Exclude Products', 'merchant' ), |
| 279 |
'multiple' => true, |
| 280 |
'desc' => esc_html__( 'Exclude products from this label.', 'merchant' ), |
| 281 |
'condition' => array( 'display_rules', 'any', 'all_products|by_category|featured_products|new_products|products_on_sale|out_of_stock' ), |
| 282 |
), |
| 283 |
|
| 284 |
array( |
| 285 |
'id' => 'show_pages', |
| 286 |
'type' => 'checkbox_multiple', |
| 287 |
'title' => esc_html__( 'Show on pages', 'merchant' ), |
| 288 |
'options' => array( |
| 289 |
'homepage' => esc_html__( 'Homepage', 'merchant' ), |
| 290 |
'single' => esc_html__( 'Product Single', 'merchant' ), |
| 291 |
'archive' => esc_html__( 'Product Archive', 'merchant' ), |
| 292 |
), |
| 293 |
'default' => array( 'homepage', 'single', 'archive' ), |
| 294 |
), |
| 295 |
|
| 296 |
array( |
| 297 |
'id' => 'show_devices', |
| 298 |
'type' => 'checkbox_multiple', |
| 299 |
'title' => esc_html__( 'Show on devices', 'merchant' ), |
| 300 |
'options' => array( |
| 301 |
'desktop' => esc_html__( 'Desktop', 'merchant' ), |
| 302 |
'mobile' => esc_html__( 'Mobile', 'merchant' ), |
| 303 |
), |
| 304 |
'default' => array( 'desktop', 'mobile' ), |
| 305 |
), |
| 306 |
), |
| 307 |
), |
| 308 |
), |
| 309 |
'default' => array( |
| 310 |
array( |
| 311 |
'layout' => 'single-label', |
| 312 |
'label' => esc_html__( 'SALE', 'merchant' ), |
| 313 |
'display_rules' => 'featured_products', |
| 314 |
), |
| 315 |
), |
| 316 |
), |
| 317 |
), |
| 318 |
) ); |
| 319 |
|