Plugin Directory

Changeset 3091857


Ignore:
Timestamp:
05/24/2024 04:09:34 AM (20 months ago)
Author:
veto
Message:

add logger and send pdf emails after creating the pdf coupons

Location:
bw-coupon
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • bw-coupon/tags/1.4.3/README.md

    r2979375 r3091857  
    1515 * curl_exec must be enabled for external image load
    1616
    17 
     17### Example install in Debian
     18```console
     19sudo apt-get install php8.2-xml php-font-lib php-dompdf-svg-lib php8.2-mbstring
     20```
    1821## Description
    1922
  • bw-coupon/tags/1.4.3/bwc.php

    r2979608 r3091857  
    44 * Description: This plugin lets WooCommerce customers purchase coupons as PDF ( Portable Document Format). You design the PDF with the WordPress Product HTML Editor. The Coupons are automatically generated and delivered to customers as PDF attachments
    55 * Depends: WooCommerce
    6  * Version: 1.4.2
    7  * Requires PHP: 7.1
     6 * Version: 1.4.3
     7 * Requires PHP: 8.0
    88 * Author: Myridia.com Co., LTD.
    9  * Author URI: http://bw-coupon.myridia.com/
     9 * Author URI: https://myridia.com/bw-coupon
    1010 * Developer: Myridia.com Co., LTD.
    1111 * Text Domain: bw-coupon
    1212 * Domain Path: /languages
    13  * WC requires at least: 2.2
    14  * WC tested up to: 8.1.1
    15  * WP requires at least: 5.0.0
    16  * WP tested up to: 6.3.1
     13 * WC requires at least: 8.9.1
     14 * WC tested up to: 8.9.1
     15 * WP requires at least: 6.5.2
     16 * WP tested up to: 6.5.2
    1717 * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    1818 *
  • bw-coupon/tags/1.4.3/includes/coupons.php

    r2979375 r3091857  
    150150{
    151151  global $wpdb;
    152 
     152  bwc_logging( '...bwc_register_coupons fnc'); 
    153153  if ( !$wpdb ):
    154154    return false;
     
    156156
    157157  $generated_coupon = 0;
    158 
     158  $emails_to_send = [];
    159159  foreach ( $post_ids as $post_id ):
    160160    $coupons = bwc_check_order_coupons_count( $post_id ); /* General check if coupon order exist */
    161161    if ( $coupons['count'] > 0 ):
     162      bwc_logging( '...coupons count:  ' . $coupons['count']); 
    162163      $order  = new WC_Order( $post_id );
    163164      $items  = $order->get_items();
     
    179180
    180181              if( bwc_coupon_fulfilled($post_id,$key,$item['qty']) == FALSE):
    181            
     182
     183                bwc_logging("...create coupon product id: " .$product_id . "  post id:" . $post_id ." key: " .$key  );
    182184                $coupon_id = bwc_create_woocommerce_coupon( $product_id, $post_id, $key);
    183185
     
    196198                  );
    197199
    198                   bwc_send_email( $coupon_id );
     200                  $emails_to_send[] =  $coupon_id; //add coupon ids for sending
    199201                endif;
    200202              endif;
    201 
    202203            endfor;
    203204          endif;
     
    206207    endif;
    207208  endforeach;;
     209 
     210  bwc_send_emails( $emails_to_send );
     211  //  var_dump($emails_to_send);
    208212  return $generated_coupon;
    209213}
  • bw-coupon/tags/1.4.3/includes/functions.php

    r2979375 r3091857  
    455455
    456456/**
     457 * Helper Loggin function
     458 *
     459 * @param string
     460 */
     461function bwc_logging( $str, $type='info' )
     462{
     463  $logger = wc_get_logger();
     464  $context = array( 'source' => 'bwc' );
     465  $logger->info( $str, $context );
     466}
     467
     468
     469/**
    457470 * Helper function to create de query arguments of the URL.
    458471 *
  • bw-coupon/tags/1.4.3/includes/mail.php

    r2979375 r3091857  
    1414}
    1515
    16 function bwc_send_test_email( $mailto=FALSE, $customer=FALSE, $title=False, $order_id='' )
     16
     17function bwc_send_emails( $coupon_ids )
    1718{
    18   load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
    19   if( $mailto ):
    20     $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
    21     $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : '';
    22     $mail_settings = ! empty( get_option( 'woocommerce_email_from_address' ) ) ? get_option( 'woocommerce_email_from_address' ) : get_bloginfo( 'admin_email' );
    23     $from_settings = ! empty( get_option( 'woocommerce_email_from_name' ) ) ? get_option( 'woocommerce_email_from_name' ) : get_bloginfo( 'name' );
    24     $headers  = 'MIME-Version: 1.0' . "\r\n";
    25     $headers .= "Content-Type: text/html\n";
    26     $headers .= 'From: ' . $from_settings . ' <' . $mail_settings . '>' . "\r\n" . 'Reply-To: ' . $mail_settings . '' . "\r\n";
    27     $message = bwc_email_format($message, $customer, $title, $order_id);
    28     $cc  = ! empty( get_option( 'bwc_cc_mail' ) ) ? get_option( 'bwc_cc_mail' ) : FALSE;
    29     $bcc  = ! empty( get_option( 'bwc_bcc_mail' ) ) ? get_option( 'bwc_bcc_mail' ) : FALSE;
    30 
    31     if($bcc):
    32       $headers .= 'Bcc: '. $bcc . "\r\n";
    33     endif;   
    34 
    35     if($cc):
    36       $headers .= 'Cc: '. $cc . "\r\n";
    37     endif;   
    38 
    39     $r = wp_mail( $mailto , $subject, $message, $headers);
    40     return $r;
    41   endif;
     19    bwc_logging('...bwc_send_emails fn');
     20    foreach( $coupon_ids as $k => $i ):
     21        bwc_logging( '...send email pdf to ' . $i);       
     22        $r =   bwc_send_email($i); //enable later
     23    endforeach;
    4224}
    4325
     
    4527function bwc_send_email( $coupon_id, $mailto=FALSE )
    4628{
     29
    4730  load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
    4831  $coupon = bwc_get_coupon( $coupon_id );
    4932  $order  = new WC_Order( $coupon->id_order );
    5033  $title  = get_post_meta( $coupon->id_order , '_billing_title', true );
    51  
     34
    5235
    5336  $coupon_post = get_post( $coupon_id );
     
    6346
    6447  $r = FALSE;
     48
    6549  if( $mailto ):
     50    //var_dump("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");     
     51    //var_dump($coupon_id );
     52    //var_dump("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); 
    6653    $pdf = bwc_create_pdf( $coupon_id );
     54
    6755    $_path = tempnam(sys_get_temp_dir(), __('Coupon','bw-coupon'). "_{$coupon_code}__");
    6856    rename($_path, $_path .= '.pdf');
    6957    file_put_contents( $_path, $pdf );
     58
    7059    $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
    7160    $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : __( 'Please download the PDF', "bw-coupon" );
     
    9786      return FALSE;
    9887    endif;
     88
    9989  endif;
     90
    10091  return FALSE;
    10192}
     
    132123
    133124
     125function bwc_send_test_email( $mailto=FALSE, $customer=FALSE, $title=False, $order_id='' )
     126{
     127  load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
     128  if( $mailto ):
     129    $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
     130    $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : '';
     131    $mail_settings = ! empty( get_option( 'woocommerce_email_from_address' ) ) ? get_option( 'woocommerce_email_from_address' ) : get_bloginfo( 'admin_email' );
     132    $from_settings = ! empty( get_option( 'woocommerce_email_from_name' ) ) ? get_option( 'woocommerce_email_from_name' ) : get_bloginfo( 'name' );
     133    $headers  = 'MIME-Version: 1.0' . "\r\n";
     134    $headers .= "Content-Type: text/html\n";
     135    $headers .= 'From: ' . $from_settings . ' <' . $mail_settings . '>' . "\r\n" . 'Reply-To: ' . $mail_settings . '' . "\r\n";
     136    $message = bwc_email_format($message, $customer, $title, $order_id);
     137    $cc  = ! empty( get_option( 'bwc_cc_mail' ) ) ? get_option( 'bwc_cc_mail' ) : FALSE;
     138    $bcc  = ! empty( get_option( 'bwc_bcc_mail' ) ) ? get_option( 'bwc_bcc_mail' ) : FALSE;
     139
     140    if($bcc):
     141      $headers .= 'Bcc: '. $bcc . "\r\n";
     142    endif;   
     143
     144    if($cc):
     145      $headers .= 'Cc: '. $cc . "\r\n";
     146    endif;   
     147
     148    $r = wp_mail( $mailto , $subject, $message, $headers);
     149    return $r;
     150  endif;
     151}
  • bw-coupon/tags/1.4.3/make_wp_readme.sh

    r2979375 r3091857  
    11#!/bin/bash
     2
    23wget -q  https://raw.githubusercontent.com/fumikito/wp-readme/master/wp-readme.php -O wp-readme.php
    3 docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.2-cli php wp-readme.php
     4docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4-cli php wp-readme.php
    45rm wp-readme.php
  • bw-coupon/trunk/README.md

    r2979375 r3091857  
    1515 * curl_exec must be enabled for external image load
    1616
    17 
     17### Example install in Debian
     18```console
     19sudo apt-get install php8.2-xml php-font-lib php-dompdf-svg-lib php8.2-mbstring
     20```
    1821## Description
    1922
  • bw-coupon/trunk/bwc.php

    r2979608 r3091857  
    44 * Description: This plugin lets WooCommerce customers purchase coupons as PDF ( Portable Document Format). You design the PDF with the WordPress Product HTML Editor. The Coupons are automatically generated and delivered to customers as PDF attachments
    55 * Depends: WooCommerce
    6  * Version: 1.4.2
    7  * Requires PHP: 7.1
     6 * Version: 1.4.3
     7 * Requires PHP: 8.0
    88 * Author: Myridia.com Co., LTD.
    9  * Author URI: http://bw-coupon.myridia.com/
     9 * Author URI: https://myridia.com/bw-coupon
    1010 * Developer: Myridia.com Co., LTD.
    1111 * Text Domain: bw-coupon
    1212 * Domain Path: /languages
    13  * WC requires at least: 2.2
    14  * WC tested up to: 8.1.1
    15  * WP requires at least: 5.0.0
    16  * WP tested up to: 6.3.1
     13 * WC requires at least: 8.9.1
     14 * WC tested up to: 8.9.1
     15 * WP requires at least: 6.5.2
     16 * WP tested up to: 6.5.2
    1717 * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    1818 *
  • bw-coupon/trunk/includes/coupons.php

    r2979375 r3091857  
    150150{
    151151  global $wpdb;
    152 
     152  bwc_logging( '...bwc_register_coupons fnc'); 
    153153  if ( !$wpdb ):
    154154    return false;
     
    156156
    157157  $generated_coupon = 0;
    158 
     158  $emails_to_send = [];
    159159  foreach ( $post_ids as $post_id ):
    160160    $coupons = bwc_check_order_coupons_count( $post_id ); /* General check if coupon order exist */
    161161    if ( $coupons['count'] > 0 ):
     162      bwc_logging( '...coupons count:  ' . $coupons['count']); 
    162163      $order  = new WC_Order( $post_id );
    163164      $items  = $order->get_items();
     
    179180
    180181              if( bwc_coupon_fulfilled($post_id,$key,$item['qty']) == FALSE):
    181            
     182
     183                bwc_logging("...create coupon product id: " .$product_id . "  post id:" . $post_id ." key: " .$key  );
    182184                $coupon_id = bwc_create_woocommerce_coupon( $product_id, $post_id, $key);
    183185
     
    196198                  );
    197199
    198                   bwc_send_email( $coupon_id );
     200                  $emails_to_send[] =  $coupon_id; //add coupon ids for sending
    199201                endif;
    200202              endif;
    201 
    202203            endfor;
    203204          endif;
     
    206207    endif;
    207208  endforeach;;
     209 
     210  bwc_send_emails( $emails_to_send );
     211  //  var_dump($emails_to_send);
    208212  return $generated_coupon;
    209213}
  • bw-coupon/trunk/includes/functions.php

    r2979375 r3091857  
    455455
    456456/**
     457 * Helper Loggin function
     458 *
     459 * @param string
     460 */
     461function bwc_logging( $str, $type='info' )
     462{
     463  $logger = wc_get_logger();
     464  $context = array( 'source' => 'bwc' );
     465  $logger->info( $str, $context );
     466}
     467
     468
     469/**
    457470 * Helper function to create de query arguments of the URL.
    458471 *
  • bw-coupon/trunk/includes/mail.php

    r2979375 r3091857  
    1414}
    1515
    16 function bwc_send_test_email( $mailto=FALSE, $customer=FALSE, $title=False, $order_id='' )
     16
     17function bwc_send_emails( $coupon_ids )
    1718{
    18   load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
    19   if( $mailto ):
    20     $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
    21     $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : '';
    22     $mail_settings = ! empty( get_option( 'woocommerce_email_from_address' ) ) ? get_option( 'woocommerce_email_from_address' ) : get_bloginfo( 'admin_email' );
    23     $from_settings = ! empty( get_option( 'woocommerce_email_from_name' ) ) ? get_option( 'woocommerce_email_from_name' ) : get_bloginfo( 'name' );
    24     $headers  = 'MIME-Version: 1.0' . "\r\n";
    25     $headers .= "Content-Type: text/html\n";
    26     $headers .= 'From: ' . $from_settings . ' <' . $mail_settings . '>' . "\r\n" . 'Reply-To: ' . $mail_settings . '' . "\r\n";
    27     $message = bwc_email_format($message, $customer, $title, $order_id);
    28     $cc  = ! empty( get_option( 'bwc_cc_mail' ) ) ? get_option( 'bwc_cc_mail' ) : FALSE;
    29     $bcc  = ! empty( get_option( 'bwc_bcc_mail' ) ) ? get_option( 'bwc_bcc_mail' ) : FALSE;
    30 
    31     if($bcc):
    32       $headers .= 'Bcc: '. $bcc . "\r\n";
    33     endif;   
    34 
    35     if($cc):
    36       $headers .= 'Cc: '. $cc . "\r\n";
    37     endif;   
    38 
    39     $r = wp_mail( $mailto , $subject, $message, $headers);
    40     return $r;
    41   endif;
     19    bwc_logging('...bwc_send_emails fn');
     20    foreach( $coupon_ids as $k => $i ):
     21        bwc_logging( '...send email pdf to ' . $i);       
     22        $r =   bwc_send_email($i); //enable later
     23    endforeach;
    4224}
    4325
     
    4527function bwc_send_email( $coupon_id, $mailto=FALSE )
    4628{
     29
    4730  load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
    4831  $coupon = bwc_get_coupon( $coupon_id );
    4932  $order  = new WC_Order( $coupon->id_order );
    5033  $title  = get_post_meta( $coupon->id_order , '_billing_title', true );
    51  
     34
    5235
    5336  $coupon_post = get_post( $coupon_id );
     
    6346
    6447  $r = FALSE;
     48
    6549  if( $mailto ):
     50    //var_dump("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");     
     51    //var_dump($coupon_id );
     52    //var_dump("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); 
    6653    $pdf = bwc_create_pdf( $coupon_id );
     54
    6755    $_path = tempnam(sys_get_temp_dir(), __('Coupon','bw-coupon'). "_{$coupon_code}__");
    6856    rename($_path, $_path .= '.pdf');
    6957    file_put_contents( $_path, $pdf );
     58
    7059    $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
    7160    $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : __( 'Please download the PDF', "bw-coupon" );
     
    9786      return FALSE;
    9887    endif;
     88
    9989  endif;
     90
    10091  return FALSE;
    10192}
     
    132123
    133124
     125function bwc_send_test_email( $mailto=FALSE, $customer=FALSE, $title=False, $order_id='' )
     126{
     127  load_plugin_textdomain( 'bw-coupon', false, 'bw-coupon/languages' ); 
     128  if( $mailto ):
     129    $subject  = ! empty( get_option( 'bwc_subject' ) ) ? get_option( 'bwc_subject' ) : __('Coupon','bw-coupon');
     130    $message  = ! empty( get_option( 'bwc_email_message' ) ) ? get_option( 'bwc_email_message' ) : '';
     131    $mail_settings = ! empty( get_option( 'woocommerce_email_from_address' ) ) ? get_option( 'woocommerce_email_from_address' ) : get_bloginfo( 'admin_email' );
     132    $from_settings = ! empty( get_option( 'woocommerce_email_from_name' ) ) ? get_option( 'woocommerce_email_from_name' ) : get_bloginfo( 'name' );
     133    $headers  = 'MIME-Version: 1.0' . "\r\n";
     134    $headers .= "Content-Type: text/html\n";
     135    $headers .= 'From: ' . $from_settings . ' <' . $mail_settings . '>' . "\r\n" . 'Reply-To: ' . $mail_settings . '' . "\r\n";
     136    $message = bwc_email_format($message, $customer, $title, $order_id);
     137    $cc  = ! empty( get_option( 'bwc_cc_mail' ) ) ? get_option( 'bwc_cc_mail' ) : FALSE;
     138    $bcc  = ! empty( get_option( 'bwc_bcc_mail' ) ) ? get_option( 'bwc_bcc_mail' ) : FALSE;
     139
     140    if($bcc):
     141      $headers .= 'Bcc: '. $bcc . "\r\n";
     142    endif;   
     143
     144    if($cc):
     145      $headers .= 'Cc: '. $cc . "\r\n";
     146    endif;   
     147
     148    $r = wp_mail( $mailto , $subject, $message, $headers);
     149    return $r;
     150  endif;
     151}
  • bw-coupon/trunk/make_wp_readme.sh

    r2979375 r3091857  
    11#!/bin/bash
     2
    23wget -q  https://raw.githubusercontent.com/fumikito/wp-readme/master/wp-readme.php -O wp-readme.php
    3 docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.2-cli php wp-readme.php
     4docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4-cli php wp-readme.php
    45rm wp-readme.php
Note: See TracChangeset for help on using the changeset viewer.