id = 'xc_woo_cloud';
$this->label = _x( 'Cloud Print Options', 'Settings tab label', XC_WOO_CLOUD );
add_filter( 'woocommerce_settings_tabs_array', array( &$this,"add_settings_tab"), 50 );
add_action( 'woocommerce_settings_'. $this->id, array( &$this,"settings_tab"));
add_action( 'woocommerce_update_options_'. $this->id, array( &$this,"update_settings") );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_admin_field_image', array(&$this,'output_image_field') );
//add_action( 'admin_print_footer_scripts', array(&$this,'admin_add_wysiwyg_custom_field_textarea'), 99 );
add_action( 'woocommerce_admin_field_texteditor', array(&$this,'output_texteditor_field') );
add_action( 'woocommerce_admin_field_xc_printer_selector', array(&$this, 'xc_printer_selector_field'));
add_action( 'woocommerce_admin_field_xc_system_status', array(&$this, 'xc_system_status_field'));
}
/**
* Add a new settings tab to the WooCommerce settings tabs array.
*
* @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
* @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
*/
public function add_settings_tab( $settings_tabs ) {
$settings_tabs[$this->id] = $this->label;
return $settings_tabs;
}
public function output_sections() {
global $current_section;
$sections = $this->get_sections();
if ( empty( $sections ) || 1 === sizeof( $sections ) ) {
return;
}
echo '
';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label ) {
echo '- ' . $label . ' ' . ( end( $array_keys ) == $id ? '' : '|' ) . '
';
}
echo '
';
}
public function get_sections() {
$sections = array(
'' => __( 'General options', XC_WOO_CLOUD ),
'invoice' => __( 'Invoice options', XC_WOO_CLOUD ),
'packing-slip' => __( 'Packing Slip options', XC_WOO_CLOUD ),
'system-status' => __( 'System Status', XC_WOO_CLOUD ),
);
$sections = apply_filters("xc_woo_cloud_print_settings_sections",$sections);
return $sections;
}
/**
* Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
*
* @uses woocommerce_admin_fields()
* @uses self::get_settings()
*/
public function settings_tab() {
global $current_section;
woocommerce_admin_fields( $this->get_settings($current_section) );
}
/**
* Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
*
* @uses woocommerce_update_options()
* @uses self::get_settings()
*/
public function update_settings() {
global $current_section;
woocommerce_update_options( $this->get_settings($current_section) );
}
public function paper_sizes(){
$data = array(
"A1"=>"A1 (594 x 841 mm)",
"A2"=>"A2 (420 x 594 mm)",
"A3"=>"A3 (297 x 420 mm)",
"A4"=>"A4 (210 x 297 mm)",
"A5"=>"A5 (148 x 210 mm)",
"A6"=>"A6 (105 x 148 mm)",
"A7"=>"A7 (74 x 105 mm)",
"A8"=>"A8 (52 x 74 mm)",
"LETTER" => "Letter (216 x 279 mm)",
);
$data = apply_filters("xc_woo_paper_sizes",$data);
return $data;
}
public function get_orders(){
$args = array(
'numberposts' => 10,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
);
$data = array();
$args = apply_filters("xc_woo_get_orders_for_sample_print_args",$args);
$orders = get_posts( $args );
foreach($orders as $order){
$_order = new WC_Order($order->ID);
if($_order->get_customer_id() > 0){
$customer = get_userdata($_order->get_customer_id());
$c_email = $customer->data->user_email;
$c_name = $customer->data->user_login;
}else{
$c_name = $_order->get_billing_first_name();
$c_email = $_order->get_billing_email();
}
$order_number = $_order->get_order_number();
$data[$order->ID] = __("Order #",XC_WOO_CLOUD).$order_number.__(" by ",XC_WOO_CLOUD).$c_name." ".$c_email;
}
return $data;
}
function get_available_payment_methods(){
$available_gateways = WC()->payment_gateways->payment_gateways();
$methods = array();
foreach($available_gateways as $v){
if($v->enabled == 'yes'){
$methods[$v->id] =$v->title;
}
}
return $methods;
}
/**
* Get all the settings for this plugin for @see woocommerce_admin_fields() function.
*
* @return array Array of settings for @see woocommerce_admin_fields() function.
*/
public function get_settings($current_section = '') {
$settings = array();
$id = $this->id."_".$current_section;
//$printers = get_xc_cloud_printers();
if($current_section == ''){
$id = $this->id;
$settings = array(
'section_title' => array(
'name' => __( 'Shop Details', XC_WOO_CLOUD ),
'type' => 'title',
'desc' => '',
'id' => $id.'_section_title'
),
'use_printnode' => array(
'name' => __( 'Use PrintNode', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Plugin will use PrintNode service insted of Google Cloud Print service', XC_WOO_CLOUD ),
'id' => $id.'_use_printnode'
),
'paper_size' => array(
'name' => __( 'Paper Size', XC_WOO_CLOUD ),
'type' => 'select',
'default' => 'A4',
'css' => 'width:150px',
'desc_tip' => __( 'Select Printer paper size', XC_WOO_CLOUD ),
'options' => $this->paper_sizes(),
'id' => $id.'_paper_size'
),
'paper_orientation' => array(
'name' => __( 'Paper Orientation', XC_WOO_CLOUD ),
'type' => 'select',
'default' => 'portrait',
'css' => 'width:150px',
'desc_tip' => __( 'Select Printer paper orientation', XC_WOO_CLOUD ),
'options' => array("portrait"=>"Portrait","landscape"=>"Landscape"),
'id' => $id.'_paper_orientation'
),
'payment_check' => array(
'name' => __( 'Only Print After Payment', XC_WOO_CLOUD ),
'type' => 'multiselect',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'Select Payment gateways (these payment gateway orders will print after payment complete. remaining orders will print when order placed) leave blank if you need to print every order when order placed.', XC_WOO_CLOUD ),
'options' => $this->get_available_payment_methods(),
'id' => $id.'_payment_check'
),
'sample_order' => array(
'name' => __( 'Sample Order', XC_WOO_CLOUD ),
'type' => 'select',
'default' => '',
'css' => 'width:250px',
'desc_tip' => __( 'Select Order for samples (sample invoices and sample packing slips)', XC_WOO_CLOUD ),
'options' => $this->get_orders(),
'id' => $id.'_sample_order'
),
'logo' => array(
'name' => __( 'Header Logo', XC_WOO_CLOUD ),
'type' => 'image',
'desc' => __( 'Header Logo', XC_WOO_CLOUD ),
'id' => $id.'_logo'
),
'title' => array(
'name' => __( 'Shop Name', XC_WOO_CLOUD ),
'type' => 'text',
'desc' => __( 'Shop Name', XC_WOO_CLOUD ),
'class' => 'input-text regular-input ',
'id' => $id.'_shop_name'
),
'address' => array(
'name' => __( 'Shop Address', XC_WOO_CLOUD ),
'type' => 'textarea',
'desc' => __( 'Shop Address',XC_WOO_CLOUD ),
'custom_attributes' => array("rows"=>10,"cols"=>100),
'id' => $id.'_shop_address'
),
'footer' => array(
'name' => __( 'Footer', XC_WOO_CLOUD ),
'type' => 'textarea',
'desc_tip' => __( 'terms & conditions, policies, etc. avalable placeholders {billing_first_name} , {billing_last_name}, {order_number} , {order_total}, {site_title}' ),
'custom_attributes' => array("rows"=>6,"cols"=>100),
'id' => $id.'_footer'
),
'enable' => array(
'name' => __( 'Enable/Disable', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Enable Printing Logs', XC_WOO_CLOUD ),
'id' => $id.'_enable_logs'
),
'section_end' => array(
'type' => 'sectionend',
'id' => $id.'_section_end'
)
);
}
if($current_section == 'invoice'){
$settings = array(
'section_title' => array(
'name' => __( 'Invoice Options', XC_WOO_CLOUD ),
'type' => 'title',
'desc' => "".__("Invoice Preview",XC_WOO_CLOUD)." | ".__("Print a Sample",XC_WOO_CLOUD)." ",
'id' => $id.'_section_title'
),
'enable' => array(
'name' => __( 'Enable/Disable', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Enable Invoice Printing', XC_WOO_CLOUD ),
'id' => $id.'_enable'
),
'skip_autoprint' => array(
'name' => __( 'Skip Auto Print', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Skip Automatic Invoice Printing, Only Print Manually', XC_WOO_CLOUD ),
'id' => $id.'_skip_autoprint'
),
array(
'title' => __( 'Select Printers ', XC_WOO_CLOUD ),
'desc_tip' => __( 'Selectt printers to print invoice', XC_WOO_CLOUD ),
'id' => $id.'_printers',
'type' => 'xc_printer_selector',
'placeholder' => __( 'N/A', XC_WOO_CLOUD ),
'default' => array(
'printerid' => '',
'size' => '',
'orientation' => '',
'copies' => '1',
),
'value' => '',
'autoload' => false,
),
'invoice-copies' => array(
'name' => __( 'Number of copies to print', XC_WOO_CLOUD ),
'type' => 'select',
'default' => '1',
'css' => 'width:150px',
'desc_tip' => __( 'Select number of invoice copies to print through google cloud print', XC_WOO_CLOUD ),
'options' => array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10),
'id' => $id.'_copies'
),
'shipping_billing_layout' => array(
'name' => __( 'Billing and Shipping Address Layout', XC_WOO_CLOUD ),
'type' => 'select',
'default' => 'billing-shipping',
'desc_tip' => __( 'Billing and shipping address order in Invoice', XC_WOO_CLOUD ),
'options' => array("billing-shipping" => __("Billing Address + Shipping Address",XC_WOO_CLOUD),
"shipping-billing" => __("Shipping Address + Billing Address",XC_WOO_CLOUD)),
'id' => $id.'_shipping_billing_layout'
),
'shipping_address' => array(
'name' => __( 'Display shipping address', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display shipping address (in addition to the default billing address) if different from billing address', XC_WOO_CLOUD ),
'id' => $id.'_show_shipping_address'
),
'shipping_method' => array(
'name' => __( 'Display Shipping Method', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display Shipping Method', XC_WOO_CLOUD ),
'id' => $id.'_show_shipping_method'
),
'email' => array(
'name' => __( 'Display email address', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display email address', XC_WOO_CLOUD ),
'id' => $id.'_show_email'
),
'phone' => array(
'name' => __( 'Display phone number', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display phone number', XC_WOO_CLOUD ),
'id' => $id.'_show_phone_number'
),
'barcode' => array(
'name' => __( 'Display Barcode', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display Barcode', XC_WOO_CLOUD ),
'id' => $id.'_show_barcode'
),
'section_end' => array(
'type' => 'sectionend',
'id' => $id.'_section_end'
)
);
}
if($current_section == 'packing-slip'){
$settings = array(
'section_title' => array(
'name' => __( 'Packing Slip options', XC_WOO_CLOUD ),
'type' => 'title',
'desc' => "".__("Packing Slip Preview",XC_WOO_CLOUD)." | ".__("Print a Sample ",XC_WOO_CLOUD)."",
'id' => $id.'_section_title'
),
'enable' => array(
'name' => __( 'Enable/Disable', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Enable Packing Slip Printing', XC_WOO_CLOUD ),
'id' => $id.'_enable'
),
'skip_autoprint' => array(
'name' => __( 'Skip Auto Print', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Skip Automatic Packing Slip Printing, Only Print Manually', XC_WOO_CLOUD ),
'id' => $id.'_skip_autoprint'
),
array(
'title' => __( 'Select Printers ', XC_WOO_CLOUD ),
'desc_tip' => __( 'Selectt printers to print packing-slips', XC_WOO_CLOUD ),
'id' => $id.'_printers',
'type' => 'xc_printer_selector',
'placeholder' => __( 'N/A', XC_WOO_CLOUD ),
'default' => array(
'printerid' => '',
'size' => '',
'orientation' => '',
'copies' => '1',
),
'value' => '',
'autoload' => false,
),
'packing-slip-copies' => array(
'name' => __( 'Number of copies to print', XC_WOO_CLOUD ),
'type' => 'select',
'default' => '1',
'css' => 'width:150px',
'desc_tip' => __( 'Select number of packing slip copies to print through google cloud print', XC_WOO_CLOUD ),
'options' => array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10),
'id' => $id.'_copies'
),
'shipping_billing_layout' => array(
'name' => __( 'Billing and Shipping Address Layout', XC_WOO_CLOUD ),
'type' => 'select',
'default' => 'shipping-billing',
'desc_tip' => __( 'Billing and shipping address order in Invoice', XC_WOO_CLOUD ),
'options' => array("billing-shipping" => __("Billing Address + Shipping Address",XC_WOO_CLOUD),
"shipping-billing" => __("Shipping Address + Billing Address",XC_WOO_CLOUD)),
'id' => $id.'_shipping_billing_layout'
),
'billing_address' => array(
'name' => __( 'Display Billing address', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display billing address (in addition to the default shipping address) if different from shipping address', XC_WOO_CLOUD ),
'id' => $id.'_show_billing_address'
),
'payment_method' => array(
'name' => __( 'Display Payment Method', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display Payment Method', XC_WOO_CLOUD ),
'id' => $id.'_show_payment_method'
),
'email' => array(
'name' => __( 'Display email address', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display email address', XC_WOO_CLOUD ),
'id' => $id.'_show_email'
),
'phone' => array(
'name' => __( 'Display phone number', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display phone number', XC_WOO_CLOUD ),
'id' => $id.'_show_phone_number'
),
'barcode' => array(
'name' => __( 'Display Barcode', XC_WOO_CLOUD ),
'type' => 'checkbox',
'default' => 'no',
'desc' => __( 'Display Barcode', XC_WOO_CLOUD ),
'id' => $id.'_show_barcode'
),
'section_end' => array(
'type' => 'sectionend',
'id' => $id.'_section_end'
)
);
}
if($current_section == 'system-status'){
$settings = array(
'section_title' => array(
'name' => __( 'Syatem Status', XC_WOO_CLOUD ),
'type' => 'title',
'id' => $id.'_section_title'
),
'enable' => array(
'name' => __( 'Enable/Disable', XC_WOO_CLOUD ),
'type' => 'xc_system_status',
'default' => '',
'desc' => __( 'System Status', XC_WOO_CLOUD ),
'id' => $id.'_system-status'
),
'section_end' => array(
'type' => 'sectionend',
'id' => $id.'_section_end'
)
);
}
$settings = apply_filters("xc_woo_cloud_print_sections_settings",$settings,$current_section,$this->id);
return apply_filters( 'wc_settings_tab_'.$this->id, $settings );
}
public function xc_printer_selector_field_google($value){
$option_value = $this->get_option( $value['id'], $value['default'] );
$description = $value['desc'];
$tooltip_html = $value['desc_tip'];
$tooltip_html = wc_help_tip( $tooltip_html );
$paper_sizes = $this->paper_sizes();
$orientations = array("portrait"=>"Portrait","landscape"=>"Landscape");
$printers = get_xc_cloud_printers();
?>
|
get_error_message());
}elseif (count($printers) == 0) {
echo __('Account either not connected, or no printers available', XC_WOO_CLOUD);
}else{
?>
|
get_option( $value['id'], $value['default'] );
$description = $value['desc'];
$tooltip_html = $value['desc_tip'];
$tooltip_html = wc_help_tip( $tooltip_html );
$paper_sizes = $this->paper_sizes();
$orientations = array("portrait"=>"Portrait","landscape"=>"Landscape");
$printers = get_xc_cloud_printers();
?>
|
get_error_message());
}elseif (count($printers) == 0) {
echo __('Account either not connected, or no printers available', XC_WOO_CLOUD);
}else{
?>
|
|
|
|
|
|
|
|
|
|
|
capabilities;
if (isset($capabilities['papers'])) {
echo $this->_options_selectbox($printer->id, 'papers', $capabilities, __('Papers', XC_WOO_CLOUD), $option_value,esc_attr( $value['id'] ));
}
$capabilities['fit_to_page'] = array('NO_FITTING' => __('No', XC_WOO_CLOUD), 'FIT_TO_PAGE' => __('Yes', XC_WOO_CLOUD));
if (isset($capabilities['fit_to_page'])) {
echo $this->_options_selectbox($printer->id, 'fit_to_page', $capabilities, __('Fit to page', XC_WOO_CLOUD), $option_value,esc_attr( $value['id'] ));
}
?>
|
|
'.htmlspecialchars($title).': ';
$output .= '