Skip to content

Commit

Permalink
Add Support for woocommerce
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunu-de committed Jun 11, 2024
1 parent ff64c72 commit 87d6662
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/classes/class.tc-pos-ticket-template.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct() {

public function add_pos_ticket_template_field($fields) {
$fields[] = array(
'field_name' => 'ticket_template_POS',
'field_name' => '_ticket_pos_template',
'field_title' => __('POS Ticket template', 'tc'),
'field_type' => 'function',
'function' => array($this, 'tc_get_ticket_templates_POS'),
Expand Down
Empty file modified includes/classes/class.updater.php
100644 → 100755
Empty file.
47 changes: 47 additions & 0 deletions includes/classes/class.wo-pos-ticket-template.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
if ( ! class_exists( 'WooCommerce_Tickera_Bridge_Extend' ) ) {

class WooCommerce_Tickera_Bridge_Extend {

public function __construct() {
add_action( 'woocommerce_product_options_general_product_data', array( $this, 'add_pos_ticket_template_field' ) );
add_action( 'woocommerce_process_product_meta', array( $this, 'save_pos_ticket_template_field' ) );
}

public function add_pos_ticket_template_field() {
echo '<div class="options_group show_if_tc_ticket">' ;
woocommerce_wp_select( [
'id' => '_ticket_pos_template',
'label' => __( 'POS Ticket Template', 'woocommerce-tickera-bridge-extend' ),
'options' => $this->get_ticket_templates_array(),
'desc_tip' => 'true',
'description' => __( 'Select how the POS ticket will look.', 'woocommerce-tickera-bridge-extend' ),
] );
echo '<div class="options_group"></div>' ;
}

public function save_pos_ticket_template_field( $post_id ) {

$post_id = (int) $post_id;
// Check if product is a ticket
$_tc_is_ticket = ( isset( $_POST['_tc_is_ticket'] ) ? 'yes' : 'no' );

if ( 'yes' == $_tc_is_ticket ) {
// Save choosen ticket template
$ticket_pos_template = isset( $_POST['_ticket_pos_template'] ) ? sanitize_text_field( $_POST['_ticket_pos_template'] ) : '';
update_post_meta( $post_id, '_ticket_pos_template', $ticket_pos_template );
} else {
delete_post_meta( $post_id, '_ticket_pos_template' );
}
}

private function get_ticket_templates_array() {
// Assuming tc_get_ticket_templates_array is a function that returns an array of ticket templates
if ( function_exists( 'tc_get_ticket_templates_array' ) ) {
return tc_get_ticket_templates_array();
} else {
return array(); // Return an empty array if the function does not exist
}
}
}
}
13 changes: 10 additions & 3 deletions tickera-order-ticket-fetcher-addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: A Tickera addon for querying ticket instances based on order information.
* Author: Distool.de
* Author URI: https://github.com/distool-de/
* Version: 0.8.8
* Version: 0.9.0
* Text Domain: tcotf
* Update URI: https://github.com/distool-de/Tickera-Order-Ticket-Fetcher-Addon/
*/
Expand All @@ -17,6 +17,12 @@

// Add Updater
include_once( plugin_dir_path( __FILE__ ) . 'includes/classes/class.updater.php' );

require_once plugin_dir_path( __FILE__ ) . 'includes/classes/class.wo-pos-ticket-template.php';

// Instantiate the class
new WooCommerce_Tickera_Bridge_Extend();

// Include the POS Ticket Template class
require_once plugin_dir_path(__FILE__) . 'includes/classes/class.tc-pos-ticket-template.php';

Expand Down Expand Up @@ -55,7 +61,7 @@ function get_ticket_instances_from_orderid() {
foreach ( $ticket_instances as $ticket_instance ) {
$ticket_id = $ticket_instance->ID;
$ticket_type_id = get_post_meta( $ticket_id, 'ticket_type_id', true );
$ticket_template_POS = get_post_meta( $ticket_type_id, 'ticket_template_POS', true );
$ticket_template_POS = get_post_meta( $ticket_type_id, '_ticket_pos_template', true );

$response[] = array(
'ticket_id' => $ticket_id,
Expand All @@ -73,4 +79,5 @@ function get_ticket_instances_from_orderid() {
}
}
}
?>

?>

0 comments on commit 87d6662

Please sign in to comment.