'.__('Settings', 'wownero_gateway').'' ); return array_merge($plugin_links, $links); } add_filter('cron_schedules', 'wownero_cron_add_one_minute'); function wownero_cron_add_one_minute($schedules) { $schedules['one_minute'] = array( 'interval' => 60, 'display' => __('Once every minute', 'wownero_gateway') ); return $schedules; } add_action('wp', 'wownero_activate_cron'); function wownero_activate_cron() { if(!wp_next_scheduled('wownero_update_event')) { wp_schedule_event(time(), 'one_minute', 'wownero_update_event'); } } add_action('wownero_update_event', 'wownero_update_event'); function wownero_update_event() { Wownero_Gateway::do_update_event(); } add_action('woocommerce_thankyou_'.Wownero_Gateway::get_id(), 'wownero_order_confirm_page'); add_action('woocommerce_order_details_after_order_table', 'wownero_order_page'); add_action('woocommerce_email_after_order_table', 'wownero_order_email'); function wownero_order_confirm_page($order_id) { Wownero_Gateway::customer_order_page($order_id); } function wownero_order_page($order) { if(!is_wc_endpoint_url('order-received')) Wownero_Gateway::customer_order_page($order); } function wownero_order_email($order) { Wownero_Gateway::customer_order_email($order); } add_action('wc_ajax_wownero_gateway_payment_details', 'wownero_get_payment_details_ajax'); function wownero_get_payment_details_ajax() { Wownero_Gateway::get_payment_details_ajax(); } add_filter('woocommerce_currencies', 'wownero_add_currency'); function wownero_add_currency($currencies) { $currencies['Wownero'] = __('Wownero', 'wownero_gateway'); return $currencies; } add_filter('woocommerce_currency_symbol', 'wownero_add_currency_symbol', 10, 2); function wownero_add_currency_symbol($currency_symbol, $currency) { switch ($currency) { case 'Wownero': $currency_symbol = 'WOW'; break; } return $currency_symbol; } if(Wownero_Gateway::use_wownero_price()) { // This filter will replace all prices with amount in Wownero (live rates) add_filter('wc_price', 'wownero_live_price_format', 10, 3); function wownero_live_price_format($price_html, $price_float, $args) { $price_float = wc_format_decimal($price_float); if(!isset($args['currency']) || !$args['currency']) { global $woocommerce; $currency = strtoupper(get_woocommerce_currency()); } else { $currency = strtoupper($args['currency']); } return Wownero_Gateway::convert_wc_price($price_float, $currency); } // These filters will replace the live rate with the exchange rate locked in for the order // We must be careful to hit all the hooks for price displays associated with an order, // else the exchange rate can change dynamically (which it should for an order) add_filter('woocommerce_order_formatted_line_subtotal', 'wownero_order_item_price_format', 10, 3); function wownero_order_item_price_format($price_html, $item, $order) { return Wownero_Gateway::convert_wc_price_order($price_html, $order); } add_filter('woocommerce_get_formatted_order_total', 'wownero_order_total_price_format', 10, 2); function wownero_order_total_price_format($price_html, $order) { return Wownero_Gateway::convert_wc_price_order($price_html, $order); } add_filter('woocommerce_get_order_item_totals', 'wownero_order_totals_price_format', 10, 3); function wownero_order_totals_price_format($total_rows, $order, $tax_display) { foreach($total_rows as &$row) { $price_html = $row['value']; $row['value'] = Wownero_Gateway::convert_wc_price_order($price_html, $order); } return $total_rows; } } add_action('wp_enqueue_scripts', 'wownero_enqueue_scripts'); function wownero_enqueue_scripts() { if(Wownero_Gateway::use_wownero_price()) wp_dequeue_script('wc-cart-fragments'); if(Wownero_Gateway::use_qr_code()) wp_enqueue_script('wownero-qr-code', WOWNERO_GATEWAY_PLUGIN_URL.'assets/js/qrcode.min.js'); wp_enqueue_script('wownero-clipboard-js', WOWNERO_GATEWAY_PLUGIN_URL.'assets/js/clipboard.min.js'); wp_enqueue_script('wownero-gateway', WOWNERO_GATEWAY_PLUGIN_URL.'assets/js/wownero-gateway-order-page.js'); wp_enqueue_style('wownero-gateway', WOWNERO_GATEWAY_PLUGIN_URL.'assets/css/wownero-gateway-order-page.css'); } // [wownero-price currency="USD"] // currency: BTC, GBP, etc // if no none, then default store currency function wownero_price_func( $atts ) { global $woocommerce; $a = shortcode_atts( array( 'currency' => get_woocommerce_currency() ), $atts ); $currency = strtoupper($a['currency']); $rate = Wownero_Gateway::get_live_rate($currency); if($currency == 'BTC') $rate_formatted = sprintf('%.8f', $rate / 1e8); else $rate_formatted = sprintf('%.5f', $rate / 1e8); return "1 WOW = $rate_formatted $currency"; } add_shortcode('wownero-price', 'wownero_price_func'); // [wownero-accepted-here] function wownero_accepted_func() { return ''; } add_shortcode('wownero-accepted-here', 'wownero_accepted_func'); } register_deactivation_hook(__FILE__, 'wownero_deactivate'); function wownero_deactivate() { $timestamp = wp_next_scheduled('wownero_update_event'); wp_unschedule_event($timestamp, 'wownero_update_event'); } register_activation_hook(__FILE__, 'wownero_install'); function wownero_install() { global $wpdb; require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); $charset_collate = $wpdb->get_charset_collate(); $table_name = $wpdb->prefix . "wownero_gateway_quotes"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name ( order_id BIGINT(20) UNSIGNED NOT NULL, payment_id VARCHAR(97) DEFAULT '' NOT NULL, currency VARCHAR(6) DEFAULT '' NOT NULL, rate BIGINT UNSIGNED DEFAULT 0 NOT NULL, amount BIGINT UNSIGNED DEFAULT 0 NOT NULL, paid TINYINT NOT NULL DEFAULT 0, confirmed TINYINT NOT NULL DEFAULT 0, pending TINYINT NOT NULL DEFAULT 1, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (order_id) ) $charset_collate;"; dbDelta($sql); } $table_name = $wpdb->prefix . "wownero_gateway_quotes_txids"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, payment_id VARCHAR(97) DEFAULT '' NOT NULL, txid VARCHAR(64) DEFAULT '' NOT NULL, amount BIGINT UNSIGNED DEFAULT 0 NOT NULL, height MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY (payment_id, txid, amount) ) $charset_collate;"; dbDelta($sql); } $table_name = $wpdb->prefix . "wownero_gateway_live_rates"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name ( currency VARCHAR(7) DEFAULT '' NOT NULL, rate BIGINT UNSIGNED DEFAULT 0 NOT NULL, updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (currency) ) $charset_collate;"; dbDelta($sql); } }