Advertisement
Guest User

my_unitprice_function for MyMail

a guest
May 27th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. if ( function_exists( 'mymail_add_tag' ) ) {
  2.    
  3.     function my_unitprice_function($option, $fallback, $campaignID = NULL, $subscriberID = NULL){
  4.  
  5.         $_pf = new WC_Product_Factory();
  6.        
  7.         //relative products
  8.         if($option < 0){
  9.  
  10.             $posts = get_posts( array(
  11.                 'numberposts' => 1,
  12.                 'post_type' => 'product',
  13.                 'offset' => $option,
  14.             ) );
  15.            
  16.             $post_id = (int) $posts[0]->ID;
  17.  
  18.         //absolute products
  19.         }else{
  20.            
  21.             $post_id = (int) $option;
  22.  
  23.         }
  24.  
  25.         $_product = $_pf->get_product($post_id);
  26.         $price_per_unit = $_product->get_price() / get_post_meta ($post_id, 'sub_title', true );
  27.         return '$'.number_format(round($price_per_unit,2),2);
  28.     }
  29.  
  30.     mymail_add_tag('unitprice', 'my_unitprice_function');
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement