Example #1
0
 /**
  * Adds Jigoshop menus.
  */
 public function beforeMenu()
 {
     $menu = $this->wp->getMenu();
     if ($this->wp->currentUserCan('manage_jigoshop')) {
         $menu[54] = array('', 'read', 'separator-jigoshop', '', 'wp-menu-separator jigoshop');
     }
     $this->wp->addMenuPage(__('Jigoshop'), __('Jigoshop'), 'manage_jigoshop', 'jigoshop', array($this->dashboard, 'display'), null, 55);
     foreach ($this->pages['jigoshop'] as $page) {
         /** @var $page PageInterface */
         $this->wp->addSubmenuPage(self::MENU, $page->getTitle(), $page->getTitle(), $page->getCapability(), $page->getMenuSlug(), array($page, 'display'));
     }
     foreach ($this->pages['products'] as $page) {
         /** @var $page PageInterface */
         $this->wp->addSubmenuPage('edit.php?post_type=' . Types::PRODUCT, $page->getTitle(), $page->getTitle(), $page->getCapability(), $page->getMenuSlug(), array($page, 'display'));
     }
     foreach ($this->pages['orders'] as $page) {
         /** @var $page PageInterface */
         $this->wp->addSubmenuPage('edit.php?post_type=' . Types::ORDER, $page->getTitle(), $page->getTitle(), $page->getCapability(), $page->getMenuSlug(), array($page, 'display'));
     }
     $this->wp->doAction('jigoshop\\admin\\before_menu');
 }
Example #2
0
    /**
     * Displays Google Analytics tracking code in the header as the LAST item before closing </head> tag
     */
    public function googleAnalyticsTracking()
    {
        // Do not track admin pages
        if ($this->wp->isAdmin()) {
            return;
        }
        // Do not track shop owners
        if ($this->wp->currentUserCan('manage_jigoshop')) {
            return;
        }
        $trackingId = $this->options->get('advanced.integration.google_analytics');
        if (empty($trackingId)) {
            return;
        }
        $userId = '';
        if ($this->wp->isUserLoggedIn()) {
            $userId = $this->wp->getCurrentUserId();
        }
        ?>
		<script type="text/javascript">
			(function(i, s, o, g, r, a, m) {
				i['GoogleAnalyticsObject'] = r;
				i[r] = i[r] || function() {
						(i[r].q = i[r].q || []).push(arguments)
					}, i[r].l = 1 * new Date();
				a = s.createElement(o),
					m = s.getElementsByTagName(o)[0];
				a.async = 1;
				a.src = g;
				m.parentNode.insertBefore(a, m)
			})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'jigoshopGoogleAnalytics');
			jigoshopGoogleAnalytics('create', '<?php 
        echo $trackingId;
        ?>
', {'userId': '<?php 
        echo $userId;
        ?>
'});
			jigoshopGoogleAnalytics('send', 'pageview');
		</script>
		<?php 
    }
Example #3
0
    /**
     * Displays Google Analytics eCommerce tracking code to add order data.
     */
    function googleAnalyticsTracking()
    {
        // Do not track admin pages
        if ($this->wp->isAdmin()) {
            return;
        }
        // Do not track shop owners
        if ($this->wp->currentUserCan('manage_jigoshop')) {
            return;
        }
        $trackingId = $this->options->get('advanced.integration.google_analytics');
        if (empty($trackingId)) {
            return;
        }
        /** @var Order $order */
        $order = $this->orderService->find((int) $_REQUEST['order']);
        if ($order->getKey() != $_REQUEST['key']) {
            return;
        }
        ?>
		<script type="text/javascript">
			jigoshopGoogleAnalytics('require', 'ecommerce');
			jigoshopGoogleAnalytics('ecommerce:addTransaction', {
				'id': '<?php 
        echo $order->getNumber();
        ?>
', // Transaction ID. Required.
				'affiliation': '<?php 
        bloginfo('name');
        ?>
', // Affiliation or store name.
				'revenue': '<?php 
        echo $order->getTotal();
        ?>
', // Grand Total.
				'shipping': '<?php 
        echo $order->getShippingPrice();
        ?>
', // Shipping.
				'tax': '<?php 
        echo $order->getTotalTax();
        ?>
' // Tax.
			});
			<?php 
        foreach ($order->getItems() as $item) {
            /** @var $item Order\Item */
            ?>
			<?php 
            $product = $item->getProduct();
            if ($product instanceof Product\Variable) {
                $variation = $product->getVariation($item->getMeta('variation_id')->getValue());
            }
            ?>
			jigoshopGoogleAnalytics('ecommerce:addItem', {
				'id': '<?php 
            echo $order->getNumber();
            ?>
', // Transaction ID. Required.
				'name': '<?php 
            echo $item->getName();
            ?>
', // Product name. Required.
				'sku': '<?php 
            echo $product->getSku();
            ?>
', // SKU/code.
				'category': '<?php 
            if (isset($variation)) {
                echo $variation->getTitle();
            }
            ?>
', // Category or variation.
				'price': '<?php 
            echo $item->getPrice();
            ?>
', // Unit price.
				'quantity': '<?php 
            echo $item->getQuantity();
            ?>
' // Quantity.
			});
			<?php 
        }
        ?>
			jigoshopGoogleAnalytics('ecommerce:send');
		</script>
		<?php 
    }