Advertisement
Guest User

Framemarket - Mark products with inventory enabled

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