Take out default variations #3169

This commit is contained in:
Coen Jacobs 2013-11-01 17:33:33 +01:00
parent 5faf171a48
commit ae64e20bb3
4 changed files with 0 additions and 584 deletions

View File

@ -1,350 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Google Analytics Integration
*
* Allows tracking code to be inserted into store pages.
*
* @class WC_Google_Analytics
* @extends WC_Integration
* @version 1.6.4
* @package WooCommerce/Classes/Integrations
* @author WooThemes
*/
class WC_Google_Analytics extends WC_Integration {
/**
* Init and hook in the integration.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'google_analytics';
$this->method_title = __( 'Google Analytics', 'woocommerce' );
$this->method_description = __( 'Google Analytics is a free service offered by Google that generates detailed statistics about the visitors to a website.', 'woocommerce' );
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->ga_id = $this->get_option( 'ga_id' );
$this->ga_set_domain_name = $this->get_option( 'ga_set_domain_name' );
$this->ga_standard_tracking_enabled = $this->get_option( 'ga_standard_tracking_enabled' );
$this->ga_ecommerce_tracking_enabled = $this->get_option( 'ga_ecommerce_tracking_enabled' );
$this->ga_event_tracking_enabled = $this->get_option( 'ga_event_tracking_enabled' );
// Actions
add_action( 'woocommerce_update_options_integration_google_analytics', array( $this, 'process_admin_options') );
// Tracking code
add_action( 'wp_footer', array( $this, 'google_tracking_code' ) );
add_action( 'woocommerce_thankyou', array( $this, 'ecommerce_tracking_code' ) );
// Event tracking code
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'add_to_cart' ) );
add_action( 'wp_footer', array( $this, 'loop_add_to_cart' ) );
}
/**
* Initialise Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
$this->form_fields = array(
'ga_id' => array(
'title' => __( 'Google Analytics ID', 'woocommerce' ),
'description' => __( 'Log into your google analytics account to find your ID. e.g. <code>UA-XXXXX-X</code>', 'woocommerce' ),
'type' => 'text',
'default' => get_option('woocommerce_ga_id') // Backwards compat
),
'ga_set_domain_name' => array(
'title' => __( 'Set Domain Name', 'woocommerce' ),
'description' => sprintf( __( '(Optional) Sets the <code>_setDomainName</code> variable. <a href="%s">See here for more information</a>.', 'woocommerce' ), 'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#multipleDomains' ),
'type' => 'text',
'default' => ''
),
'ga_standard_tracking_enabled' => array(
'title' => __( 'Tracking code', 'woocommerce' ),
'label' => __( 'Add tracking code to your site\'s footer. You don\'t need to enable this if using a 3rd party analytics plugin.', 'woocommerce' ),
'type' => 'checkbox',
'checkboxgroup' => 'start',
'default' => get_option('woocommerce_ga_standard_tracking_enabled') ? get_option('woocommerce_ga_standard_tracking_enabled') : 'no' // Backwards compat
),
'ga_ecommerce_tracking_enabled' => array(
'label' => __( 'Add eCommerce tracking code to the thankyou page', 'woocommerce' ),
'type' => 'checkbox',
'checkboxgroup' => '',
'default' => get_option('woocommerce_ga_ecommerce_tracking_enabled') ? get_option('woocommerce_ga_ecommerce_tracking_enabled') : 'no' // Backwards compat
),
'ga_event_tracking_enabled' => array(
'label' => __( 'Add event tracking code for add to cart actions', 'woocommerce' ),
'type' => 'checkbox',
'checkboxgroup' => 'end',
'default' => 'no'
)
);
} // End init_form_fields()
/**
* Google Analytics standard tracking
*
* @access public
* @return void
*/
function google_tracking_code() {
global $woocommerce;
if ( is_admin() || current_user_can('manage_options') || $this->ga_standard_tracking_enabled == "no" ) return;
$tracking_id = $this->ga_id;
if ( ! $tracking_id ) return;
$loggedin = ( is_user_logged_in() ) ? 'yes' : 'no';
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
} else {
$user_id = '';
$username = __( 'Guest', 'woocommerce' );
}
if ( ! empty( $this->ga_set_domain_name ) )
$set_domain_name = "['_setDomainName', '" . esc_js( $this->ga_set_domain_name ) . "'],\n";
else
$set_domain_name = '';
echo "<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', '" . esc_js( $tracking_id ) . "'], " . $set_domain_name . "
['_setCustomVar', 1, 'logged-in', '" . $loggedin . "', 1],
['_setCustomVar', 2, 'user-id', '" . $user_id . "', 1],
['_setCustomVar', 3, 'username', '" . $username . "', 1],
['_trackPageview']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>";
}
/**
* Google Analytics eCommerce tracking
*
* @access public
* @param mixed $order_id
* @return void
*/
function ecommerce_tracking_code( $order_id ) {
global $woocommerce;
if ( $this->ga_ecommerce_tracking_enabled == "no" || current_user_can('manage_options') || get_post_meta( $order_id, '_ga_tracked', true ) == 1 )
return;
$tracking_id = $this->ga_id;
if ( ! $tracking_id ) return;
// Doing eCommerce tracking so unhook standard tracking from the footer
remove_action( 'wp_footer', array( $this, 'google_tracking_code' ) );
// Get the order and output tracking code
$order = new WC_Order( $order_id );
$loggedin = is_user_logged_in() ? 'yes' : 'no';
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
} else {
$user_id = '';
$username = __( 'Guest', 'woocommerce' );
}
if ( ! empty( $this->ga_set_domain_name ) )
$set_domain_name = "['_setDomainName', '" . esc_js( $this->ga_set_domain_name ) . "'],";
else
$set_domain_name = '';
$code = "
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', '" . esc_js( $tracking_id ) . "'], " . $set_domain_name . "
['_setCustomVar', 1, 'logged-in', '" . esc_js( $loggedin ) . "', 1],
['_setCustomVar', 2, 'user-id', '" . esc_js( $user_id ) . "', 1],
['_setCustomVar', 3, 'username', '" . esc_js( $username ) . "', 1],
['_trackPageview']
);
_gaq.push(['_addTrans',
'" . esc_js( $order->get_order_number() ) . "', // order ID - required
'" . esc_js( get_bloginfo( 'name' ) ) . "', // affiliation or store name
'" . esc_js( $order->get_total() ) . "', // total - required
'" . esc_js( $order->get_total_tax() ) . "', // tax
'" . esc_js( $order->get_total_shipping() ) . "', // shipping
'" . esc_js( $order->billing_city ) . "', // city
'" . esc_js( $order->billing_state ) . "', // state or province
'" . esc_js( $order->billing_country ) . "' // country
]);
";
// Order items
if ( $order->get_items() ) {
foreach ( $order->get_items() as $item ) {
$_product = $order->get_product_from_item( $item );
$code .= "_gaq.push(['_addItem',";
$code .= "'" . esc_js( $order->get_order_number() ) . "',";
$code .= "'" . esc_js( $_product->get_sku() ? __( 'SKU:', 'woocommerce' ) . ' ' . $_product->get_sku() : $_product->id ) . "',";
$code .= "'" . esc_js( $item['name'] ) . "',";
if ( isset( $_product->variation_data ) ) {
$code .= "'" . esc_js( woocommerce_get_formatted_variation( $_product->variation_data, true ) ) . "',";
} else {
$out = array();
$categories = get_the_terms($_product->id, 'product_cat');
if ( $categories ) {
foreach ( $categories as $category ){
$out[] = $category->name;
}
}
$code .= "'" . esc_js( join( "/", $out) ) . "',";
}
$code .= "'" . esc_js( $order->get_item_total( $item, true, true ) ) . "',";
$code .= "'" . esc_js( $item['qty'] ) . "'";
$code .= "]);";
}
}
$code .= "
_gaq.push(['_trackTrans']); // submits transaction to the Analytics servers
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
";
echo '<script type="text/javascript">' . $code . '</script>';
update_post_meta( $order_id, '_ga_tracked', 1 );
}
/**
* Google Analytics event tracking for single product add to cart
*
* @access public
* @return void
*/
function add_to_cart() {
if ( $this->disable_tracking( $this->ga_event_tracking_enabled ) ) return;
if ( ! is_single() ) return;
global $product;
$parameters = array();
// Add single quotes to allow jQuery to be substituted into _trackEvent parameters
$parameters['category'] = "'" . __( 'Products', 'woocommerce' ) . "'";
$parameters['action'] = "'" . __( 'Add to cart', 'woocommerce' ) . "'";
$parameters['label'] = "'" . esc_js( $product->get_sku() ? __('SKU:', 'woocommerce') . ' ' . $product->get_sku() : "#" . $product->id ) . "'";
$this->event_tracking_code( $parameters, '.single_add_to_cart_button' );
}
/**
* Google Analytics event tracking for loop add to cart
*
* @access public
* @return void
*/
function loop_add_to_cart() {
if ( $this->disable_tracking( $this->ga_event_tracking_enabled ) ) return;
$parameters = array();
// Add single quotes to allow jQuery to be substituted into _trackEvent parameters
$parameters['category'] = "'" . __( 'Products', 'woocommerce' ) . "'";
$parameters['action'] = "'" . __( 'Add to cart', 'woocommerce' ) . "'";
$parameters['label'] = "($(this).data('product_sku')) ? ('SKU: ' + $(this).data('product_sku')) : ('#' + $(this).data('product_id'))"; // Product SKU or ID
$this->event_tracking_code( $parameters, '.add_to_cart_button.product_type_simple' );
}
/**
* Google Analytics event tracking for loop add to cart
*
* @access private
* @param mixed $parameters associative array of _trackEvent parameters
* @param mixed $selector jQuery selector for binding click event
* @return void
*/
private function event_tracking_code( $parameters, $selector ) {
global $woocommerce;
$parameters = apply_filters( 'woocommerce_ga_event_tracking_parameters', $parameters );
wc_enqueue_js("
$('" . $selector . "').click(function() {
" . sprintf( "_gaq.push(['_trackEvent', %s, %s, %s]);", $parameters['category'], $parameters['action'], $parameters['label'] ) . "
});
");
}
/**
* Check if tracking is disabled
*
* @access private
* @param mixed $type
* @return bool
*/
private function disable_tracking( $type ) {
if ( is_admin() || current_user_can( 'manage_options' ) || ( ! $this->ga_id ) || 'no' == $type ) return true;
}
}
/**
* Add the integration to WooCommerce.
*
* @package WooCommerce/Classes/Integrations
* @access public
* @param array $integrations
* @return array
*/
function add_google_analytics_integration( $integrations ) {
$integrations[] = 'WC_Google_Analytics';
return $integrations;
}
add_filter('woocommerce_integrations', 'add_google_analytics_integration' );

