Categories
Blog Code Snippets Javascript JQuery

Woocommerce – Prevent the Product Image from Opening in New Window

You’ve got your woocommerce site up and running but there’s this really annoying thing happening when users click on the product image. The image opens in the same window, navigating away from the product page.

Here’s a quick fix using jquery. If you’re not familiar with child themes, download the Custom CSS/JS plugin and drop this into a javascript file!

jQuery(document).ready(function( $ ){
  if ( $(".woocommerce-product-gallery__image").length ) {    //make sure the link element exists on the page
    $( ".woocommerce-product-gallery__image a" ).click(function( event ) {
      event.preventDefault();     //cancel the onclick action
    });
  }
});
Categories
Blog Code Snippets PHP

Send E-mail with Attachment using PHP

Here’s a perfectly working snippet of PHP code which will send an e-mail with an attachment (of any file type).

This code has been updated to disable jumbled/garbage/corruption which showed up on gmail (while it was fine on Outlook).

//File settings
$fileatt = "../uploads/myLovelyFile.pdf";
$fileatttype = "application/octet-stream"; //Octet-stream is a file type to allow all types of files
$fileattname = "myLovelyFile";

//Read file contents
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);

//Prepare file contents for e-mail
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$data = chunk_split(base64_encode($data));

$subject = "My Lovely Subject";

$mainMessage = "Hello,"
. "

This is my lovely message."
. "
Please see the attached file."
. "

Best Regards,"
. "
Kim";

$from = "Sandy Sender ";

$to = "Randy Recipient ";

$headers = "From: $from" . "\r\n";
$headers .= 'Reply-To: dispatcher@sender.com' . "\r\n"; //Optional
$headers .= "BCC: barbara@blindcopy.com\r\n"; //Optional

$headers .= "MIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"\n";
$headers .= "Importance: High\n"; //Optional
$message = "This is a multi-part message in MIME format.\n\n" . "–{$mime_boundary}\n"
. "Content-Type: text/html; charset=\"iso-8859-1\n"
. "Content-Transfer-Encoding: 7bit\n\n" . $mainMessage . "\n\n";

//Attach file to e-mail
$message .= "–{$mime_boundary}\n"
. "Content-Type: {$fileatttype};\n" . " name=\"{$fileattname}\"\n"
. "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n"
. "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "-{$mime_boundary}-\n";

// Send the email
mail($to, $subject, $message, $headers);

 

Categories
Blog Code Snippets

Add Checkmarks to your Unordered List Items

You have a regular unordered which shows with bullet points just like this:

HTML:

<ul>
 	<li>Apples</li>
 	<li>Oranges</li>
 	<li>Grapes</li>
</ul>

Result:

  • Apples
  • Oranges
  • Grapes

The bullet points are ugly and the check marks would be so much more relevant. Here’s how to turn the bullet points into checks.

First, add a class like checkmark to the ul tag which will indicate when the checks should be applied.

HTML:

<ul class="checkmark">
 	<li>Apples</li>
 	<li>Oranges</li>
 	<li>Grapes</li>
</ul>

Next, add your CSS:

ul.checkmark {
  list-style: none;
  margin-left: 25px;
}

ul.checkmark li {
  line-height: 1.8;
  position: relative;
}

ul.checkmark li:before {
  color: #781fd7;
  content: '✓';
  font-weight: bold;
  left: -25px;
  position: absolute;
}

Here’s your result:

  • Apples
  • Oranges
  • Grapes