Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter jedidiah13

    (@jedidiah13)

    see above reply

    Thread Starter jedidiah13

    (@jedidiah13)

    I solved my own problem by using something similar to what rickymccallum87 suggested…
    I used a custom meta field to record the IDs for all the images, including the featured image then compared that to the current gallery images to see if they had changed, if they did then update the custom meta value with the new numbers and send an email to let people know the pictures changed.

    code is as follows:

    // send email when images change for a product
    add_action( 'woocommerce_update_product', 'imagecheck_on_product_save', 10, 1 );
    function imagecheck_on_product_save( $product_id ) {
    	$product = wc_get_product( $product_id );
    	// do something with this product
    	$metaImages = get_post_meta( $product_id, '_gallery_image_ids', true );
      	$currentImages = $product->get_gallery_image_ids();
    	
    	$imageIDs = get_post_thumbnail_id( $product_id );
    	if ($imagesIDs != "" )
    	{
    		
    	$imageIDs = $imageIDs . ", ";
    	foreach($currentImages as $value){
    		$imageIDs = $imageIDs . $value . ", "; 
    	}
    	
      	if ( $metaImages != $imageIDs ) {
    		update_post_meta( $product_id, '_gallery_image_ids', esc_attr( $imageIDs ) );
    		
    		global $current_user;
        	        wp_get_current_user();
    		$email = $current_user->user_email;
    		$lastuser = $current_user->user_firstname;
    		
    		if ( $product->get_sku() != "" ) 
    		{
    			$memail = "<pre>USER: " . $lastuser . " made the following changes:</br>
    Meta gallery images: " . $metaImages . "</br>
    </br>
    Actual gallery images: " . $imageIDs . "
    " . $memail . "</pre>";
    			$headers = array('Content-Type: text/html; charset=UTF-8');
    			$subject = "PICTURES CHANGED - SKU: " . $product->get_sku();
    			$to = "(insert who you want to send to here)";
    			wp_mail( $to, $subject, $memail, $headers ); 
    		}
    	}
    	}
    }
    • This reply was modified 3 years, 8 months ago by jedidiah13.
    • This reply was modified 3 years, 8 months ago by jedidiah13.
    Thread Starter jedidiah13

    (@jedidiah13)

    I want to model it after this currently working code that notifies people when changes have been made to the product description:

    <?php
    // code to document content changes to products (underlines additions, strikethrough removals)
    add_action('pre_post_update', 'content_change_email', 10, 2);
    function content_change_email($post_ID, $data) 
    {
    	function diff($old, $new)
    	{
        	$matrix = array();
        	$maxlen = 0;
        	foreach($old as $oindex => $ovalue)
    		{
            	$nkeys = array_keys($new, $ovalue);
           		foreach($nkeys as $nindex)
    			{
                	$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
                    $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
                	if($matrix[$oindex][$nindex] > $maxlen)
    				{
                    	$maxlen = $matrix[$oindex][$nindex];
                    	$omax = $oindex + 1 - $maxlen;
                    	$nmax = $nindex + 1 - $maxlen; 
    				} /* close if($matrix */ 
    			} /* close foreach($nkeys */ 
    		} /* close foreach($old */
        	if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
        	return array_merge(
            	diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
            	array_slice($new, $nmax, $maxlen),
            	diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
    	} /*close function diff */
    	
    	function htmlDiff($old, $new)
    	{
        	$ret = '';
        	$diff = diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));
        	foreach($diff as $k)
    		{
            	if(is_array($k))
                	$ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":'').(!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":'');
            	else $ret .= $k . ' '; 
    		} /* close foreach($diff */
        	return $ret; 
    	} /* close function htmlDiff */
    	
    	$type = get_post_type( $post_ID ); // get post type
    	if ( $type == 'product' )
    	{ // if post type is product
    		$content = $_POST['content'];
    		$product = wc_get_product( $post_ID );
    		$oldcontent = $product->post->post_content;
    		$status = $product->get_status();
    		if ( $status == "publish" ) 
    		{
    			if ( $content != "" ) 
    			{
    				if ( $oldcontent != $content ) 
    				{
    					$msg = htmlDiff($oldcontent, $content);
    					$memail = "
    <style type='text/css'>
    ins { background-color:#ccffcc; }
    del { background-color:#ffcccc; }
    </style>
    <table>
        <tr>
            <td>".$msg."</td>
        </tr>
    </table>";
    					//$file = file_put_contents("changes.html", $email); *** send email not write to file
    					$headers = array('Content-Type: text/html; charset=UTF-8');
    		
    					global $current_user;
        				wp_get_current_user();
    					$email = $current_user->user_email;
    					$lastuser = $current_user->user_firstname;
    		
    					
    					if ( $product->get_sku() != "" ) 
    					{
    						$memail = "USER: " . $lastuser . " made the following changes:
    Additions will have underlining.
    Subtractions will be strikethrough.
    			
    " . $memail;
    						$subject = "CONTENT CHANGED - SKU: " . $product->get_sku();
    						$to = "";
    						
    						wp_mail( $to, $subject, $memail, $headers ); 
    					} /* close if ( $product->get_sku() */
    				} /* close if ( $oldcontent */
    			} /* close if ( $content */
    			/* check if image ids have changed
    			$images = $_POST['image_ids'];
    			$oldImages = $product->get_gallery_image_ids();
    			if ( $images != "" ) 
    			{
    				if ( $oldImages != $images ) 
    				{
    					
    					
    				}
    			}*/
    		} /* close if ( $status */
    	} /* close if ( $type */
    	
    	remove_action('pre_post_update', 'content_change_email', 10, 2);
    }
    ?>
    Thread Starter jedidiah13

    (@jedidiah13)

    No this does not help what I am trying to achieve in any way. I do not want to create another meta field for display.
    To recap:
    An employee changes the images (adds, deletes, adds and deletes), one or all of the images.
    Then BEFORE the product is saved, it compares the post value of the image gallery to the current image gallery value, if they are different (they have been changed) an email is sent to someone.

    Thread Starter jedidiah13

    (@jedidiah13)

    found the answer myself here:
    https://github.com/woocommerce/woocommerce/pull/18708

    I followed the comment on the page stating that stated this code:
    add_filter( ‘post_class’, function( $classes ) {
    if ( is_admin() ) {
    $current_screen = get_current_screen();
    if ( $current_screen->base == ‘edit’ && $current_screen->post_type == ‘shop_order’ ) $classes[] = ‘no-link’;
    }
    return $classes;
    } );

    Add this to functions.php and it makes it removes the row click to edit order for everything

    • This reply was modified 4 years, 4 months ago by jedidiah13.
    Thread Starter jedidiah13

    (@jedidiah13)

    I believe the problem had something to do with me being logged into our store when I was checking links. It appears to be working now. Thanks.

    Resolved.

    Thread Starter jedidiah13

    (@jedidiah13)

    resolved

    Thread Starter jedidiah13

    (@jedidiah13)

    Ok I do see now that I can simply convert all the editors I have into “shop managers”. its annoying but doable. you may want to extend this to editor roles in the future as well

    Thread Starter jedidiah13

    (@jedidiah13)

    OK i dont think i was clear enough…

    On the admin backend area… I want an editor to be able to review any offers that have come in. As of right now I cannot allow that to happen even with a role manager plugin. The only people able to see offers made on our products are admins. I need editors to be able to see and respond to it.

    The reason I want this is because the people that can accept or reject offers want the backend to be simplified as much as possible (they aren’t tech people). My backend menu as an administrator is very complicated looking because I see every option the site has for settings etc. They want to log in and ONLY see what they are responsible for on the website. In other words I want them to see the woocommerce tag and hover over it and see the offers menu the way I see it as an admin. I cannot enable this for editors. If this is possible please give me a step by step how to.

    Thread Starter jedidiah13

    (@jedidiah13)

    also to clarify further, I use Relevanssi for the front end search and it works like a charm searching the store using multiple numbers (assuming this works because of Relevanssi indexing it all), but it will not work in the back end (admin) section

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