View File

@ -1,94 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* ShareDaddy Integration
*
* Enables ShareDaddy integration.
*
* @class WC_ShareDaddy
* @extends WC_Integration
* @version 1.6.4
* @package WooCommerce/Classes/Integrations
* @author WooThemes
*/
class WC_ShareDaddy extends WC_Integration {
/**
* Init and hook in the integration.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'sharedaddy';
$this->method_title = __( 'ShareDaddy', 'woocommerce' );
$this->method_description = __( 'ShareDaddy is a sharing plugin bundled with JetPack.', 'woocommerce' );
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Actions
add_action( 'woocommerce_update_options_integration_sharedaddy', array( $this, 'process_admin_options' ) );
// Share widget
add_action( 'woocommerce_share', array( $this, 'sharedaddy_code' ) );
}
/**
* Initialise Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Output ShareDaddy button?', 'woocommerce' ),
'description' => __( 'Enable this option to show the ShareDaddy button on the product page.', 'woocommerce' ),
'type' => 'checkbox',
'default' => get_option('woocommerce_sharedaddy') ? get_option('woocommerce_sharedaddy') : 'no'
)
);
}
/**
* Output share code.
*
* @access public
* @return void
*/
function sharedaddy_code() {
global $post;
if ( $this->enabled == 'yes' && function_exists('sharing_display') ) {
?><div class="social"><?php echo sharing_display(); ?></div><?php
}
}
}
/**
* Add the integration to WooCommerce.
*
* @package WooCommerce/Classes/Integrations
* @access public
* @param array $integrations
* @return array
*/
function add_sharedaddy_integration( $integrations ) {
if ( class_exists('jetpack') )
$integrations[] = 'WC_ShareDaddy';
return $integrations;
}
add_filter('woocommerce_integrations', 'add_sharedaddy_integration' );

