Guest User

Marketpress.php - Mark products with zero inventory

a guest
Jun 16th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.82 KB | None | 0 0
  1. <?php
  2.  
  3. function framemarket_listall_shops(){
  4.  
  5.     global $wpdb;
  6.  
  7.     $query = "SELECT blog_id FROM " . $wpdb->base_prefix . "blogs WHERE spam != '1' AND archived != '1' AND deleted != '1' AND public = '1' ORDER BY path";
  8.  
  9.  
  10.  
  11.     $blogs = $wpdb->get_results($query);
  12.  
  13.     $blogs = apply_filters( 'framemarket_list_shops', $blogs );
  14.  
  15.     ?>
  16.  
  17. <select name="shoplist" onchange="document.location.href=this.options[this.selectedIndex].value;">
  18.  
  19.     <option value=""><?php echo apply_filters('shop_drop_default_label', 'Visit a shop') ?></option>
  20.  
  21.     <?php
  22.  
  23.     foreach($blogs as $blog){
  24.  
  25.         $blog_details = get_blog_details($blog->blog_id);
  26.  
  27. ?>
  28.  
  29. <option value="<?php echo $blog_details->siteurl; ?>"> <?php echo $blog_details->blogname; ?></option>
  30.  
  31. <?php
  32.  
  33.     }
  34.  
  35. ?>
  36.  
  37.  </select>
  38.  
  39. <?php
  40.  
  41. }
  42.  
  43. // [mp_product_stock]
  44. function mp_product_stock_sc( $atts ){
  45.     global $post;
  46.     $product_id = $post->ID;
  47.     $stock = get_post_meta($product_id, 'mp_inventory', true);
  48.     //return $stock[0];
  49.  
  50.     if ($stock[0] == 0 ) {
  51.         return $stock[0];
  52.     } else {
  53.         return '';
  54.     }
  55. }
  56. add_shortcode( 'mp_product_stock', 'mp_product_stock_sc' );
  57.    
  58.    
  59.  
  60. // output in a grid of 4 across
  61.  
  62. function framemarket_grid_mp_list_products( $echo = true, $paginate = '', $paged = '', $per_page = '', $order_by = '', $order = '', $category = '', $tag = '', $search = '' ) {
  63.  
  64.   global $wp_query, $mp, $grid_home;
  65.  
  66.   $settings = get_option('mp_settings');
  67.  
  68.  
  69.  
  70.   //setup taxonomy if applicable
  71.  
  72.   $taxonomy_query = '';
  73.  
  74.   if ($category) {
  75.  
  76.     $taxonomy_query = '&product_category=' . sanitize_title($category);
  77.  
  78.   } else if ($tag) {
  79.  
  80.     $taxonomy_query = '&product_tag=' . sanitize_title($tag);
  81.  
  82.   } else if (isset($wp_query->query_vars['taxonomy']) && ($wp_query->query_vars['taxonomy'] == 'product_category' || $wp_query->query_vars['taxonomy'] == 'product_tag')) {
  83.  
  84.     $taxonomy_query = '&' . $wp_query->query_vars['taxonomy'] . '=' . get_query_var($wp_query->query_vars['taxonomy']);
  85.  
  86.   }
  87.  
  88.  
  89.  
  90.   //check if it's a search
  91.  
  92.   $search_query = '';
  93.  
  94.   if (isset($wp_query->query_vars['s']) && $wp_query->query_vars['s']){
  95.  
  96.     $search_query = '&s=' . $wp_query->query_vars['s'];
  97.  
  98.   }
  99.  
  100.  
  101.  
  102.     if ( $paginate ) {
  103.  
  104.         // $paged = true;
  105.  
  106.     } else if ( $paginate === '' ) {
  107.  
  108.         if ( $settings['paginate'] ) {
  109.  
  110.             //$paged = true;
  111.  
  112.         }
  113.  
  114.         else
  115.  
  116.             $paginate_query = '&nopaging=true';
  117.  
  118.     } else {
  119.  
  120.         $paginate_query = '&nopaging=true';
  121.  
  122.     }
  123.  
  124.  
  125.  
  126.     if (! $paged) {
  127.  
  128.         $paged = ( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 1;
  129.  
  130.     }
  131.  
  132.  
  133.  
  134.     //get page details
  135.  
  136.     if ( $paged ) {
  137.  
  138.         //figure out perpage
  139.  
  140.         if ( intval( $per_page ) )
  141.  
  142.           $paginate_query = '&posts_per_page='.intval($per_page);
  143.  
  144.         else
  145.  
  146.           $paginate_query = '&posts_per_page='.$settings['per_page'];
  147.  
  148.  
  149.  
  150.         //figure out page
  151.  
  152.         //if ( $wp_query->query_vars['paged'] )
  153.  
  154.         //  $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
  155.  
  156.  
  157.  
  158.         if ( intval( $paged ) )
  159.  
  160.             $paginate_query .= '&paged='.intval($paged);
  161.  
  162.         else if ($wp_query->query_vars['paged'])
  163.  
  164.             $paginate_query .= '&paged='.intval($wp_query->query_vars['paged']);
  165.  
  166.         /*else if ($paged)
  167.  
  168.             $paginate_query .= '&paged='.intval($paged);*/
  169.  
  170.     }
  171.  
  172.  
  173.  
  174.   //get order by
  175.  
  176.   if (!$order_by) {
  177.  
  178.     if ($settings['order_by'] == 'price')
  179.  
  180.       $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num';
  181.  
  182.     else if ($settings['order_by'] == 'sales')
  183.  
  184.       $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num';
  185.  
  186.     else
  187.  
  188.       $order_by_query = '&orderby='.$settings['order_by'];
  189.  
  190.   } else {
  191.  
  192.     if ('price' == $order_by)
  193.  
  194.         $order_by_query = '&meta_key=mp_price_sort&orderby=meta_value_num';
  195.  
  196.     else if('sales' == $order_by)
  197.  
  198.       $order_by_query = '&meta_key=mp_sales_count&orderby=meta_value_num';
  199.  
  200.     else
  201.  
  202.         $order_by_query = '&orderby='.$order_by;
  203.  
  204.   }
  205.  
  206.  
  207.  
  208.   //get order direction
  209.  
  210.   if (!$order) {
  211.  
  212.     $order_query = '&order='.$settings['order'];
  213.  
  214.   } else {
  215.  
  216.     $order_query = '&order='.$order;
  217.  
  218.   }
  219.  
  220.  
  221.   //The Query
  222.  
  223.   $custom_query = new WP_Query('post_type=product&post_status=publish' . $search_query . $taxonomy_query . $paginate_query . $order_by_query . $order_query);
  224.  
  225.   $wp_query = $custom_query;
  226.  
  227.   $content = '<div id="mp_product_list">';
  228.  
  229.  
  230.  
  231.   if ($last = count($custom_query->posts)) {
  232.  
  233.  
  234.  
  235.     $count = 1;
  236.  
  237.     $counter = 0;
  238.  
  239.     foreach ($custom_query->posts as $post) {
  240.  
  241.  
  242.  
  243.             //add last css class for styling grids
  244.  
  245.             if (($count%5 == 0))
  246.  
  247.                  $class = array('mp_product', 'last-product');
  248.  
  249.             else
  250.  
  251.                  $class = 'mp_product';
  252.  
  253.  
  254.  
  255.       $content .= '<div '.mp_product_class(false, $class, $post->ID).'>';
  256.      
  257.       $content .= '<div class="mp_product_meta">';
  258.  
  259.       //price
  260.  
  261.       $meta = mp_product_price(false, $post->ID, false);
  262.      
  263.  
  264.       //button
  265.  
  266.       $meta .= mp_buy_button(false, 'list', $post->ID);
  267.      
  268.       $meta .= '<span class="original-sold">' . mp_product_stock_sc( $atts ) . '</span>';    
  269.  
  270.      
  271.  
  272.       $content .= apply_filters( 'mp_product_list_meta', $meta, $post->ID );
  273.  
  274.       $content .= '</div>';
  275.  
  276.       $content .= '<div class="mp_product_content">';
  277.      
  278.       $product_content = mp_product_image( false, 'list', $post->ID );
  279.      
  280.  
  281.       if( $mp->get_setting('show_excerpt') == 1 )
  282.  
  283.     $product_content .= $mp->product_excerpt($post->post_excerpt, $post->post_content, $post->ID);
  284.  
  285.       $content .= apply_filters( 'mp_product_list_content', $product_content, $post->ID );
  286.      
  287.       $content .= '<h3 class="mp_product_name"><a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a></h3>';
  288.  
  289.       $content .= '</div>';
  290.  
  291.       $content .= '</div>';
  292.  
  293.  
  294.  
  295.       $count++;
  296.  
  297.       $counter++;
  298.  
  299.         //add last css class for styling grids
  300.  
  301.       if (($counter%5 == 0))
  302.  
  303.             $content .= '<div class="clear"></div>';
  304.  
  305.     }
  306.  
  307.   } else {
  308.  
  309.     $content .= '<div id="mp_no_products">' . apply_filters( 'mp_product_list_none', __('No Products', 'mp') ) . '</div>';
  310.  
  311.   }
  312.  
  313.  
  314.  
  315.   $content .= '</div>';
  316.  
  317.  
  318.  
  319.     if (  $wp_query->max_num_pages > 1 ) :
  320.  
  321.         $content .= '<div id="navigation-bottom" class="navigation">';
  322.  
  323.         if (  $wp_query->query_vars['paged'] > 1 ) {
  324.  
  325.             if ($grid_home) {
  326.  
  327.                 $content .= '<div class="nav-previous"><a href="?page='.($wp_query->query_vars['paged']-1).'" >'. __('<span class="meta-nav">&larr;</span> Previous', 'framemarket').'</a></div>';
  328.  
  329.             } else {
  330.  
  331.                 $content .= '<div class="nav-previous">'. get_previous_posts_link( __('<span class="meta-nav">&larr;</span> Previous', 'framemarket') ).'</a></div>';
  332.  
  333.             }
  334.  
  335.         }
  336.  
  337.         if (  $wp_query->max_num_pages > $wp_query->query_vars['paged'] ) {
  338.  
  339.             if ($grid_home) {
  340.  
  341.                 $content .= '<div class="nav-next"><a href="?page='.($wp_query->query_vars['paged']+1).'" >'. __('Next <span class="meta-nav">&rarr;</span>', 'framemarket' ).'</a></div>';
  342.  
  343.             } else {
  344.  
  345.                 $content .= '<div class="nav-next">'. get_next_posts_link(__('Next <span class="meta-nav">&rarr;</span>', 'framemarket' )).'</div>';
  346.  
  347.             }
  348.  
  349.         }
  350.  
  351.         $content .= '</div>';
  352.  
  353.     endif;
  354.  
  355.  
  356.  
  357.     if ( $echo )
  358.  
  359.         echo $content;
  360.  
  361.     else
  362.  
  363.         return $content;
  364.  
  365. }
  366.  
  367.  
  368.  
  369. function framemarket_mp_list_global_products($args = '') {
  370.  
  371.   global $wpdb, $mp, $grid_home;
  372.  
  373.  
  374.  
  375.   $defaults = array(
  376.  
  377.         'echo' => true,
  378.  
  379.     'paginate' => true,
  380.  
  381.         'page' => 1,
  382.  
  383.     'per_page' => 20,
  384.  
  385.         'order_by' => 'date',
  386.  
  387.     'order' => 'DESC',
  388.  
  389.         'category' => '',
  390.  
  391.     'tag' => '',
  392.  
  393.         's' => '',
  394.  
  395.         'sentence' => '',
  396.  
  397.         'exact' => '',
  398.  
  399.         'show_thumbnail' => true,
  400.  
  401.         'thumbnail_size' => 150,
  402.  
  403.         'context' => 'list',
  404.  
  405.         'show_price' => true,
  406.  
  407.         'text' => 'excerpt',
  408.  
  409.         'as_list' => false
  410.  
  411.     );
  412.  
  413.  
  414.  
  415.   $r = wp_parse_args( $args, $defaults );
  416.  
  417.   extract( $r );
  418.  
  419.  
  420.  
  421.   //setup taxonomy if applicable
  422.  
  423.   if ($category) {
  424.  
  425.     $category = $wpdb->escape( sanitize_title( $category ) );
  426.  
  427.     $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_category' AND t.slug = '$category'";
  428.  
  429.     $query_count = "SELECT COUNT(*) FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_category' AND t.slug = '$category'";
  430.  
  431.   } else if ($tag) {
  432.  
  433.     $tag = $wpdb->escape( sanitize_title( $tag ) );
  434.  
  435.     $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_tag' AND t.slug = '$tag'";
  436.  
  437.     $query_count = "SELECT COUNT(*) FROM {$wpdb->base_prefix}mp_products p INNER JOIN {$wpdb->base_prefix}mp_term_relationships r ON p.id = r.post_id INNER JOIN {$wpdb->base_prefix}mp_terms t ON r.term_id = t.term_id WHERE p.blog_public = 1 AND t.type = 'product_tag' AND t.slug = '$tag'";
  438.  
  439.   } else {
  440.  
  441.     $query = "SELECT blog_id, p.post_id, post_permalink, post_title, post_content FROM {$wpdb->base_prefix}mp_products p WHERE p.blog_public = 1";
  442.  
  443.     $query_count = "SELECT COUNT(*) FROM {$wpdb->base_prefix}mp_products p WHERE p.blog_public = 1";
  444.  
  445.   }
  446.  
  447.  
  448.  
  449.     // get search
  450.  
  451.     if ( !empty($s) ) {
  452.  
  453.         // added slashes screw with quote grouping when done early, so done later
  454.  
  455.         $s = stripslashes($s);
  456.  
  457.         if ( !empty($sentence) ) {
  458.  
  459.             $search_terms = array($s);
  460.  
  461.         } else {
  462.  
  463.             preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $s, $matches);
  464.  
  465.             $search_terms = array_map('_search_terms_tidy', $matches[0]);
  466.  
  467.         }
  468.  
  469.         $n = !empty($exact) ? '' : '%';
  470.  
  471.         $search = '';
  472.  
  473.         $searchand = '';
  474.  
  475.         foreach( (array) $search_terms as $term ) {
  476.  
  477.             $term = esc_sql( like_escape( $term ) );
  478.  
  479.             $search .= "{$searchand}((p.post_title LIKE '{$n}{$term}{$n}') OR (p.post_content LIKE '{$n}{$term}{$n}'))";
  480.  
  481.             $searchand = ' AND ';
  482.  
  483.         }
  484.  
  485.         if ( !empty($search) ) {
  486.  
  487.             $query .= " AND ({$search}) ";
  488.  
  489.         }
  490.  
  491.     }
  492.  
  493.  
  494.  
  495.   //get order by
  496.  
  497.   switch ($order_by) {
  498.  
  499.  
  500.  
  501.     case 'title':
  502.  
  503.       $query .= " ORDER BY p.post_title";
  504.  
  505.       break;
  506.  
  507.  
  508.  
  509.     case 'price':
  510.  
  511.       $query .= " ORDER BY p.price";
  512.  
  513.       break;
  514.  
  515.  
  516.  
  517.     case 'sales':
  518.  
  519.       $query .= " ORDER BY p.sales_count";
  520.  
  521.       break;
  522.  
  523.  
  524.  
  525.     case 'rand':
  526.  
  527.       $query .= " ORDER BY RAND()";
  528.  
  529.       break;
  530.  
  531.  
  532.  
  533.     case 'date':
  534.  
  535.     default:
  536.  
  537.       $query .= " ORDER BY p.post_date";
  538.  
  539.       break;
  540.  
  541.   }
  542.  
  543.  
  544.  
  545.   //get order direction
  546.  
  547.   if ($order == 'ASC') {
  548.  
  549.     $query .= " ASC";
  550.  
  551.   } else {
  552.  
  553.     $query .= " DESC";
  554.  
  555.   }
  556.  
  557.  
  558.  
  559.   //get page details
  560.  
  561.   if ($paginate)
  562.  
  563.     $query .= " LIMIT " . intval(($page-1)*$per_page) . ", " . intval($per_page);
  564.  
  565.  
  566.  
  567.   //The Query
  568.  
  569.   $results = $wpdb->get_results( $query );
  570.  
  571.   if ($paginate){
  572.  
  573.       $total_results = $wpdb->get_var( $query_count );
  574.  
  575.       $total_pages = ceil($total_results/$per_page);
  576.  
  577.   }
  578.  
  579.  
  580.  
  581.   // Make sure show thumbnail setting follow main site
  582.  
  583.   $show_thumbnail = ( !$mp->get_setting('show_thumbnail') ) ? false : $show_thumbnail;
  584.  
  585.  
  586.  
  587.    $content = '<div id="mp_product_list">';
  588.  
  589.  
  590.  
  591.   if ($results) {
  592.  
  593.     $count = 1;
  594.  
  595.     $counter = 0;
  596.  
  597.     foreach ($results as $product) {
  598.  
  599.  
  600.  
  601.             //add last css class for styling grids
  602.  
  603.             if (($count%4 == 0))
  604.  
  605.                  $content .= '<div class="product mp_product last-product">';
  606.  
  607.             else
  608.  
  609.                   $content .= '<div class="product mp_product">';
  610.  
  611.  
  612.  
  613.  
  614.  
  615.       global $current_blog;
  616.  
  617.       switch_to_blog($product->blog_id);
  618.  
  619.  
  620.  
  621.       //grab permalink
  622.  
  623.       $permalink = get_permalink( $product->post_id );
  624.  
  625.  
  626.  
  627.       //grab thumbnail
  628.  
  629.       if ($show_thumbnail)
  630.  
  631.         $thumbnail = mp_product_image( false, $context, $product->post_id, $thumbnail_size );
  632.  
  633.  
  634.  
  635.       //price
  636.  
  637.       if ($show_price) {
  638.  
  639.         if ($context == 'widget')
  640.  
  641.           $price = mp_product_price(false, $product->post_id, ''); //no price label in widgets
  642.  
  643.         else
  644.  
  645.           $price = mp_product_price(false, $product->post_id, '');
  646.  
  647.       }
  648.  
  649.  
  650.  
  651.       restore_current_blog();
  652.  
  653.  
  654.  
  655.       $content .= '<h3 class="mp_product_name"><a href="' . $permalink . '">' . esc_attr($product->post_title) . '</a></h3>';
  656.  
  657.       $content .= '<div class="mp_product_content">';
  658.  
  659.  
  660.  
  661.       $content .= $thumbnail;
  662.  
  663.  
  664.  
  665.       $content .= '</div>';
  666.  
  667.  
  668.  
  669.       $content .= '<div class="mp_product_meta">';
  670.  
  671.  
  672.  
  673.       //price
  674.  
  675.       $content .= $price;
  676.  
  677.  
  678.  
  679.       //button
  680.  
  681.       $content .= '<a class="mp_link_buynow" href="' . $permalink . '">' .  __('Buy Now &raquo;', 'mp') . '</a>';
  682.  
  683.       $content .= '</div>';
  684.  
  685.  
  686.  
  687.         $content .= '</div>';
  688.  
  689.          $count++;
  690.  
  691.           $counter++;
  692.  
  693.             //add last css class for styling grids
  694.  
  695.           if (($counter%4 == 0))
  696.  
  697.                 $content .= '<div class="clear"></div>';
  698.  
  699.     }
  700.  
  701.   } else {
  702.  
  703.     $content .= '<div id="mp_no_products">' . apply_filters( 'mp_product_list_none', __('No Products', 'mp') ) . '</div>';
  704.  
  705.   }
  706.  
  707.  
  708.  
  709.     // Pagination
  710.  
  711.     if ( $paginate ){
  712.  
  713.         if ( $total_pages > 0 ){
  714.  
  715.             $content .= '<div id="navigation-bottom" class="navigation">';
  716.  
  717.             if (  $page > 1 ) {
  718.  
  719.                 if ($grid_home) {
  720.  
  721.                     $content .= '<div class="nav-previous"><a href="?page='.($page-1).'" >'. __('<span class="meta-nav">&larr;</span> Previous', 'framemarket').'</a></div>';
  722.  
  723.                 } else {
  724.  
  725.                     $content .= '<div class="nav-previous">'. get_previous_posts_link( __('<span class="meta-nav">&larr;</span> Previous', 'framemarket'), $total_pages ).'</a></div>';
  726.  
  727.                 }
  728.  
  729.             }
  730.  
  731.             if (  $total_pages > $page ) {
  732.  
  733.                 if ($grid_home) {
  734.  
  735.                     $content .= '<div class="nav-next"><a href="?page='.($page+1).'" >'. __('Next <span class="meta-nav">&rarr;</span>', 'framemarket' ).'</a></div>';
  736.  
  737.                 } else {
  738.  
  739.                     $content .= '<div class="nav-next">'. get_next_posts_link(__('Next <span class="meta-nav">&rarr;</span>', 'framemarket' ), $total_pages).'</div>';
  740.  
  741.                 }
  742.  
  743.             }
  744.  
  745.             $content .= '</div>';
  746.  
  747.         }
  748.  
  749.     }
  750.  
  751.  
  752.  
  753.     $content .= '</div>';
  754.  
  755.  
  756.  
  757.   if ($echo)
  758.  
  759.     echo $content;
  760.  
  761.   else
  762.  
  763.     return $content;
  764.  
  765. }
  766.  
  767.  
  768.  
  769. function framemarket_mp_list_categories( $echo = true, $args = '' ) {
  770.  
  771.   $args['taxonomy'] = 'product_category';
  772.  
  773.   $args['echo'] = false;
  774.  
  775.   $args['title_li'] = '';
  776.  
  777.  
  778.  
  779.   $list = '<ul id="mp_category_list">' . wp_list_categories( $args ) . '</ul>';
  780.  
  781.  
  782.  
  783.   if ($echo)
  784.  
  785.     echo $list;
  786.  
  787.   else
  788.  
  789.     return $list;
  790.  
  791. }
  792.  
  793.  
  794.  
  795. function framemarket_global_categories_theme($content) {
  796.  
  797.   global $wp_query;
  798.  
  799.  
  800.  
  801.   if ( $slug = get_query_var('global_taxonomy') ) {
  802.  
  803.     $args = array();
  804.  
  805.     $args['echo'] = false;
  806.  
  807.     $args['category'] = $slug;
  808.  
  809.  
  810.  
  811.     //check for paging
  812.  
  813.     if (get_query_var('paged'))
  814.  
  815.       $args['page'] = intval(get_query_var('paged'));
  816.  
  817.  
  818.  
  819.     $content = framemarket_mp_list_global_products( $args );
  820.  
  821.     $content .= get_posts_nav_link();
  822.  
  823.  
  824.  
  825.   } else { //no category set, so show list
  826.  
  827.     $content .= mp_global_categories_list( array( 'echo' => false ) );
  828.  
  829.   }
  830.  
  831.  
  832.  
  833.   return $content;
  834.  
  835. }
  836.  
  837.  
  838.  
  839. function framemarket_product_meta() {
  840.  
  841.    global $post, $id;
  842.  
  843.    $post_id = ( NULL === $post->ID ) ? $id : $post->ID;
  844.  
  845.  
  846.  
  847.    //don't filter outside of the loop
  848.  
  849.     if ( !in_the_loop() )
  850.  
  851.           return $content;
  852.  
  853.  
  854.  
  855.    $content = '<div class="product-meta-details">';
  856.  
  857.    $content .= mp_category_list($post_id, '<span class="grid_mp_product_categories">' . __( 'Categorized in ', 'mp' ), ', ', '</span>');
  858.  
  859.    $content .= '&nbsp;&nbsp;';
  860.  
  861.    $content .= mp_tag_list($post_id, '<span class="grid_mp_product_tags">'.__('Tagged in ', 'mp'), ', ', '</span>');
  862.  
  863.    $content .= '</div><hr/><div class="product-meta-details">';
  864.  
  865.    $content .= mp_product_price(false);
  866.  
  867.    $content .= mp_pinit_button();
  868.  
  869.    $content .= mp_buy_button(false, 'single');
  870.  
  871.    $content .= '</div><hr />';
  872.  
  873.  
  874.  
  875.    return $content;
  876.  
  877.  }
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885. function framemarket_mp_order_status() {
  886.  
  887.   global $mp, $wp_query;
  888.  
  889.     $settings = get_option('mp_settings');
  890.  
  891.   echo $settings['msg']['order_status'];
  892.  
  893.  
  894.  
  895.   $order_id = ($wp_query->query_vars['order_id']) ? $wp_query->query_vars['order_id'] : $_GET['order_id'];
  896.  
  897.  
  898.  
  899.   if (!empty($order_id)) {
  900.  
  901.     //get order
  902.  
  903.     $order = $mp->get_order($order_id);
  904.  
  905.  
  906.  
  907.     if ($order) { //valid order
  908.  
  909.       echo '<hr/><h2><em>' . sprintf( __('Order Details (%s):', 'mp'), htmlentities($order_id)) . '</em></h2>';
  910.  
  911.       ?>
  912.  
  913.       <h3><?php _e('Current Status', 'mp'); ?></h3>
  914.  
  915.       <ul>
  916.  
  917.       <?php
  918.  
  919.       //get times
  920.  
  921.       $received = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_received_time);
  922.  
  923.       if ($order->mp_paid_time)
  924.  
  925.         $paid = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_paid_time);
  926.  
  927.       if ($order->mp_shipped_time)
  928.  
  929.         $shipped = date(get_option('date_format') . ' - ' . get_option('time_format'), $order->mp_shipped_time);
  930.  
  931.  
  932.  
  933.       if ($order->post_status == 'order_received') {
  934.  
  935.         echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>';
  936.  
  937.       } else if ($order->post_status == 'order_paid') {
  938.  
  939.         echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>';
  940.  
  941.         echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>';
  942.  
  943.       } else if ($order->post_status == 'order_shipped' || $order->post_status == 'order_closed') {
  944.  
  945.         echo '<li>' . __('Shipped:', 'mp') . ' <strong>' . $shipped . '</strong></li>';
  946.  
  947.         echo '<li>' . __('Paid:', 'mp') . ' <strong>' . $paid . '</strong></li>';
  948.  
  949.         echo '<li>' . __('Received:', 'mp') . ' <strong>' . $received . '</strong></li>';
  950.  
  951.       }
  952.  
  953.  
  954.  
  955.       $order_paid = $order->post_status != 'order_received';
  956.  
  957.       $max_downloads = intval($settings['max_downloads']) ? intval($settings['max_downloads']) : 5;
  958.  
  959.       ?>
  960.  
  961.       </ul>
  962.  
  963. <hr/>
  964.  
  965.       <h3><?php _e('Payment Information:', 'mp'); ?></h3>
  966.  
  967.       <ul>
  968.  
  969.         <li>
  970.  
  971.           <?php _e('Payment Method:', 'mp'); ?>
  972.  
  973.           <strong><?php echo $order->mp_payment_info['gateway_public_name']; ?></strong>
  974.  
  975.         </li>
  976.  
  977.         <li>
  978.  
  979.           <?php _e('Payment Type:', 'mp'); ?>
  980.  
  981.           <strong><?php echo $order->mp_payment_info['method']; ?></strong>
  982.  
  983.         </li>
  984.  
  985.         <li>
  986.  
  987.           <?php _e('Transaction ID:', 'mp'); ?>
  988.  
  989.           <strong><?php echo $order->mp_payment_info['transaction_id']; ?></strong>
  990.  
  991.         </li>
  992.  
  993.         <li>
  994.  
  995.           <?php _e('Payment Total:', 'mp'); ?>
  996.  
  997.           <strong><?php echo $mp->format_currency($order->mp_payment_info['currency'], $order->mp_payment_info['total']) . ' ' . $order->mp_payment_info['currency']; ?></strong>
  998.  
  999.         </li>
  1000.  
  1001.       </ul>
  1002.  
  1003.  
  1004.  
  1005. <hr/>
  1006.  
  1007.       <h3><?php _e('Order Information:', 'mp'); ?></h3>
  1008.  
  1009.       <table id="mp-order-product-table" class="mp_cart_contents">
  1010.  
  1011.         <thead><tr>
  1012.  
  1013.           <th class="mp_cart_col_thumb">&nbsp;</th>
  1014.  
  1015.           <th class="mp_cart_col_product"><?php _e('Item', 'mp'); ?></th>
  1016.  
  1017.           <th class="mp_cart_col_quant"><?php _e('Quantity', 'mp'); ?></th>
  1018.  
  1019.           <th class="mp_cart_col_price"><?php _e('Price', 'mp'); ?></th>
  1020.  
  1021.           <th class="mp_cart_col_subtotal"><?php _e('Subtotal', 'mp'); ?></th>
  1022.  
  1023.           <th class="mp_cart_col_downloads"><?php _e('Download', 'mp'); ?></th>
  1024.  
  1025.         </tr></thead>
  1026.  
  1027.         <tbody>
  1028.  
  1029.         <?php
  1030.  
  1031.           if (is_array($order->mp_cart_info) && count($order->mp_cart_info)) {
  1032.  
  1033.                         foreach ($order->mp_cart_info as $product_id => $variations) {
  1034.  
  1035.                             //for compatibility for old orders from MP 1.x
  1036.  
  1037.                             if (isset($variations['name'])) {
  1038.  
  1039.                 $data = $variations;
  1040.  
  1041.                 echo '<tr>';
  1042.  
  1043.                   echo '  <td class="mp_cart_col_thumb">' . mp_product_image( false, 'widget', $product_id ) . '</td>';
  1044.  
  1045.                   echo '  <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a></td>';
  1046.  
  1047.                   echo '  <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>';
  1048.  
  1049.                   echo '  <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>';
  1050.  
  1051.                   echo '  <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>';
  1052.  
  1053.                   echo '  <td class="mp_cart_col_downloads"></td>';
  1054.  
  1055.                   echo '</tr>';
  1056.  
  1057.                             } else {
  1058.  
  1059.                                 foreach ($variations as $variation => $data) {
  1060.  
  1061.                       echo '<tr>';
  1062.  
  1063.                       echo '  <td class="mp_cart_col_thumb">' . mp_product_image( false, 'widget', $product_id ) . '</td>';
  1064.  
  1065.                       echo '  <td class="mp_cart_col_product"><a href="' . get_permalink($product_id) . '">' . esc_attr($data['name']) . '</a></td>';
  1066.  
  1067.                       echo '  <td class="mp_cart_col_quant">' . number_format_i18n($data['quantity']) . '</td>';
  1068.  
  1069.                       echo '  <td class="mp_cart_col_price">' . $mp->format_currency('', $data['price']) . '</td>';
  1070.  
  1071.                       echo '  <td class="mp_cart_col_subtotal">' . $mp->format_currency('', $data['price'] * $data['quantity']) . '</td>';
  1072.  
  1073.                                     if (is_array($data['download']) && $download_url = $mp->get_download_url($product_id, $order->post_title)) {
  1074.  
  1075.                     if ($order_paid) {
  1076.  
  1077.                       //check for too many downloads
  1078.  
  1079.                                             if (intval($data['download']['downloaded']) < $max_downloads)
  1080.  
  1081.                                                 echo '  <td class="mp_cart_col_downloads"><a href="' . $download_url . '">' . __('Download&raquo;', 'mp') . '</a></td>';
  1082.  
  1083.                                             else
  1084.  
  1085.                                               echo '  <td class="mp_cart_col_downloads">' . __('Limit Reached', 'mp') . '</td>';
  1086.  
  1087.                                         } else {
  1088.  
  1089.                                           echo '  <td class="mp_cart_col_downloads">' . __('Awaiting Payment', 'mp') . '</td>';
  1090.  
  1091.                                         }
  1092.  
  1093.                                     } else {
  1094.  
  1095.                                         echo '  <td class="mp_cart_col_downloads"></td>';
  1096.  
  1097.                                     }
  1098.  
  1099.                       echo '</tr>';
  1100.  
  1101.                                 }
  1102.  
  1103.                             }
  1104.  
  1105.             }
  1106.  
  1107.           } else {
  1108.  
  1109.             echo '<tr><td colspan="6">' . __('No products could be found for this order', 'mp') . '</td></tr>';
  1110.  
  1111.           }
  1112.  
  1113.           ?>
  1114.  
  1115.         </tbody>
  1116.  
  1117.       </table>
  1118.  
  1119.       <ul>
  1120.  
  1121.         <?php //coupon line
  1122.  
  1123.         if ( $order->mp_discount_info ) { ?>
  1124.  
  1125.         <li><?php _e('Coupon Discount:', 'mp'); ?> <strong><?php echo $order->mp_discount_info['discount']; ?></strong></li>
  1126.  
  1127.         <?php } ?>
  1128.  
  1129.  
  1130.  
  1131.         <?php //shipping line
  1132.  
  1133.         if ( $order->mp_shipping_total ) { ?>
  1134.  
  1135.         <li><?php _e('Shipping:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_shipping_total); ?></strong></li>
  1136.  
  1137.         <?php } ?>
  1138.  
  1139.  
  1140.  
  1141.         <?php //tax line
  1142.  
  1143.         if ( $order->mp_tax_total ) { ?>
  1144.  
  1145.         <li><?php _e('Taxes:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_tax_total); ?></strong></li>
  1146.  
  1147.         <?php } ?>
  1148.  
  1149.  
  1150.  
  1151.         <li><?php _e('Order Total:', 'mp'); ?> <strong><?php echo $mp->format_currency('', $order->mp_order_total); ?></strong></li>
  1152.  
  1153.       </ul>
  1154.  
  1155. <hr/>
  1156.  
  1157.       <h3><?php _e('Shipping Information:', 'mp'); ?></h3>
  1158.  
  1159.       <table>
  1160.  
  1161.         <tr>
  1162.  
  1163.         <td align="right"><?php _e('Full Name:', 'mp'); ?></td><td>
  1164.  
  1165.         <?php echo esc_attr($order->mp_shipping_info['name']); ?></td>
  1166.  
  1167.         </tr>
  1168.  
  1169.  
  1170.  
  1171.         <tr>
  1172.  
  1173.         <td align="right"><?php _e('Address:', 'mp'); ?></td>
  1174.  
  1175.         <td><?php echo esc_attr($order->mp_shipping_info['address1']); ?></td>
  1176.  
  1177.         </tr>
  1178.  
  1179.  
  1180.  
  1181.         <?php if ($order->mp_shipping_info['address2']) { ?>
  1182.  
  1183.         <tr>
  1184.  
  1185.         <td align="right"><?php _e('Address 2:', 'mp'); ?></td>
  1186.  
  1187.         <td><?php echo esc_attr($order->mp_shipping_info['address2']); ?></td>
  1188.  
  1189.         </tr>
  1190.  
  1191.         <?php } ?>
  1192.  
  1193.  
  1194.  
  1195.         <tr>
  1196.  
  1197.         <td align="right"><?php _e('City:', 'mp'); ?></td>
  1198.  
  1199.         <td><?php echo esc_attr($order->mp_shipping_info['city']); ?></td>
  1200.  
  1201.         </tr>
  1202.  
  1203.  
  1204.  
  1205.         <?php if ($order->mp_shipping_info['state']) { ?>
  1206.  
  1207.         <tr>
  1208.  
  1209.         <td align="right"><?php _e('State/Province/Region:', 'mp'); ?></td>
  1210.  
  1211.         <td><?php echo esc_attr($order->mp_shipping_info['state']); ?></td>
  1212.  
  1213.         </tr>
  1214.  
  1215.         <?php } ?>
  1216.  
  1217.  
  1218.  
  1219.         <tr>
  1220.  
  1221.         <td align="right"><?php _e('Postal/Zip Code:', 'mp'); ?></td>
  1222.  
  1223.         <td><?php echo esc_attr($order->mp_shipping_info['zip']); ?></td>
  1224.  
  1225.         </tr>
  1226.  
  1227.  
  1228.  
  1229.         <tr>
  1230.  
  1231.         <td align="right"><?php _e('Country:', 'mp'); ?></td>
  1232.  
  1233.         <td><?php echo $mp->countries[$order->mp_shipping_info['country']]; ?></td>
  1234.  
  1235.         </tr>
  1236.  
  1237.  
  1238.  
  1239.         <?php if ($order->mp_shipping_info['phone']) { ?>
  1240.  
  1241.         <tr>
  1242.  
  1243.         <td align="right"><?php _e('Phone Number:', 'mp'); ?></td>
  1244.  
  1245.         <td><?php echo esc_attr($order->mp_shipping_info['phone']); ?></td>
  1246.  
  1247.         </tr>
  1248.  
  1249.         <?php } ?>
  1250.  
  1251.       </table>
  1252.  
  1253.  
  1254.  
  1255.       <?php
  1256.  
  1257.     if (isset($order->mp_order_notes)) {
  1258.  
  1259.         echo '<div class="grid_mp_order_notes"><h3>' . apply_filters('mp_order_status_section_title_order_notes', __('Order Notes', 'mp'), $order) . '</h3>' .
  1260.  
  1261.             wpautop($order->mp_order_notes) . '</div>';
  1262.  
  1263.     }
  1264.  
  1265.       ?>
  1266.  
  1267.  
  1268.  
  1269.       <?php mp_orderstatus_link(true, false, __('&laquo; Back', 'mp')); ?>
  1270.  
  1271.       <?php
  1272.  
  1273.  
  1274.  
  1275.     } else { //not valid order id
  1276.  
  1277.       echo '<hr/><h3>' . __('Invalid Order ID. Please try again:', 'mp') . '</h3>';
  1278.  
  1279.       ?>
  1280.  
  1281.       <form action="<?php mp_orderstatus_link(true, true); ?>" method="get">
  1282.  
  1283.             <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?><br />
  1284.  
  1285.             <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label>
  1286.  
  1287.             <input type="submit" id="order-id-submit" value="<?php _e('Look Up &raquo;', 'mp'); ?>" />
  1288.  
  1289.       </form>
  1290.  
  1291.       <?php
  1292.  
  1293.     }
  1294.  
  1295.  
  1296.  
  1297.   } else {
  1298.  
  1299.  
  1300.  
  1301.     //get from usermeta
  1302.  
  1303.     $user_id = get_current_user_id();
  1304.  
  1305.     if ($user_id) {
  1306.  
  1307.       if (is_multisite()) {
  1308.  
  1309.         global $blog_id;
  1310.  
  1311.         $meta_id = 'mp_order_history_' . $blog_id;
  1312.  
  1313.       } else {
  1314.  
  1315.         $meta_id = 'mp_order_history';
  1316.  
  1317.       }
  1318.  
  1319.       $orders = get_user_meta($user_id, $meta_id, true);
  1320.  
  1321.     } else {
  1322.  
  1323.       //get from cookie
  1324.  
  1325.       if (is_multisite()) {
  1326.  
  1327.         global $blog_id;
  1328.  
  1329.         $cookie_id = 'mp_order_history_' . $blog_id . '_' . COOKIEHASH;
  1330.  
  1331.       } else {
  1332.  
  1333.         $cookie_id = 'mp_order_history_' . COOKIEHASH;
  1334.  
  1335.       }
  1336.  
  1337.  
  1338.  
  1339.       if (isset($_COOKIE[$cookie_id]))
  1340.  
  1341.         $orders = unserialize($_COOKIE[$cookie_id]);
  1342.  
  1343.     }
  1344.  
  1345.  
  1346.  
  1347.     if (is_array($orders) && count($orders)) {
  1348.  
  1349.       krsort($orders);
  1350.  
  1351.       //list orders
  1352.  
  1353.       echo '<hr/><h3>' . __('Your Recent Orders:', 'mp') . '</h3>';
  1354.  
  1355.       echo '<ul id="mp-order-list">';
  1356.  
  1357.       foreach ($orders as $timestamp => $order)
  1358.  
  1359.         echo '  <li><strong>' . date(get_option('date_format') . ' - ' . get_option('time_format'), $timestamp) . ':</strong> <a href="./' . trailingslashit($order['id']) . '">' . $order['id'] . '</a> - ' . $mp->format_currency('', $order['total']) . '</li>';
  1360.  
  1361.       echo '</ul>';
  1362.  
  1363.  
  1364.  
  1365.       ?>
  1366.  
  1367.       <form action="<?php mp_orderstatus_link(true, true); ?>" method="get">
  1368.  
  1369.             <label><?php _e('Or enter your 12-digit Order ID number:', 'mp'); ?><br />
  1370.  
  1371.             <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label>
  1372.  
  1373.             <input type="submit" id="order-id-submit" value="<?php _e('Look Up &raquo;', 'mp'); ?>" />
  1374.  
  1375.       </form>
  1376.  
  1377.       <?php
  1378.  
  1379.  
  1380.  
  1381.     } else {
  1382.  
  1383.  
  1384.  
  1385.       if (!is_user_logged_in()) {
  1386.  
  1387.         ?>
  1388.  
  1389.         <table class="mp_cart_login">
  1390.  
  1391.           <thead><tr>
  1392.  
  1393.             <th class="mp_cart_login" colspan="2"><?php _e('Have a User Account? Login To View Your Order History:', 'mp'); ?></th>
  1394.  
  1395.             <th>&nbsp;</th>
  1396.  
  1397.           </tr></thead>
  1398.  
  1399.           <tbody>
  1400.  
  1401.           <tr>
  1402.  
  1403.             <td class="mp_cart_login">
  1404.  
  1405.               <form name="loginform" id="loginform" action="<?php echo wp_login_url(); ?>" method="post">
  1406.  
  1407.                     <label><?php _e('Username', 'mp'); ?><br />
  1408.  
  1409.                     <input type="text" name="log" id="user_login" class="input" value="" size="20" /></label>
  1410.  
  1411.                 <br />
  1412.  
  1413.                     <label><?php _e('Password', 'mp'); ?><br />
  1414.  
  1415.                     <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
  1416.  
  1417.                 <br />
  1418.  
  1419.                     <input type="submit" name="wp-submit" id="mp_login_submit" value="<?php _e('Login &raquo;', 'mp'); ?>" />
  1420.  
  1421.                     <input type="hidden" name="redirect_to" value="<?php mp_orderstatus_link(true, true); ?>" />
  1422.  
  1423.               </form>
  1424.  
  1425.             </td>
  1426.  
  1427.             <td class="mp_cart_or_label"><?php _e('or', 'mp'); ?></td>
  1428.  
  1429.             <td class="mp_cart_checkout">
  1430.  
  1431.               <form action="<?php mp_orderstatus_link(true, true); ?>" method="get">
  1432.  
  1433.                     <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?><br />
  1434.  
  1435.                     <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label>
  1436.  
  1437.                     <input type="submit" id="order-id-submit" value="<?php _e('Look Up &raquo;', 'mp'); ?>" />
  1438.  
  1439.               </form>
  1440.  
  1441.             </td>
  1442.  
  1443.           </tr>
  1444.  
  1445.           </tbody>
  1446.  
  1447.         </table>
  1448.  
  1449.         <?php
  1450.  
  1451.       } else {
  1452.  
  1453.         ?>
  1454.  
  1455.         <form action="<?php mp_orderstatus_link(true, true); ?>" method="get">
  1456.  
  1457.             <label><?php _e('Enter your 12-digit Order ID number:', 'mp'); ?><br />
  1458.  
  1459.             <input type="text" name="order_id" id="order_id" class="input" value="" size="20" /></label>
  1460.  
  1461.             <input type="submit" id="order-id-submit" value="<?php _e('Look Up &raquo;', 'mp'); ?>" />
  1462.  
  1463.         </form>
  1464.  
  1465.         <?php
  1466.  
  1467.       }
  1468.  
  1469.  
  1470.  
  1471.     }
  1472.  
  1473.   }
  1474.  
  1475. }
  1476.  
  1477.  
  1478.  
  1479. function framemarket_page_title_output() {
  1480.  
  1481.     global $wp_query, $wpdb;
  1482.  
  1483.  
  1484.  
  1485.     //filter out nav titles
  1486.  
  1487.     if (!empty($title) && $id === false)
  1488.  
  1489.       return $title;
  1490.  
  1491.  
  1492.  
  1493.     if ( $slug = get_query_var('global_taxonomy') ) {
  1494.  
  1495.       $slug = $wpdb->escape( $slug );
  1496.  
  1497.       $name = $wpdb->get_var( "SELECT name FROM {$wpdb->base_prefix}mp_terms WHERE slug = '$slug'" );
  1498.  
  1499.     }
  1500.  
  1501.  
  1502.  
  1503.     switch ($wp_query->query_vars['pagename']) {
  1504.  
  1505.       case 'mp_global_products':
  1506.  
  1507.         return __('Marketplace Products', 'mp');
  1508.  
  1509.         break;
  1510.  
  1511.  
  1512.  
  1513.       case 'mp_global_categories':
  1514.  
  1515.         if ($name)
  1516.  
  1517.           return sprintf( __('Product Category: %s', 'mp'), esc_attr($name) );
  1518.  
  1519.         else
  1520.  
  1521.           return __('Marketplace Product Categories', 'mp');
  1522.  
  1523.         break;
  1524.  
  1525.  
  1526.  
  1527.       case 'mp_global_tags':
  1528.  
  1529.         if ($name)
  1530.  
  1531.           return sprintf( __('Product Tag: %s', 'mp'), esc_attr($name) );
  1532.  
  1533.         else
  1534.  
  1535.           return __('Marketplace Product Tags', 'mp');
  1536.  
  1537.         break;
  1538.  
  1539.  
  1540.  
  1541.       default:
  1542.  
  1543.        return '';
  1544.  
  1545.     }
  1546.  
  1547.   }
  1548.  
  1549. ?>
Advertisement
Add Comment
Please, Sign In to add comment