Help Center
How can we help? 👋

Woocommerce

Woocommerce Integration

Instant Feedback Installation

  1. Create a folder called sj-wc-instant-feedback
  1. Create a file inside the folder called sj-wc-instant-feedback.php (cannot be word or google doc. Should be notepad file)
  1. Put the following contents inside the file
<?php
/**
 * Plugin Name: Sitejabber
 * Plugin URI: https://www.sitejabber.com
 * Description: Sitejabber instant feedback
 * Version: 1.0
 * Author: Michael Lai
 * Author URI: https://www.sitejabber.com
 */

add_action( 'woocommerce_thankyou', 'sitejabber_instant_feedback' );

if (!function_exists('sitejabber_instant_feedback')) {
function sitejabber_instant_feedback ( $order_id ){
	$order = wc_get_order( $order_id );

	if ($order) {
$products = [];
		$order_items = $order->get_items();
		if (!is_wp_error( $order_items )  && count($order_items)) {
			foreach( $order_items as $item_id => $item ) {
				$product = $item->get_product();
				if($product) {
					$tP = [];
					$image_id  = $product->get_image_id();
					$productLink = $product->get_permalink();
					$tP['title'] = $product->get_name();
					$tP['price'] = $product->price;
					$tP['sku'] = $product->sku ? $product->sku : $product->id;
					$tP['product_link'] = $productLink;
					$tP['images'][] = wp_get_attachment_image_url( $image_id, 'full' );
					$products[] = $tP;
				}
			}
		}
?>


<div class="stjr-instant-feedback"></div><script>document.querySelector("body").addEventListener("STJR.instantFeedbackWidgetLoaded",function(){STJR.setConfig({language:'en',user:{first_name:'<?php echo $order->get_billing_first_name() ?>',last_name:'<?php echo $order->get_billing_last_name() ?>',email:'<?php echo $order->get_billing_email() ?>'},order_id:'<?php echo $order->get_order_number() ?>',order_date:'<?php echo $order->get_date_created() ?>',<?php if(count($products)) { ?> products:<?php echo json_encode($products, true) ?> <?php } ?>})});</script>

<script>(function(d,s,id,c){var js,rC=[],uRC=[],r=0;Array.from(document.querySelectorAll('[class*="stjr-"]')).forEach(r=>{rC=[...rC,...Array.from(r.classList).filter((cl)=>{return /^stjr-/.test(cl);})]});uRC=[...new Set(rC)];t=d.getElementsByTagName(s)[0];js=d.createElement(s);js.id=id;js.src='https://www.sitejabber.com/js/v2/{CLIENT-ID}/widgets.js'+(uRC.length ? '?widget-classes=' + uRC.join("|") : '?widget-classes=stjr-base')+'';js.onload=js.onreadystatechange=function(){if(!r&&(!this.readyState||this.readyState[0]=='c')){r=1;c();}};t.parentNode.insertBefore(js,t);}(document,'script','sj-widget',function(){}));</script>


<?php
        }
    }
}
?>

Please replace {CLIENT-ID} with the Client ID in your dashboard here.

4. Compress the folder into a zip file

5. Go to WooCommerce admin panel

6. Click on plugins

7. Click on add new

8. Click on upload plugin

9. Select the file and upload

10. After uploading click on activate button

Widget Installation

Open the theme file editor :

  1. Login to the Admin dashboard
  1. Navigate to “Appearance”
  1. Go to “Theme File Editor”, it will open file edition on the active theme

Product Review Widgets

Product rating | Product review widget | Product Json

Place in ctive theme’s functions.php file

Below is an example only:

<?php

    /* Sitejabber review widgets related function and short codes  */

    /* short code examples
        [sitejabber_product_rating_widget sku="product-1" group="item_group" group_value="12345" histogram="true"]
        <? echo echo do_shortcode( '[sitejabber_product_rating_widget sku="product-1" group="item_group" group_value="12345" histogram="true"]' ); ?>
    */

    /* rating widget widget */
    /*!
		@param array [
              'sku' => null,
              'group_value'  =>  null,
              'group'  =>  'item_group',
              'histogram' => false
          ]


	*/
    function sitejabber_product_rating_widget($atts) {
          $a = shortcode_atts([
              'sku' => null,
              'group_value'  =>  null,
              'group'  =>  'item_group',
              'histogram' => false
          ], $atts);

          $fieldCode =  1;

          $sku = $a['sku'] ? $a['sku'] :  $fieldCode;

          return ($fieldCode ? '<div class="main-product-rating-widget-' . $a['sku'] . ' ">' : '') . '<div class="stjr-product-rating" ' . ($sku ? 'data-product-id="' . $sku . '"' : '') . (($a['group'] && $a['group_value']) ? 'data-group="' . $a['group'] . '" data-group-value="' . $a['group_value'] . '"' : '') .  ($a['histogram'] ? ' data-hover-histogram="true" ' : '') . ' ></div>' . ($fieldCode ? '</div>' : '');
    }
    add_shortcode('sitejabber_product_rating_widget', 'sitejabber_product_rating_widget');


    /* Review page widget */
    /*!
		@param array [
              'sku' => null,
              'group_value'  =>  null,
              'group'  =>  'item_group'
          ]
        @shortcode [sitejabber_product_review_page_widget sku="product-1" group="item_group" group_value="12345"]
	*/

    function sitejabber_product_review_page_widget($atts) {
          $a = shortcode_atts([
              'sku' => null,
              'group_value'  =>  null,
              'group'  =>  'item_group'
          ], $atts);

          $sku = $a['sku'] ? $a['sku'] :  get_field("code");

          return '<div class="stjr-product-review-page" ' . ($sku ? 'data-product-id="' . $sku . '"' : '') . (($a['group'] && $a['group_value']) ? 'data-group="' . $a['group'] . '" data-group-value="' . $a['group_value'] . '"' : '') . ' ></div>';
    }
    add_shortcode('sitejabber_product_review_page_widget', 'sitejabber_product_review_page_widget');


    /* Product json */
    /*!
		@param array [
              'sku' => null,
          ]
        @shortcode [sitejabber_product_page_json sku="product-1"]
	*/
    function sitejabber_product_page_json($atts) {
        $a = shortcode_atts([
            'sku' => null,
        ], $atts);

        $tP = [];

        if ($a['sku']) {
            $product_id = wc_get_product_id_by_sku($a['sku']);
            if ($product_id) {
                $product = wc_get_product($product_id);
                if ($product) {
                    $tP = [];
                    $image_id  = $product->get_image_id();
                    $productLink = $product->get_permalink();
                    $tP['id'] = $product_id;
                    $tP['title'] = $product->get_name();
                    $tP['price'] = $product->price;
                    $tP['sku'] = $product->sku;
                    $tP['product_link'] = get_permalink($product_id);
                    $tP['images'][] = wp_get_attachment_image_url($image_id, 'full');
                }
            }
            return '<script id="ProductJson-product-template" type="application/json">'.json_encode($tP);.'</script>';
        } else {
            return '';
        }

    }
    add_shortcode('sitejabber_product_page_json', 'sitejabber_product_page_json');

    /* script loader */
    function sitejabber_widget_script_loader() {
        return "<script>(function(d,s,id,c){var js,rC=[],uRC=[],r=0;Array.from(document.querySelectorAll('[class*="stjr-"]')).forEach(r=>{rC=[...rC,...Array.from(r.classList).filter((cl)=>{return /^stjr-/.test(cl);})]});uRC=[...new Set(rC)];t=d.getElementsByTagName(s)[0];js=d.createElement(s);js.id=id;js.src='https://www.sitejabber.com/js/v2/{API-KEY}/widgets.js'+(uRC.length ? '?widget-classes=' + uRC.join("|") : '?widget-classes=stjr-base')+'';js.onload=js.onreadystatechange=function(){if(!r&&(!this.readyState||this.readyState[0]=='c')){r=1;c();}};t.parentNode.insertBefore(js,t);}(document,'script','sj-widget',function(){}));</script>"
    }
    add_shortcode('sitejabber_widget_script_loader', 'sitejabber_widget_script_loader');

?>
Did this answer your question?
😞
😐
🤩