View File

@ -1,135 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* ShareThis Integration
*
* Enables ShareThis integration.
*
* @class WC_ShareThis
* @extends WC_Integration
* @version 1.6.4
* @package WooCommerce/Classes/Integrations
* @author WooThemes
*/
class WC_ShareThis extends WC_Integration {
/** @var string Default code for share this */
var $default_code;
/**
* Init and hook in the integration.
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'sharethis';
$this->method_title = __( 'ShareThis', 'woocommerce' );
$this->method_description = __( 'ShareThis offers a sharing widget which will allow customers to share links to products with their friends.', 'woocommerce' );
$this->default_code = '<div class="social">
<iframe src="https://www.facebook.com/plugins/like.php?href={permalink}&layout=button_count&show_faces=false&width=100&action=like&colorscheme=light&height=21" style="border:none; overflow:hidden; width:100px; height:21px;"></iframe>
<span class="st_twitter"></span><span class="st_email"></span><span class="st_sharethis" st_image="{image}"></span><span class="st_plusone_button"></span>
</div>';
// Load the settings.
$this->init_form_fields();
$this->init_settings();
// Define user set variables
$this->publisher_id = $this->get_option( 'publisher_id' );
$this->sharethis_code = $this->get_option( 'sharethis_code', $this->default_code );
// Actions
add_action( 'woocommerce_update_options_integration_sharethis', array( $this, 'process_admin_options' ) );
// Share widget
add_action( 'woocommerce_share', array( $this, 'sharethis_code' ) );
}
/**
* Validate share this code to allow tags/attributes used by sharethis
* @param string $key
* @return string
*/
public function validate_sharethis_code_field( $key ) {
$text = $this->get_option( $key );
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
$text = trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
}
return $text;
}
/**
* Initialise Settings Form Fields
*
* @access public
* @return void
*/
function init_form_fields() {
$this->form_fields = array(
'publisher_id' => array(
'title' => __( 'ShareThis Publisher ID', 'woocommerce' ),
'description' => sprintf( __( 'Enter your %1$sShareThis publisher ID%2$s to show social sharing buttons on product pages.', 'woocommerce' ), '<a href="http://sharethis.com/account/">', '</a>' ),
'type' => 'text',
'default' => get_option('woocommerce_sharethis')
),
'sharethis_code' => array(
'title' => __( 'ShareThis Code', 'woocommerce' ),
'description' => __( 'You can tweak the ShareThis code by editing this option.', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->default_code
)
);
}
/**
* Output share code.
*
* @access public
* @return void
*/
function sharethis_code() {
global $post;
if ( $this->publisher_id ) {
$thumbnail = ( $thumbnail_id = get_post_thumbnail_id( $post->ID ) ) ? current(wp_get_attachment_image_src( $thumbnail_id, 'large' )) : '';
$sharethis = ( is_ssl() ) ? 'https://ws.sharethis.com/button/buttons.js' : 'http://w.sharethis.com/button/buttons.js';
$sharethis_code = str_replace( '{permalink}', urlencode( get_permalink( $post->ID ) ), $this->sharethis_code );
if ( isset( $thumbnail ) ) $sharethis_code = str_replace( '{image}', urlencode( $thumbnail ), $sharethis_code );
echo str_replace( '&', '&amp;', $sharethis_code );
echo '<script type="text/javascript">var switchTo5x=true;</script><script type="text/javascript" src="' . $sharethis . '"></script>';
echo '<script type="text/javascript">stLight.options({publisher:"' . $this->publisher_id . '"});</script>';
}
}
}
/**
* Add the integration to WooCommerce.
*
* @package WooCommerce/Classes/Integrations
* @access public
* @param array $integrations
* @return array
*/
function add_sharethis_integration( $integrations ) {
$integrations[] = 'WC_ShareThis';
return $integrations;
}
add_filter('woocommerce_integrations', 'add_sharethis_integration' );

View File

@ -306,11 +306,6 @@ final class WooCommerce {
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
include_once( 'includes/class-wc-https.php' ); // https Helper include_once( 'includes/class-wc-https.php' ); // https Helper
// Include Core Integrations - these are included sitewide
include_once( 'includes/integrations/google-analytics/class-wc-google-analytics.php' );
include_once( 'includes/integrations/sharethis/class-wc-sharethis.php' );
include_once( 'includes/integrations/sharedaddy/class-wc-sharedaddy.php' );
// Include template hooks in time for themes to remove/modify them // Include template hooks in time for themes to remove/modify them
include_once( 'includes/wc-template-hooks.php' ); include_once( 'includes/wc-template-hooks.php' );
} }