function wooccm_shipping_fields($fields)
{
    // Check if we have any fields to process
    $options = get_option('wccs_settings2');
    if (empty($options['shipping_buttons'])) {
        return $fields;
    }
    foreach ($options['shipping_buttons'] as $btn) {
        if (!empty($btn['cow']) && empty($btn['deny_checkout'])) {
            if ($btn['cow'] == 'country') {
                $fields['shipping_' . $btn['cow'] . '']['type'] = 'wooccmcountry';
            } elseif ($btn['cow'] == 'state') {
                $fields['shipping_' . $btn['cow'] . '']['type'] = 'wooccmstate';
            } else {
                $fields['shipping_' . $btn['cow'] . '']['type'] = '' . $btn['type'] . '';
            }
            if ($btn['cow'] !== 'country' || $btn['cow'] !== 'state') {
                $fields['shipping_' . $btn['cow'] . '']['placeholder'] = '' . (isset($btn['placeholder']) ? $btn['placeholder'] : '') . '';
            }
            $fields['shipping_' . $btn['cow'] . '']['class'] = array('' . $btn['position'] . ' ' . (isset($btn['conditional_tie']) ? $btn['conditional_tie'] : '') . ' ' . (isset($btn['extra_class']) ? $btn['extra_class'] : '') . '');
            $fields['shipping_' . $btn['cow'] . '']['label'] = wpml_string_wccm_pro('' . $btn['label'] . '');
            $fields['shipping_' . $btn['cow'] . '']['clear'] = '' . (isset($btn['clear_row']) ? $btn['clear_row'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['default'] = '' . (isset($btn['force_title2']) ? $btn['force_title2'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['options'] = '' . (isset($btn['option_array']) ? $btn['option_array'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['user_role'] = '' . (isset($btn['user_role']) ? $btn['user_role'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['role_options'] = '' . (isset($btn['role_options']) ? $btn['role_options'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['role_options2'] = '' . (isset($btn['role_options2']) ? $btn['role_options2'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['required'] = false;
            $fields['shipping_' . $btn['cow'] . '']['wooccm_required'] = '' . (isset($btn['checkbox']) ? $btn['checkbox'] : false) . '';
            $fields['shipping_' . $btn['cow'] . '']['cow'] = '' . (isset($btn['cow']) ? $btn['cow'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['color'] = '' . (isset($btn['colorpickerd']) ? $btn['colorpickerd'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['colorpickertype'] = '' . (isset($btn['colorpickertype']) ? $btn['colorpickertype'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['order'] = '' . (isset($btn['order']) ? $btn['order'] : '') . '';
            $fields['shipping_' . $btn['cow'] . '']['fancy'] = '' . (isset($btn['fancy']) ? $btn['fancy'] : '') . '';
            if (!empty($btn['disabled'])) {
                unset($fields['shipping_' . $btn['cow'] . '']);
            }
        }
    }
    // Resort the fields by order
    $fields[] = uasort($fields, 'wooccm_sort_fields');
    if ($fields[0]) {
        unset($fields[0]);
    }
    return $fields;
}
示例#2
0
function wooccm_remove_notices_conditional($posted)
{
    $notice = WC()->session->get('wc_notices');
    $shipping = array('country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode');
    $billing = array('country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state', 'postcode', 'email', 'phone');
    $names = array('billing', 'shipping');
    $inc = 3;
    foreach ($names as $name) {
        $array = $name == 'billing' ? $billing : $shipping;
        $options2 = get_option('wccs_settings' . $inc . '');
        if (!empty($options2['' . $name . '_buttons'])) {
            foreach ($options2['' . $name . '_buttons'] as $btn) {
                if (!empty($btn['chosen_valt']) && !empty($btn['conditional_parent_use']) && !empty($btn['conditional_tie']) && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && !empty($btn['conditional_parent'])) {
                    if (!empty($_POST[$btn['cow']])) {
                        foreach ($options['buttons'] as $btn2) {
                            if (!empty($btn2['chosen_valt']) && !empty($btn2['conditional_parent_use']) && !empty($btn2['conditional_tie']) && $btn2['type'] !== 'changename' && $btn2['type'] !== 'heading' && empty($btn2['conditional_parent'])) {
                                if (sanitize_text_field($_POST['' . $btn['cow'] . '']) != $btn2['chosen_valt']) {
                                    if (empty($_POST['' . $btn2['cow'] . ''])) {
                                        foreach ($notice['error'] as $position => $value) {
                                            if (strip_tags($value) == '' . wpml_string_wccm_pro($btn2['label']) . ' is a required field.') {
                                                unset($notice['error'][$position]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        foreach ($notice['error'] as $position => $value) {
                            if (strip_tags($value) == '' . wpml_string_wccm_pro($btn2['label']) . ' is a required field.') {
                                unset($notice['error'][$position]);
                            }
                        }
                    }
                }
            }
        }
        $inc--;
    }
    $options = get_option('wccs_settings');
    global $woocommerce;
    if (!empty($options['buttons'])) {
        foreach ($options['buttons'] as $btn) {
            if (!empty($btn['chosen_valt']) && !empty($btn['conditional_parent_use']) && !empty($btn['conditional_tie']) && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && !empty($btn['conditional_parent'])) {
                if (!empty($_POST[$btn['cow']])) {
                    foreach ($options['buttons'] as $btn2) {
                        if (!empty($btn2['chosen_valt']) && !empty($btn2['conditional_parent_use']) && !empty($btn2['conditional_tie']) && $btn2['type'] !== 'changename' && $btn2['type'] !== 'heading' && empty($btn2['conditional_parent'])) {
                            if (sanitize_text_field($_POST['' . $btn['cow'] . '']) != $btn2['chosen_valt']) {
                                if (empty($_POST['' . $btn2['cow'] . ''])) {
                                    foreach ($notice['error'] as $position => $value) {
                                        if (strip_tags($value) == '' . wpml_string_wccm_pro($btn2['label']) . ' is a required field.') {
                                            unset($notice['error'][$position]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    foreach ($notice['error'] as $position => $value) {
                        if (strip_tags($value) == '' . wpml_string_wccm_pro($btn2['label']) . ' is a required field.') {
                            unset($notice['error'][$position]);
                        }
                    }
                }
            }
        }
    }
    WC()->session->set('wc_notices', $notice);
}
示例#3
0
function wooccm_install()
{
    $options = get_option('wccs_settings');
    $options2 = get_option('wccs_settings2');
    $options3 = get_option('wccs_settings3');
    update_option('wooccm_update_notice', 0);
    if (function_exists('icl_register_string')) {
        icl_register_string('WooCommerce Checkout Manager', 'is a required field.', 'is a required field.');
    }
    if (empty($options['checkness']['position'])) {
        $options['checkness']['position'] = 'after_order_notes';
    }
    if (empty($options['checkness']['wooccm_notification_email'])) {
        $options['checkness']['wooccm_notification_email'] = get_option('admin_email');
    }
    if (empty($options['checkness']['payment_method_d'])) {
        $options['checkness']['payment_method_d'] = 'Payment Method';
    }
    if (empty($options['checkness']['time_stamp_title'])) {
        $options['checkness']['time_stamp_title'] = 'Order Time';
    }
    if (empty($options['checkness']['payment_method_t'])) {
        $options['checkness']['payment_method_t'] = '1';
    }
    if (empty($options['checkness']['shipping_method_d'])) {
        $options['checkness']['shipping_method_d'] = 'Shipping Method';
    }
    if (empty($options['checkness']['shipping_method_t'])) {
        $options['checkness']['shipping_method_t'] = '1';
    }
    if (empty($options2['shipping_buttons'])) {
        $shipping = array('country' => 'Country', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'company' => 'Company Name', 'address_1' => 'Address', 'address_2' => '', 'city' => 'Town/ City', 'state' => 'State', 'postcode' => 'Zip');
        $ship = 0;
        foreach ($shipping as $name => $value) {
            $options2['shipping_buttons'][$ship]['label'] = __('' . $value . '', 'woocommerce');
            $options2['shipping_buttons'][$ship]['cow'] = $name;
            $options2['shipping_buttons'][$ship]['checkbox'] = 'true';
            $options2['shipping_buttons'][$ship]['order'] = $ship + 1;
            $options2['shipping_buttons'][$ship]['type'] = 'wooccmtext';
            if ($name == 'country') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-wide';
            }
            if ($name == 'first_name') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-first';
            }
            if ($name == 'last_name') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-last';
                $options2['shipping_buttons'][$ship]['clear_row'] = true;
            }
            if ($name == 'company') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-wide';
            }
            if ($name == 'address_1') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-wide';
                $options2['shipping_buttons'][$ship]['placeholder'] = __('Street address', 'woocommerce');
            }
            if ($name == 'address_2') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-wide';
                $options2['shipping_buttons'][$ship]['placeholder'] = __('Apartment, suite, unit etc. (optional)', 'woocommerce');
            }
            if ($name == 'city') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-wide';
                $options2['shipping_buttons'][$ship]['placeholder'] = __('Town / City', 'woocommerce');
            }
            if ($name == 'state') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-first';
            }
            if ($name == 'postcode') {
                $options2['shipping_buttons'][$ship]['position'] = 'form-row-last';
                $options2['shipping_buttons'][$ship]['placeholder'] = __('Postcode / Zip', 'woocommerce');
                $options2['shipping_buttons'][$ship]['clear_row'] = true;
            }
            $ship++;
        }
    }
    if (empty($options3['billing_buttons'])) {
        $billing = array('country' => 'Country', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'company' => 'Company Name', 'address_1' => 'Address', 'address_2' => '', 'city' => 'Town/ City', 'state' => 'State', 'postcode' => 'Zip', 'email' => 'Email Address', 'phone' => 'Phone');
        $bill = 0;
        foreach ($billing as $name => $value) {
            $options3['billing_buttons'][$bill]['label'] = __('' . $value . '', 'woocommerce');
            $options3['billing_buttons'][$bill]['cow'] = $name;
            $options3['billing_buttons'][$bill]['checkbox'] = 'true';
            $options3['billing_buttons'][$bill]['order'] = $bill + 1;
            $options3['billing_buttons'][$bill]['type'] = 'wooccmtext';
            if ($name == 'country') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-wide';
            }
            if ($name == 'first_name') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-first';
            }
            if ($name == 'last_name') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-last';
                $options3['billing_buttons'][$bill]['clear_row'] = true;
            }
            if ($name == 'company') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-wide';
            }
            if ($name == 'address_1') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-wide';
                $options3['billing_buttons'][$bill]['placeholder'] = __('Street address', 'woocommerce');
            }
            if ($name == 'address_2') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-wide';
                $options3['billing_buttons'][$bill]['placeholder'] = __('Apartment, suite, unit etc. (optional)', 'woocommerce');
            }
            if ($name == 'city') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-wide';
                $options3['billing_buttons'][$bill]['placeholder'] = __('Town / City', 'woocommerce');
            }
            if ($name == 'state') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-first';
            }
            if ($name == 'postcode') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-last';
                $options3['billing_buttons'][$bill]['placeholder'] = __('Postcode / Zip', 'woocommerce');
                $options3['billing_buttons'][$bill]['clear_row'] = true;
            }
            if ($name == 'email') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-first';
            }
            if ($name == 'phone') {
                $options3['billing_buttons'][$bill]['position'] = 'form-row-last';
                $options3['billing_buttons'][$bill]['clear_row'] = true;
            }
            $bill++;
        }
    }
    if (!empty($options['buttons'])) {
        foreach ($options['buttons'] as $i => $btn) {
            if (!empty($btn['check_1']) || !empty($btn['check_2'])) {
                $options['buttons'][$i]['option_array'] = implode('||', array('' . wpml_string_wccm_pro('' . $btn['check_1'] . '') . '', '' . wpml_string_wccm_pro('' . $btn['check_2'] . '') . ''));
                $options['buttons'][$i]['check_1'] = '';
                $options['buttons'][$i]['check_2'] = '';
            }
            $options['buttons'][$i]['type'] = $btn['type'] == 'checkbox' ? 'checkbox_wccm' : $btn['type'];
            $options['buttons'][$i]['type'] = $btn['type'] == 'text' ? 'wooccmtext' : $btn['type'];
            $options['buttons'][$i]['type'] = $btn['type'] == 'select' ? 'wooccmselect' : $btn['type'];
            $options['buttons'][$i]['type'] = $btn['type'] == 'date' ? 'datepicker' : $btn['type'];
            if (empty($btn['option_array'])) {
                $btn['option_array'] = '';
            }
            $mysecureop = explode('||', $btn['option_array']);
            if (!empty($btn['option_a'])) {
                array_push($mysecureop, $btn['option_a']);
            }
            if (!empty($btn['option_b'])) {
                array_push($mysecureop, $btn['option_b']);
            }
            $uniqueThevalues = array_unique($mysecureop);
            $options['buttons'][$i]['option_array'] = implode('||', $uniqueThevalues);
        }
    }
    foreach ($options3['billing_buttons'] as $i => $btn) {
        if (!empty($btn['check_1']) || !empty($btn['check_2'])) {
            $options3['billing_buttons'][$i]['option_array'] = implode('||', array('' . wpml_string_wccm_pro('' . $btn['check_1'] . '') . '', '' . wpml_string_wccm_pro('' . $btn['check_2'] . '') . ''));
            $options3['billing_buttons'][$i]['check_1'] = '';
            $options3['billing_buttons'][$i]['check_2'] = '';
        }
        $options3['billing_buttons'][$i]['type'] = $btn['type'] == 'checkbox' ? 'checkbox_wccm' : $btn['type'];
        $options3['billing_buttons'][$i]['type'] = $btn['type'] == 'text' ? 'wooccmtext' : $btn['type'];
        $options3['billing_buttons'][$i]['type'] = $btn['type'] == 'select' ? 'wooccmselect' : $btn['type'];
        $options3['billing_buttons'][$i]['type'] = $btn['type'] == 'date' ? 'datepicker' : $btn['type'];
    }
    foreach ($options2['shipping_buttons'] as $i => $btn) {
        if (!empty($btn['check_1']) || !empty($btn['check_2'])) {
            $options2['shipping_buttons'][$i]['option_array'] = implode('||', array('' . wpml_string_wccm_pro('' . $btn['check_1'] . '') . '', '' . wpml_string_wccm_pro('' . $btn['check_2'] . '') . ''));
            $options2['shipping_buttons'][$i]['check_1'] = '';
            $options2['shipping_buttons'][$i]['check_2'] = '';
        }
        $options2['shipping_buttons'][$i]['type'] = $btn['type'] == 'checkbox' ? 'checkbox_wccm' : $btn['type'];
        $options2['shipping_buttons'][$i]['type'] = $btn['type'] == 'text' ? 'wooccmtext' : $btn['type'];
        $options2['shipping_buttons'][$i]['type'] = $btn['type'] == 'select' ? 'wooccmselect' : $btn['type'];
        $options2['shipping_buttons'][$i]['type'] = $btn['type'] == 'date' ? 'datepicker' : $btn['type'];
    }
    update_option('wccs_settings', $options);
    update_option('wccs_settings2', $options2);
    update_option('wccs_settings3', $options3);
}
function upload_scripts_enhanced()
{
    global $woocommerce;
    $options = get_option('wccs_settings');
    $length = empty($options['checkness']['file_upload_number']) ? 'this.files.length' : $options['checkness']['file_upload_number'];
    if (!empty($options['buttons'])) {
        foreach ($options['buttons'] as $btn) {
            if ($btn['type'] == 'wooccmupload') {
                $file_types = explode(",", $btn['option_array']);
                $number_of_types = count($file_types);
                ?>
<p>
<script type="text/javascript">
jQuery(document).ready(function($){

	$("#<?php 
                echo $btn['cow'];
                ?>
_field").magnificPopup({
  delegate: "a.wooccm-zoom-special", // child items selector, by clicking on it popup will open
  type: "image",
  zoom: {
            enabled: true,
            duration: 400,
			easing: "ease-out"
   }
});

(function post_image_content() {
var input = document.getElementById("<?php 
                echo $btn['cow'];
                ?>
_file"),
    formdata = false, loadfiles, formnames = [], loadfiles = [];

$("#<?php 
                echo $btn['cow'];
                ?>
_files_button_wccm").click( function(){
$("#<?php 
                echo $btn['cow'];
                ?>
_field input[type=file]").click();
return false;
});

if (window.FormData) {
    formdata = new FormData();
}

function showUploadedItem ( source, getname, filetype ) {
													var 
													list = document.getElementById("<?php 
                echo $btn['cow'];
                ?>
_field"),
													li   = document.createElement("span"),
													name   = document.createElement("name"),
													span   = document.createElement("span"),
													zoom   = document.createElement("a"),
													edit   = document.createElement("a"),
													dele   = document.createElement("a"),
													a   = document.createElement("a"),
													spana   = document.createElement("spana"),
													img  = document.createElement("img");
														
														name.innerHTML = getname;
														edit.innerHTML = "Edit";
														dele.innerHTML = "Delete";
																if (filetype.match("image.*")) {
																			img.src = source;
																			a.href = source;
																			a.title = getname;
																			edit.href = source;
																			zoom.href = source;
																			zoom.title = getname;
																			zoom.innerHTML = "Zoom <img style=display:none />";
																			li.appendChild(a);
																			a.appendChild(img);
																			a.className = "wooccm-zoom-special wooccm-image-holder mfp-zoom";
																			zoom.className = "wooccm-zoom-special wooccm_zoom wooccm-btn wooccm-btn-zoom";
																			edit.className = "wooccm_edit wooccm-btn wooccm-btn-edit enable";
																	}else{
																		zoom.innerHTML = "Zoom";
																		li.appendChild(spana);
																		spana.appendChild(img);
																		spana.className = "wooccm-image-holder";
																		zoom.className = "wooccm_zoom wooccm-btn disable";
																		edit.className = "wooccm_edit wooccm-btn disable";
																	}
																if ( ( false === filetype.match("application/ms.*") && false === filetype.match("application/x.*") && false === filetype.match("audio.*") && false === filetype.match("text.*") && false === filetype.match("video.*") ) || ( 0 === filetype.length || !filetype) ) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/interactive.png');
                ?>
";
																	}
																if (filetype.match("application/ms.*")) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/spreadsheet.png');
                ?>
";
																	}
																if (filetype.match("application/x.*")) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/archive.png');
                ?>
";
																	}
																if (filetype.match("audio.*")) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/audio.png');
                ?>
";
																	}
																if (filetype.match("text.*")) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/text.png');
                ?>
";
																	}
																if (filetype.match("video.*")) {
																		  img.src = "<?php 
                echo site_url('wp-includes/images/media/video.png');
                ?>
";
																	}
																	
													li.title = getname;
													dele.title = getname;
													edit.title = getname;
													li.appendChild(name);
													li.appendChild(span);
													span.appendChild(zoom);
													span.appendChild(edit);
													span.appendChild(dele);
													list.appendChild(li);
													li.className = "wooccm_each_file";
													name.className = "wooccm_name";
													dele.id = "wooccm_dele";
													dele.className = "wooccm_dele wooccm-btn wooccm-btn-danger";
													span.className = "container";
													
					
									}
												
input.addEventListener("change", function (evt) {
	$("#<?php 
                echo $btn['cow'];
                ?>
_field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
	
	var count = $("#<?php 
                echo $btn['cow'];
                ?>
_files_button_wccm").data("count") || 0;
	$("#<?php 
                echo $btn['cow'];
                ?>
_files_button_wccm").data("count", ++count);
	
    var img, reader, file, iname, len = <?php 
                echo $length;
                ?>
;
	var file_array = <?php 
                echo wooccm_js_array($file_types);
                ?>
;
	var wooempt = <?php 
                echo $file_types;
                ?>
;
	

    for ( i = 0; i < len; i++ ) {
        file = this.files[i];
		
		for(x=0; x < <?php 
                echo $number_of_types;
                ?>
; x++){
		if( !wooempt || file.type.match(file_array[x])  ) {
										
             if ( window.FileReader ) {
                reader = new FileReader();
				reader.onload = (function(theFile){
							var fileName = theFile.name,
								filetype = theFile.type;
							return function(e){
								showUploadedItem( e.target.result, fileName, filetype );
							};
						})(file); 
				reader.readAsDataURL(file);
			}
			
				formdata.append("<?php 
                echo $btn['cow'];
                ?>
", file);
				formnames.push(file.name);
				loadfiles.push(file);
				
				$.ajax({
					url: "<?php 
                echo admin_url('/admin-ajax.php?action=wooccm_front_endupload&name=' . $btn['cow'] . '');
                ?>
",
					type: "POST",
					data: formdata,
					cache: false,
					processData: false,
					contentType: false, 
					success: function (res) {
						console.dir(res);
						var result = $.parseJSON(res), new_val;
						
					    new_val = document.getElementById("<?php 
                echo $btn['cow'];
                ?>
").value.split("||");
						new_val[0] = result[0];
						new_val[1] += result[1] + ",";
						document.getElementById("<?php 
                echo $btn['cow'];
                ?>
").value = new_val[0] + "||" + new_val[1];
		
						$("#<?php 
                echo $btn['cow'];
                ?>
_field").unblock();
					}
				});
				
		}else{
			$("#<?php 
                echo $btn['cow'];
                ?>
_field").unblock();
		}
		}
    }

	if( formdata ) {	
		$("#<?php 
                echo $btn['cow'];
                ?>
_field").unblock();
	}
	
			
}, false);
	
$("#caman_content #wooccmtoolbar #save").click( function(){
	$("#caman_content #wooccmtoolbar").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
							
	var title = this.title, the_file, wooxtro = document.getElementById("wooccmactualimage").getAttribute("data-caman-hidpi"), listing, store = [], count = $(".wooccm_each_file").each(function(){});
	formdata = new FormData();
	
	for(var t = 0; t < count.length; t++) {
		if( count[t].getAttribute("wooccm-attach-id") ){
			break;
		}
			store.push(count[t]);
	}
	
	if( store.length !== 0 ){
		listing = document.getElementById("<?php 
                echo $btn['cow'];
                ?>
").value.split("||");
		listing = listing[1].split(",");
		listing = listing.filter(Number);
	
		$.each(listing, function(index, value){
			$(store[index]).attr("wooccm-attach-id", value);
		});
	}
		
	
	$(".wooccm_each_file").each(function(){
		if( this.title === title) {
			var currentgutz = this;
			this.firstElementChild.href = wooxtro;
			this.firstElementChild.firstElementChild.src = wooxtro;
			this.lastElementChild.firstElementChild.href = wooxtro;
			this.lastElementChild.lastElementChild.previousElementSibling.href = wooxtro;	
			
			var byteString;
			var dataURI = wooxtro; //data:image/gif;base64,R0lGODlhyAAiALM...DfD0QAADs
			 
			if (dataURI.split(',')[0].indexOf('base64') >= 0)
			 
			   byteString = atob(dataURI.split(',')[1]);
			 
			else
			 
			   byteString = unescape(dataURI.split(',')[1]);
			 
			// separate out the mime component
			var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
			 
			// write the bytes of the string to a typed array
			var ia = new Uint8Array(byteString.length);
			for (var i = 0; i < byteString.length; i++) {
			   ia[i] = byteString.charCodeAt(i);
			}
			 
			var extension = mimeString.split('/')[1];
			var fileName = "image_" + new Date().getTime() + "." + extension;
			var blob = new Blob([ia], {type:mimeString});
			
			the_file = new File([blob], title, {
				type: "image/png" 
			});
			
			
			formdata.append("<?php 
                echo $btn['cow'];
                ?>
", the_file);
			var remove = this.getAttribute("wooccm-attach-id");
			
			$.ajax({
				url: "<?php 
                echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&name=' . $btn['cow'] . '&remove=');
                ?>
" + remove,
				type: "POST",
				data: formdata,
				cache: false,
				processData: false,
				contentType: false,
				success: function (res) {
					var result = $.parseJSON(res);
					$(currentgutz).attr("wooccm-attach-id", result);
					$("#<?php 
                echo $btn['cow'];
                ?>
").val(function(index, value) {
						return value.replace(remove, result);
					});
	
					$("#caman_content #wooccmtoolbar").unblock();
					alert("<?php 
                echo wpml_string_wccm_pro($options['checkness']['picture_success']);
                ?>
");
				}
		
			});
		}
	});
	
	
});
	
$(document).on('click','.wooccm_dele',function(){ 
		
	var c = confirm("<?php 
                echo wpml_string_wccm_pro($options['checkness']['file_delete']);
                ?>
 " + this.title + " ?"), listing, store = [], count = $(".wooccm_each_file").each(function(){});
	if (c==true) {
		
	$("#<?php 
                echo $btn['cow'];
                ?>
_field").block({ message: null, overlayCSS: { background: '#fff no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } });
		
	for(var t = 0; t < count.length; t++) {
		if( count[t].getAttribute("wooccm-attach-id") ){
			break;
		}
			store.push(count[t]);
	}
	
	if( store.length !== 0 ){
		listing = document.getElementById("<?php 
                echo $btn['cow'];
                ?>
").value.split("||");
		listing = listing[1].split(",");
		listing = listing.filter(Number);
	
		$.each(listing, function(index, value){
			$(store[index]).attr("wooccm-attach-id", value);
		});
	}
		
	var currentname = this.title, wooccmeachfile = document.getElementsByClassName("wooccm_each_file"), remove, shell;
		formdata = new FormData();
			
			for( i = 0; i < wooccmeachfile.length; i++ ){
				if(wooccmeachfile[i].title === currentname){
					remove = wooccmeachfile[i].getAttribute("wooccm-attach-id");
					shell = wooccmeachfile[i];
				}
			}
						
			$.ajax({
				url: "<?php 
                echo admin_url('/admin-ajax.php?action=wooccm_front_enduploadsave&remove=');
                ?>
" + remove,
				type: "POST",
				data: formdata,
				cache: false,
				processData: false,
				contentType: false,
				success: function (res) {
						remove = remove + ",";
						$("#<?php 
                echo $btn['cow'];
                ?>
").val(function(index, value) {
							return value.replace(remove, "");
						});
						
						shell.outerHTML = "";
					
					$("#<?php 
                echo $btn['cow'];
                ?>
_field").unblock();
				}
		
			});
	
	 
	} else {
	}
	
});



	$("#caman_content #wooccmtoolbar #close").click( function(){
		var li = document.getElementById( "wooccmactualimage" );
		li.outerHTML = "";
		$("#caman_content .FilterValue").each(function(){
			$(this).text("0");
		});
		$("#caman_content .FilterSetting input").each(function(){
			$(this).val("0");
		});
		$("#PresetFilters a").each(function(){
			$(this).removeClass("Active");
		});
		$("#caman_content").hide();
		$("html").css("overflow", "visible");
	});
	
	$(document).on('click','.wooccm_edit',function(){
       return false;
     });
	
	 $(document).on('click','.wooccm_edit.enable',function(){ 
		 var imageinbase = this.href,
			 li = document.getElementById( "wooccmimageeditorpro" ),
			 data = document.createAttribute("data-caman-hidpi"),
			 img  = document.createElement("img");
			 
			 data.value = imageinbase;
			 
			 $("#caman_content #wooccmtoolbar #save").attr("title", this.title);
			 
		 if( $(".wooccmimageeditor img").length == 0 ){
			 img.id = "wooccmactualimage";
			 img.src = imageinbase;
			 img.setAttributeNode(data);
			 li.appendChild(img);
	   
	   
			$.getScript( "<?php 
                echo plugins_url('includes/pickers/caman/dist/caman_controls.js', WOOCCM_RELPATH);
                ?>
");
		 }
	   
	   $("#caman_content").show();
	   $("html").css("overflow", "hidden");
     });
	 
	 


}());
});
</script>
</p>
<?php 
            }
        }
    }
}
示例#5
0
function wooccm_ccf_custom_checkout_process()
{
    global $woocommerce;
    $options = get_option('wccs_settings');
    if (count($options['buttons']) == 0) {
        return;
    }
    foreach ($options['buttons'] as $btn) {
        foreach ($woocommerce->cart->cart_contents as $key => $values) {
            $multiproductsx = $btn['single_p'];
            $show_field_single = $btn['single_px'];
            $multiproductsx_cat = $btn['single_p_cat'];
            $show_field_single_cat = $btn['single_px_cat'];
            $productsarraycm[] = $values['product_id'];
            // Products
            // hide field
            // show field without more
            if (!empty($btn['single_px']) && empty($btn['more_content'])) {
                $show_field_array = explode('||', $show_field_single);
                if (in_array($values['product_id'], $show_field_array) && count($woocommerce->cart->cart_contents) < 2) {
                    if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                        if (empty($_POST['' . $btn['cow'] . ''])) {
                            wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                        }
                    }
                }
            }
            // Category
            // hide field
            $terms = get_the_terms($values['product_id'], 'product_cat');
            if (!empty($terms)) {
                foreach ($terms as $term) {
                    $categoryarraycm[] = $term->slug;
                    // without more
                    // show field without more
                    if (!empty($btn['single_px_cat']) && empty($btn['more_content'])) {
                        $show_field_array_cat = explode('||', $show_field_single_cat);
                        if (in_array($term->slug, $show_field_array_cat) && count($woocommerce->cart->cart_contents) < 2) {
                            if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                                if (empty($_POST['' . $btn['cow'] . ''])) {
                                    wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                                }
                            }
                        }
                    }
                }
            }
        }
        // end cart
        // ===========================================================================================
        // Products
        // hide field
        // show field with more
        if (!empty($btn['single_px']) && !empty($btn['more_content'])) {
            $show_field_array = explode('||', $show_field_single);
            if (array_intersect($productsarraycm, $show_field_array)) {
                if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                    if (empty($_POST['' . $btn['cow'] . ''])) {
                        wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                    }
                }
            }
        }
        // Category
        // hide field
        // with more
        // show field with more
        if (!empty($btn['single_px_cat']) && !empty($btn['more_content'])) {
            $show_field_array_cat = explode('||', $show_field_single_cat);
            if (array_intersect($categoryarraycm, $show_field_array_cat)) {
                if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                    if (empty($_POST['' . $btn['cow'] . ''])) {
                        wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                    }
                }
            }
        }
        $categoryarraycm = '';
        $productsarraycm = '';
    }
}
function wooccm_shipping_ccf_custom_checkout_process()
{
    global $woocommerce;
    $options = get_option('wccs_settings2');
    $ship_to_another_address = isset($_POST['ship_to_different_address']) ? sanitize_text_field($_POST['ship_to_different_address']) : false;
    if (WC()->cart->needs_shipping_address() === true && $ship_to_another_address == 1) {
        if (count($options['shipping_buttons']) == 0) {
            return;
        }
        foreach ($options['shipping_buttons'] as $btn) {
            if ($btn['checkbox'] === 'true') {
                // without checkbox
                if (empty($btn['single_px_cat']) && empty($btn['single_p_cat']) && empty($btn['single_px']) && empty($btn['single_p']) && !empty($btn['label']) && $btn['type'] !== 'changename' && $btn['type'] !== 'heading') {
                    if (empty($_POST['shipping_' . $btn['cow'] . ''])) {
                        wc_add_notice('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> ' . wpml_string_wccm_pro('is a required field.') . '', 'error');
                    }
                }
                // checkbox
                if (empty($btn['single_px_cat']) && empty($btn['single_p_cat']) && empty($btn['single_px']) && empty($btn['single_p']) && $btn['type'] == 'checkbox' && !empty($btn['label']) && $btn['type'] !== 'changename' && $btn['type'] !== 'heading') {
                    if (sanitize_text_field($_POST['shipping_' . $btn['cow'] . '']) == '' . $btn['check_2'] . '' && !empty($btn['checkbox'])) {
                        wc_add_notice('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> ' . wpml_string_wccm_pro('is a required field.') . '', 'error');
                    }
                }
            }
            foreach ($woocommerce->cart->cart_contents as $key => $values) {
                $multiproductsx = isset($btn['single_p']) ? $btn['single_p'] : '';
                $show_field_single = isset($btn['single_px']) ? $btn['single_px'] : '';
                $multiproductsx_cat = isset($btn['single_p_cat']) ? $btn['single_p_cat'] : '';
                $show_field_single_cat = isset($btn['single_px_cat']) ? $btn['single_px_cat'] : '';
                $productsarraycm[] = $values['product_id'];
                // Products
                // hide field
                // show field without more
                if (!empty($btn['single_px']) && empty($btn['more_content'])) {
                    $show_field_array = explode('||', $show_field_single);
                    if (in_array($values['product_id'], $show_field_array) && count($woocommerce->cart->cart_contents) < 2) {
                        if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                            if (empty($_POST['shipping_' . $btn['cow'] . ''])) {
                                wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                            }
                        }
                    }
                }
                // Category
                // hide field
                $terms = get_the_terms($values['product_id'], 'product_cat');
                if (!empty($terms)) {
                    foreach ($terms as $term) {
                        $categoryarraycm[] = $term->slug;
                        // without more
                        // show field without more
                        if (!empty($btn['single_px_cat']) && empty($btn['more_content'])) {
                            $show_field_array_cat = explode('||', $show_field_single_cat);
                            if (in_array($term->slug, $show_field_array_cat) && count($woocommerce->cart->cart_contents) < 2) {
                                if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                                    if (empty($_POST['shipping_' . $btn['cow'] . ''])) {
                                        wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // end cart
            // ===========================================================================================
            // Products
            // hide field
            // show field with more
            if (!empty($btn['single_px']) && !empty($btn['more_content'])) {
                $show_field_array = explode('||', $show_field_single);
                if (array_intersect($productsarraycm, $show_field_array)) {
                    if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                        if (empty($_POST['shipping_' . $btn['cow'] . ''])) {
                            wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                        }
                    }
                }
            }
            // Category
            // hide field
            // with more
            // show field with more
            if (!empty($btn['single_px_cat']) && !empty($btn['more_content'])) {
                $show_field_array_cat = explode('||', $show_field_single_cat);
                if (array_intersect($categoryarraycm, $show_field_array_cat)) {
                    if (!empty($btn['checkbox']) && !empty($btn['label']) && $btn['type'] !== 'changename') {
                        if (empty($_POST['shipping_' . $btn['cow'] . ''])) {
                            wc_add_notice(__('<strong>' . wpml_string_wccm_pro($btn['label']) . '</strong> is a required field.'), 'error');
                        }
                    }
                }
            }
            $categoryarraycm = '';
            $productsarraycm = '';
        }
    }
}