Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Rustaurius

    (@rustaurius)

    Hi Lee,

    If you’re using the “Pretty Permalinks” option, the variable to get the product slug would be:

    get_query_var('single_product')

    which you would then have to search the products database and match to find the corresponding product ID. Without “Pretty Permalinks”, it would be:

    $_GET['SingleProduct']

    to get the product ID.

    Thread Starter Lee_L

    (@lee_l)

    Isn’t there a memory variable that defined when an individual product is called ?

    Once a user clicks on a product is that (item_id) setup in memory as a variable ?

    Or maybe I am missing that ‘SingleProduct’ is that memory variable you are referring to.

    Just to make sure we are on the same page, the problem I am trying to solve is to link a specific product to a Post or Custom Post which contains a product review. This means I need to pass the product id (item_id) to the Review code if a new review is being stored so it is linked to the correct Review.

    I guess what I am missing is that once I click on an individual product, UPCP already has to know the item_id because I am viewing the product. Is that item_id able to be viewed by either an existing shortcode or by creating my own shortcode using the $_GET function ?

    add_shortcode("product-catalogue", "Insert_Product_Catalog");
    
    function Insert_Minimal_Products($atts) {
    	global $wpdb, $items_table_name, $catalogue_items_table_name;
    
    	// Get the attributes passed by the shortcode, and store them in new variables for processing
    	extract( shortcode_atts( array(
    				"catalogue_url" => "",
    				"product_ids" => "",
    				"catalogue_id" => "",
    				"category_id" => "",
    				"subcategory_id" => "",
    				"product_count" => 3,
    				"products_wide" => 3),
    			$atts
    		)
    	);
    Plugin Author Rustaurius

    (@rustaurius)

    Hi Lee,

    The plugin actually searches for the item ID around line 825:

    if ($Pretty_Links == "Yes") {$Product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $items_table_name WHERE Item_Slug=%s", trim(get_query_var('single_product'), "/? ")));}
    else {$Product = $wpdb->get_row($wpdb->prepare("SELECT * FROM $items_table_name WHERE Item_ID='%d'", $_GET['SingleProduct']));}

    The code your referencing is only used by the widgets to create the mini product listings some people add to their headers and sidebars.

    Thread Starter Lee_L

    (@lee_l)

    I am sorry maybe I am not explaining myself properly.

    IS there a shortcode or way to find the ITEM_ID from within the plugin ?

    I will try again to give a few examples:

    [myplugin postid= “item_id”]
    [wp-review id=”item_id”]
    [yasr setid=”item_id”]

    Can the ITEM_ID be passed to another plugin?

    I believe you pass the Product Name to Ultimate Review Plug in order to match to the right review. My question is there a similiar ITEM_ID variable that can be pass as well ?

    [ultimate-reviews product_name=’Smith & Wesson Shield’]
    The problem is the product name is not unique enough to be a key field.

    function UPCP_Add_Product_Reviews($Product) {
    	$ReturnString = do_shortcode("[ultimate-reviews product_name='" . $Product->Item_Name . "']");
    	return $ReturnString;
    }

    If I am not explaining this properly please let me know.

    Plugin Author Rustaurius

    (@rustaurius)

    Hi Lee,

    There’s no shortcode or specific way to access the Item_ID from within the plugin. How it’s accessed depends on what point you’re trying to access the Item_ID variable, and whether it’s being passed externally.

    If you’re trying to send the Item_ID to a different plugin, you’d probably have to create a custom function and add it into the “Shortcodes.php” file in the correct location.

    It would probably look similar to the function that called the reviews plugin:

    function UPCP_Add_Product_Reviews($Product) {
    	$ReturnString = do_shortcode("[ultimate-reviews product_name='" . $Product->Item_Name . "']");
    	return $ReturnString;
    }

    If you were replacing the name with the item id at that point it would look like:

    $Product->Item_ID

    Thread Starter Lee_L

    (@lee_l)

    Thanks I was just staring at the shortcode.php file thinking the same thing.

    That’s what I needed.

    Appreciate your patience.

    Plugin Author Rustaurius

    (@rustaurius)

    Happy we could get on the same page in the end haha

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Anyway to Query [get] current Product ID’ is closed to new replies.