Bonjour à tous ,

je vais tenter de vous expliquer simplement ce que je souhaiterais faire à partir de 2 plugins wordpress : Woocommerce et Gaugepress.

Je souhaiterais utiliser la valeur d'une variable donné par Woocommerce pour l'utiliser dans Gaugespress :



Woocommerce (script de ecommerce) m'affiche dans la partie admin de mon site tout un ensemble de statistiques et en particulier le nombre total de vente que j'ai réalisé (c'est la valeur de cette variable $order_items qui m'interesse).

Pour cela, il me semble que wordpress utilise la requête sql suivante :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	$order_items = apply_filters( 'woocommerce_reports_sales_overview_order_items', absint( $wpdb->get_var( "
		SELECT SUM( order_item_meta.meta_value )
		FROM {$wpdb->prefix}woocommerce_order_items as order_items
		LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
		LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
		LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID
		LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
		LEFT JOIN {$wpdb->terms} AS term USING( term_id )
		WHERE 	term.slug IN ('" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "')
		AND 	posts.post_status 	= 'publish'
		AND 	tax.taxonomy		= 'shop_order_status'
		AND 	order_items.order_item_type = 'line_item'
		AND 	order_item_meta.meta_key = '_qty'
	" ) ) );





Je souhaiterais donc récuperer la valeur de cette variable $order_items pour l'utiliser afin de déterminer la valeur de la variable $value de Gaugepress.
Je vous mets le script plugin.php de Gaugepress :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
  Plugin Name: GaugePress
  Plugin URI: http://wordpress.org/extend/plugins/gaugepress/
  Author URI: http://www.kouratoras.gr
  Author: Konstantinos Kouratoras
  Contributors: kouratoras
  Tags: gauges,gauge,visualization,metric,bar,counter
  Requires at least: 3.2
  Tested up to: 3.9.1
  Stable tag: 0.3.3
  Version: 0.3.3
  License: GPLv2 or later
  Description: GaugePress is a handy WordPress plugin for generating and animating nice and clean gauges.

  Copyright 2012 Konstantinos Kouratoras (kouratoras@gmail.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
define('GP_PLUGIN_DIR_NAME', 'gaugepress');
 
class GaugePress {
 
	/* -------------------------------------------------- */
	/* Constructor
	  /*-------------------------------------------------- */
 
	public function __construct() {
 
		load_plugin_textdomain('gaugepress', false, plugin_dir_path(__FILE__) . '/lang/');
 
		//Register scripts and styles
		add_action('wp_enqueue_scripts', array(&$this, 'register_plugin_scripts'));
		add_action('wp_enqueue_scripts', array(&$this, 'register_plugin_styles'));
 
		//Shortcode
		require_once( plugin_dir_path(__FILE__) . '/plugin-shortcode.php' );
		new GaugePressShortcode();
	}
 
	/* -------------------------------------------------- */
	/* Registers and enqueues scripts.
	  /* -------------------------------------------------- */
 
	public function register_plugin_scripts() {
 
		wp_enqueue_script('jquery');
 
		wp_register_script('justgage', plugins_url(GP_PLUGIN_DIR_NAME . '/js/justgage.js'), '', '', true);
		wp_enqueue_script('justgage');
 
		wp_register_script('raphael', plugins_url(GP_PLUGIN_DIR_NAME . '/js/raphael.2.1.0.min.js'), '', '', true);
		wp_enqueue_script('raphael');
 
//		wp_register_script('waypoints', plugins_url(GP_PLUGIN_DIR_NAME . '/js/waypoints.min.js'));
//		wp_enqueue_script('waypoints');
	}
 
	/* -------------------------------------------------- */
	/* Registers and enqueues styles.
	  /* -------------------------------------------------- */
 
	public function register_plugin_styles() {
 
	}
 
}
 
new GaugePress();

Je vous joins également le fichier shortcode de Gaugepress :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
 
class GaugePressShortcode {
 
	/**
	 * Constructor
	 */
	public function __construct() {
		add_action('init', array(&$this, 'register_gaugepress_shortcode'));
	}
 
	/**
	 * Registers the shortcode
	 */
	function register_gaugepress_shortcode() {
		add_shortcode('gauge', array(&$this, 'gaugepress_shortcode'));
	}
 
	/**
	 * Creates the shortcode
	 */
	function gaugepress_shortcode($atts) {
 
		$width = (isset($atts['width'])) ? $atts['width'] : '300px';
		$height = (isset($atts['height'])) ? $atts['height'] : '200px';
		$value = (isset($atts['value'])) ? $atts['value'] : '50';
 
		$min = (isset($atts['min'])) ? $atts['min'] : '0';
		$max = (isset($atts['max'])) ? $atts['max'] : '100';
 
		$title = (isset($atts['title'])) ? $atts['title'] : 'The title';
		$label = (isset($atts['label'])) ? $atts['label'] : 'label';
 
		$hideMinMax = (isset($atts['hideminmax'])) ? $atts['hideminmax'] : 'false';
		$counter = (isset($atts['counter'])) ? $atts['counter'] : 'true';
		$decimals = (isset($atts['decimals'])) ? $atts['decimals'] : '0';
		$format = (isset($atts['format'])) ? $atts['format'] : 'true';
 
		$color = (isset($atts['color'])) ? $atts['color'] : '#D26041';
		$levelColorsGradient = 'false';
		if (strpos($color,',') !== false) {
			$color = str_replace(',', '","', $color);
			$levelColorsGradient = 'true';
		}
 
		$backcolor = (isset($atts['backcolor'])) ? $atts['backcolor'] : '#EDEBEB';
		$widthscale = (isset($atts['widthscale'])) ? $atts['widthscale'] : '1';
		$titleFontColor = (isset($atts['titlecolor'])) ? $atts['titlecolor'] : '#000';
		$valueFontColor = (isset($atts['valuecolor'])) ? $atts['valuecolor'] : '#000';
 
		$gid = rand(1, 9999);
 
		$gauge = '<div id="g'.$gid.'" class="gaugePress" style="height:'.$height.';width:'.$width.';"></div>';
 
		$gauge .='<script>

		var g'.$gid.';

		';
 
		$gauge .= '
		var $gp = jQuery.noConflict();
		$gp(function() {
		var g'.$gid.' = new JustGage({
				id: "g'.$gid.'", 
				value: '.$value.', 
				min: '.$min.',
				max: '.$max.',
				title: "'.$title.'", 
				label: "'.$label.'", 
				hideMinMax: '.$hideMinMax.',
				gaugeColor: "'.$backcolor.'",
				levelColors: ["'.$color.'"],
				levelColorsGradient: '.$levelColorsGradient.',
				gaugeWidthScale: '.$widthscale.',
				counter: '.$counter.',
				decimals: '.$decimals.',
				formatNumber: '.$format.',
				titleFontColor: "'.$titleFontColor.'", 
				valueFontColor: "'.$valueFontColor.'",
			});
		});	
		</script>
		';
 
		return $gauge;
	}
 
}