Advertisement
CodeDropz

Download Zip

Jul 27th, 2021
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. add_action('woocommerce_email_after_order_table', 'add_download_links', 10, 4 );
  2.  
  3. function add_download_links( $order, $sent_to_admin, $plain_text, $email ) {
  4.  
  5.     foreach( $order->get_items() as $item_id => $item ) {
  6.         if( $files_meta = $item->get_meta( '_dndmfu_wc_files' ) ) {
  7.             $files = maybe_unserialize( $files_meta );
  8.             if( isset( $files['files'] ) ) {
  9.                 foreach( $files['files'] as $file ) {
  10.                     $data[] = wp_basename( pathinfo( $file, PATHINFO_DIRNAME ) ).'/'. wp_basename( $file );
  11.                 }
  12.             }
  13.         }
  14.     }
  15.  
  16.     if( $data ) {
  17.         $nonce = wp_create_nonce( 'dndmfu_wc_download' );
  18.         $post_id = (int)$order->get_id();
  19.         echo '<div style="margin-bottom: 40px;">';
  20.             echo '<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;" border="1">';
  21.                 echo '<tbody>';
  22.                     echo '<tr><td>Files</td></tr>';
  23.                     echo '<tr>';
  24.                         echo '<td style="border:1px solid #e5e5e5;">';
  25.                             echo '<a href="'.site_url('wp-admin').'/post.php?post='.$post_id.'&action=edit&cd_action=dndmfu_wc_download&files='.implode(',', $data ).'&security='.$nonce.'">Download Zip</a></a>';
  26.                         echo '</td>';
  27.                     echo '</tr>';
  28.                 echo '</tbody>';
  29.             echo '</table>';
  30.         echo '</div>';
  31.        
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement