/*
Plugin Name: WooCommerce OLX Integration
Description: Integrate WooCommerce with OLX to automatically post new products as OLX listings.
Version: 2.0.0
Author: Sejkan Design
Author URI: https://sejkan.com
License: Commercial
License URI: https://sejkan.com/licenses
Text Domain: wc-olx-integration
Domain Path: /languages
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
require_once 'includes/authentication.php';
require_once 'includes/listings.php';
require_once 'includes/image-upload.php';
require_once 'includes/olx-refresh.php';
require_once 'includes/authpage.php';
require_once 'includes/olx-attributes.php';
require_once 'includes/olx-bulk-edit.php';
require_once 'includes/mapiranje.php';
require_once 'includes/delete.php';
require_once 'includes/license.php';
// Ensure the function is declared only once
if (!function_exists('sync_product_to_olx')) {
function sync_product_to_olx($post_id) {
// Check license before proceeding
if (!wc_olx_check_license()) {
olx_integration_log('License not valid, skipping OLX sync');
return;
}
$product = wc_get_product($post_id);
if (!$product) {
olx_integration_log('No product found for post ID ' . $post_id);
return;
}
$olx_flag = get_post_meta($post_id, '_olx', true);
olx_integration_log('OLX Listing Flag: ' . $olx_flag);
// Check if the product is marked to be removed from OLX
if ($olx_flag === 'NE') {
delete_olx_listing($post_id);
return;
}
// Check if the product is marked for OLX listing
if ($olx_flag !== 'DA') {
olx_integration_log('Product not marked for OLX listing, skipping...');
return;
}
// Extract product details
$title = $product->get_name();
$description = $product->get_description();
$short_description = $product->get_short_description();
$price = $product->get_price();
$location_lat = get_post_meta($post_id, '_olx_location_lat', true);
$location_lon = get_post_meta($post_id, '_olx_location_lon', true);
$category_id = get_post_meta($post_id, '_olx_category_id', true);
// Create or update OLX listing
$listing_data = create_olx_listing($title, $description, $short_description, $price, $location_lat, $location_lon, $category_id, $post_id);
if (is_wp_error($listing_data)) {
olx_integration_log('Error creating OLX listing: ' . $listing_data->get_error_message());
return;
}
if ($listing_data && isset($listing_data['id'])) {
$olx_listing_id = $listing_data['id'];
$olx_url = "https://olx.ba/artikal/{$olx_listing_id}";
$message = "OLX listing created/updated with ID: {$olx_listing_id}. View Listing ";
olx_integration_log($message);
} else {
olx_integration_log('Failed to create/update OLX listing, no ID returned.');
}
}
function delete_olx_listing($post_id) {
$post_type = get_post_type($post_id);
if ($post_type !== 'product') {
return; // Exit if not a product
}
$olx_listing_id = get_post_meta($post_id, '_olx_listing_id', true);
if ($olx_listing_id) {
$token = get_olx_token();
if (!$token) {
olx_integration_log('No token, cannot delete OLX listing.');
return;
}
$url = "https://api.olx.ba/listings/{$olx_listing_id}";
$response = wp_remote_request($url, array(
'method' => 'DELETE',
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $token
)
));
olx_integration_log('Deleting OLX listing with ID: ' . $olx_listing_id);
if (is_wp_error($response)) {
olx_integration_log('Error deleting OLX listing: ' . $response->get_error_message());
return;
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
olx_integration_log('OLX delete response: ' . print_r($data, true));
if (isset($data['message']) && $data['message'] === 'Uspješno ste izbrisali oglas') {
olx_integration_log('OLX listing deleted successfully with ID: ' . $olx_listing_id);
delete_post_meta($post_id, '_olx_listing_id');
set_transient('_olx_message_' . $post_id, 'Successfully deleted OLX listing.', 30);
// Delete from custom table
global $wpdb;
$table_name = $wpdb->prefix . 'olx_integration';
$wpdb->delete($table_name, array('product_id' => $post_id), array('%d'));
} else {
olx_integration_log('Failed to delete OLX listing.');
}
}
}
}
// Check if license is valid before proceeding
function wc_olx_check_license() {
$license_manager = WC_OLX_License::get_instance();
return $license_manager->is_license_valid();
}
// Hook into product save
add_action('save_post_product', 'sync_product_to_olx', 20, 1);
// Hook into product price update
add_action('woocommerce_product_set_price', 'sync_product_to_olx', 20, 1);
// Hook into product stock update
add_action('woocommerce_product_set_stock', 'sync_product_to_olx', 20, 1);
// Hook into product deletion
add_action('before_delete_post', 'delete_olx_listing');
// Hook into post meta update for custom meta fields (if needed)
add_action('updated_post_meta', 'sync_product_to_olx_meta', 10, 4);
add_action('added_post_meta', 'sync_product_to_olx_meta', 10, 4);
add_action('deleted_post_meta', 'sync_product_to_olx_meta', 10, 4);
function sync_product_to_olx_meta($meta_id, $post_id, $meta_key, $meta_value) {
$relevant_meta_keys = array('_olx_category_id', '_olx_location_lat', '_olx_location_lon', '_olx_attribute_');
foreach ($relevant_meta_keys as $key) {
if (strpos($meta_key, $key) !== false) {
sync_product_to_olx($post_id);
break;
}
}
}
function olx_admin_notices() {
global $post;
if (isset($post->ID)) {
$message = get_transient('_olx_message_' . $post->ID);
if ($message) {
echo '
' . wp_kses_post($message) . '
';
delete_transient('_olx_message_' . $post->ID);
}
}
}
add_action('admin_notices', 'olx_admin_notices');
register_activation_hook(__FILE__, 'create_olx_integration_table');
function create_olx_integration_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'olx_integration';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
product_id bigint(20) NOT NULL,
olx_listing_id bigint(20) DEFAULT NULL,
olx_url text DEFAULT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY product_id (product_id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
function insert_or_update_olx_data($product_id, $olx_listing_id, $olx_url) {
global $wpdb;
$table_name = $wpdb->prefix . 'olx_integration';
$existing_record = $wpdb->get_var($wpdb->prepare("SELECT id FROM $table_name WHERE product_id = %d", $product_id));
if ($existing_record) {
$wpdb->update(
$table_name,
array(
'olx_listing_id' => $olx_listing_id,
'olx_url' => $olx_url,
'updated_at' => current_time('mysql')
),
array('product_id' => $product_id),
array(
'%d',
'%s',
'%s'
),
array('%d')
);
} else {
$wpdb->insert(
$table_name,
array(
'product_id' => $product_id,
'olx_listing_id' => $olx_listing_id,
'olx_url' => $olx_url,
'created_at' => current_time('mysql'),
'updated_at' => current_time('mysql')
),
array(
'%d',
'%d',
'%s',
'%s',
'%s'
)
);
}
}
// Add custom bulk actions to WooCommerce products
add_filter('bulk_actions-edit-product', 'register_custom_bulk_actions');
function register_custom_bulk_actions($bulk_actions) {
$bulk_actions['delete_olx_listings'] = __('Delete OLX Listings', 'woocommerce');
return $bulk_actions;
}
Printer za naljepnice BROTHER PT-D210 - ABC Shop
Početna Printer za naljepnice BROTHER PT-D210
Nema na stanju Printer za naljepnice BROTHER PT-D210 Brother 24 mjeseca
91,00 KM 107,79 KM Ušteda: 16,00 KM (16%)
Nema na zalihi
Proizvod trenutno nije dostupan.
Kratki opis SAŽETAK Kompaktan printer za naljepnice koji je brz i jednostavan za korištenje. Izradite ukrasne naljepnice s raznim uzorcima pomocu ugradenih predložaka putem grafickog zaslona jednostavnog za citanje. Ispisuje naljepnice širine do 12 mm. Kompaktan i lagan. Znacajke jednostavne za korištenje. Brojni fontovi, okviri i simboli. Ugradeni rezac za naljepnice. Organizujte svoje radno mjesto - jasno oznacite važne stvari s naljepnicama Brotherovog pisaca P-touch. Takoder ukljucuje kasetu s trakom širine 12 mm (ispis crno na bijelom).
Show More
Opisi
Specifikacije https://www.brother.hr/labelling-and-receipts/pt-d210
Tehnologija ispisa Termalni
Vrsta printera Prenosni
Brzina printanja 20mm/sek
Automatski rezač Ne
Dimenzije (Š x D x V) 157 x 149 x 68 mm
Težina 0,49 kg
Garancija (mj) 24 mjeseca
Recenzije
Ocjena
Napiši komentar za ovaj proizvod
Podijeli utiske sa drugim kupcima
Napiši recenziju
Trenutno nema proizvoda
Recenzije
Trenutno nema recenzija.