Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter lakewebworks

    (@lakewebworks)

    Follow up: I should have mentioned that I’m using the Divi theme (not sure if that’s relevant). In any case, I couldn’t wait any longer for a reply and figured it must be a stylesheet-related issue (I do see that toolbar.css is loading), so I FTP’d in, located the flag image file, and wrote some CSS to call it as a background image (manageable, since I’ve only got two languages). Here it is in case it’s of benefit to anyone else:

    .tool-items a {
    	background: url(/wp-content/plugins/google-language-translator/images/flags.png) 0px 0px no-repeat;
    }
    .tool-items a.united-states {
    background-position-x: -118px;
      background-position-y: -351px;
    }
    .tool-items a.mexico {
    background-position-x: -118px;
      background-position-y: -438px;
    }
    .tool-item.selected, .tool-item:hover {
    	background: url(/wp-content/plugins/google-language-translator/images/flags.png) 0px 0px no-repeat;
    }

    Thread Starter lakewebworks

    (@lakewebworks)

    Oh, I should add that my shortcode looked like this:

    [wp-shopify collection_id="141421936749" limit="4"]

    Thread Starter lakewebworks

    (@lakewebworks)

    Hi Fahad,

    I’ve never worked with WordPress shortcodes or the Shopify API code before, but I was able to successfully modify your functions.php file to get what I needed. I’m sure you can improve it and extend it to make your plugin better, but this got the job done for me:

    function wpsy_shop_display_shortcode($atts = array(), $content = null, $tag = ''){
    	
    		// normalize attribute keys, lowercase
    		$atts = array_change_key_case((array)$atts, CASE_LOWER);
    		$collection_id = ($atts['collection_id']?$atts['collection_id']:$_GET['collection_id']);
    		$limit = ($atts['limit']?$atts['limit']:$_GET['limit']);
    		
    		$wpsy_db_data = get_option('wpsy_db_data');
    		$url = $wpsy_db_data['wpsy_url'];
    		$api_key = $wpsy_db_data['wpsy_api_key'];
    		$password = $wpsy_db_data['wpsy_password'];
    	
    	   //API URL to get product by ID
    		$requestURL = "https://" . $api_key . ":" . $password . "@" . $url;
    		$requestURL .= '/admin/products.json?collection_id=' . $collection_id;
    		$response = wp_remote_get($requestURL, array(
    		  'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
    		  'body' => null,
    	   ));
    	   //pree($response);
    	   if (is_wp_error($response)) {
    		  $o = wpsy_shop_product_display_get_error(__('Sorry, the site is having a technical difficulty.','wp-shopify').':'  . $response->get_error_message());
    		  return $o;
    	   }  else if (wp_remote_retrieve_response_code( $response ) != 200) {
    		  $o = wpsy_shop_product_display_get_error(__('Sorry, did not get what we expected from the shop.','wp-shopify').':'  . wp_remote_retrieve_response_message( $response )); 
    		  return $o;
    	   }
    	   $response = json_decode(wp_remote_retrieve_body($response));	
    	   ob_start();
    	   if(!empty($response) && isset($response->products)){
    		   
    		   
    	?>
    	<ul class="wp_shopify">
    	<?php	   
    	       $Count = 0;
    		   foreach($response->products as $product_data){
    			   
    			$product_data->price = wpsy_product_price($product_data);
    			$product_url = home_url().'/product/?id='.$product_data->id;
    	?>
    	<li>
    	<a title="<?php echo ucwords($product_data->product_type); ?>" href="<?php echo $product_url; ?>"><img alt="<?php echo $product_data->title; ?>" src="<?php echo $product_data->image->src; ?>" /></a>
    	<a class="ptitle" href="<?php echo $product_url; ?>"><?php echo $product_data->title; ?></a>
    	<strong><?php echo $product_data->price; ?></strong>
    	</li>
    	<?php	
    			$Count++;
    			if ($Count == $limit){
    				break; //stop foreach loop after limit is reached
    			}	
    		   }
    	?>
    	</ul>
    	<p style="clear:both;">The response: <?php //var_dump($response); ?></p>
    	<p>The limit: <?php echo $limit; ?></p>
    	<?php	   
    
    		$o = ob_get_contents();
    		
    		ob_end_clean();
    		   
    	   }
    	   
    	   return $o;
    	}

    There aren’t that many Shopify-WordPress plugins out there, and this did exactly what I wanted (as opposed to the other WPShopify plugin that creates its own cart on the WordPress side and doesn’t let you link over to the product page on your Shopify site). So I think your plugin fills a valuable niche and will be successful if you develop it further. Thanks for your work, it really helped me out… Hope my little modification helps you in turn!

    Thread Starter lakewebworks

    (@lakewebworks)

    Hi Fahad,

    I wanted to follow up to let you know that I looked at the Shopify API and got what I think is a better idea. Since the API supports filtering a product list by collection:

    GET /admin/api/2019-10/products.json?collection_id=841564295

    …I thought it might be worth trying to use your shortcode to pull in a particular collection. That way the content of the set of products could be managed on the Shopify end (i.e., one could create a SMART collection based on a tag, or many other ways).

    I experimented by modifying your functions.php file. For the wpsy_shop_display_shortcode function I modified the request URL to

    /admin/products.json?collection_id=[my collection id number]

    …and it worked fine. So I think if your plugin was extended with a shortcode option that lets one specify a collection number, and a number to limit the number of results, that would work.

    Thanks,
    David

    Thread Starter lakewebworks

    (@lakewebworks)

    That sounds good, thanks. What I’m hoping to do is to display a list of a set of products (so probably this would be a modification of your [wp-shopify] shortcode because it’s a set of products), filtered by tag (so maybe there could be a second attribute to limit the number of products displayed). Thanks for the support!

    Thread Starter lakewebworks

    (@lakewebworks)

    I haven’t tried it in a vanilla installation of WordPress 4.5 yet (i.e, with the 2015 or 2016 theme), but I’m guessing that it’s not so much browser related as perhaps some kind of conflict with how some themes handle jquery. If you compare the markup generated by the shortcode in the two different installs of the site noted in my original post, there’s obviously a huge difference in how the shortcode is getting processed and rendered. I was hoping that might provide a valuable clue as to exactly where in the process the template rendering is breaking down.

Viewing 6 replies - 1 through 6 (of 6 total)