PHP - Php Table Column Doesn't Show - Woocommerce
I need to copy a table from one code to another. But I couldn't figure out how to do it properly. Just tried to copy code from one file to another but it doesn't work the same. I need to find where to change the code to show right columns.
https://easyupload.io/maoa9h - zipped cart.php (original code with right table) and review.php (the one that doesn't show right table)
We need to copy the table from cart.php: But it doesn't work. The quantity column doesn't show in review.php - as you can see here https://ibb.co/brP0yy1 Similar TutorialsHello Guys.
I am having a trouble viewing a specific column content both in phpMyAdmin and console.It only shows a partial info about the contents inside that column.
I have attached a screenshot of this to give you a demonstration inside that link:
http://i59.tinypic.com/2n6ymqf.jpg
as you can see , the user picked hamburger ,steak and ground beef (and some more), but it seems that it stops showing it right in the middle of the word. Is there any limit for characters in this case?
What would be possible to figure that out please?
Thanks in advance..
Edited by osherdo, 17 December 2014 - 09:11 PM. I'm using a woocommerce order report plugin, some customers order multiple products but order report shows only number of order and one product name: I want to see all product names: also I want to see customer notes it doesn't show up
<?php /** * Plugin Name: Custom Order Report * Description: Generates a report on individual WooCommerce products sold during a specified time period. * Version: 1.4.8 */ // Add the Product Sales Report to the WordPress admin add_action('admin_menu', 'hm_psrf_admin_menu'); function hm_psrf_admin_menu() { add_submenu_page('woocommerce', 'Custom Order Report', 'Custom Order Report', 'view_woocommerce_reports', 'hm_sbpf', 'hm_sbpf_page'); } function hm_psrf_default_report_settings() { return array( 'report_time' => '30d', 'report_start' => date('Y-m-d', current_time('timestamp') - (86400 * 31)), 'report_end' => date('Y-m-d', current_time('timestamp') - 86400), 'order_statuses' => array('wc-processing', 'wc-on-hold', 'wc-completed'), 'products' => 'all', 'product_cats' => array(), 'product_ids' => '', 'variations' => 0, 'orderby' => 'quantity', 'orderdir' => 'desc', 'fields' => array('product_id', 'product_sku', 'product_name', 'quantity_sold', 'gross_sales'), 'limit_on' => 0, 'limit' => 10, 'include_header' => 1, 'exclude_free' => 0 ); } // This function generates the Product Sales Report page HTML function hm_sbpf_page() { $savedReportSettings = get_option('hm_psr_report_settings'); if (isset($_POST['op']) && $_POST['op'] == 'preset-del' && !empty($_POST['r']) && isset($savedReportSettings[$_POST['r']])) { unset($savedReportSettings[$_POST['r']]); update_option('hm_psr_report_settings', $savedReportSettings); $_POST['r'] = 0; echo('<script type="text/javascript">location.href = location.href;</script>'); } $reportSettings = (empty($savedReportSettings) ? hm_psrf_default_report_settings() : array_merge(hm_psrf_default_report_settings(), $savedReportSettings[ isset($_POST['r']) && isset($savedReportSettings[$_POST['r']]) ? $_POST['r'] : 0 ] )); // For backwards compatibility with pre-1.4 versions if (!empty($reportSettings['cat'])) { $reportSettings['products'] = 'cats'; $reportSettings['product_cats'] = array($reportSettings['cat']); } $fieldOptions = array( 'order_id' => 'Order ID', /*'product_id' => 'Product ID',*/ 'customer_name' => 'Customer Name', /*'variation_id' => 'Variation ID',*/ 'city' => 'City', 'address' => 'Address', 'product_name' => 'Product Name', 'quantity_sold' => 'Quantity Sold', /*'product_sku' => 'Product SKU',*/ 'gross_sales' => 'Gross Sales', 'product_categories' => 'Schools', /*'variation_attributes' => 'Variation Attributes',*/ /*'gross_after_discount' => 'Gross Sales (After Discounts)'*/ 'ceremony_date' => 'Ceremony Date', 'ceremony_time' => 'Ceremony Time', ); include(dirname(__FILE__).'/admin.php'); } // Hook into WordPress init; this function performs report generation when // the admin form is submitted add_action('init', 'hm_sbpf_on_init', 9999); function hm_sbpf_on_init() { global $pagenow; // Check if we are in admin and on the report page if (!is_admin()) return; if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'hm_sbpf' && !empty($_POST['hm_sbp_do_export'])) { // Verify the nonce check_admin_referer('hm_sbpf_do_export'); $newSettings = array_intersect_key($_POST, hm_psrf_default_report_settings()); foreach ($newSettings as $key => $value) if (!is_array($value)) $newSettings[$key] = htmlspecialchars($value); // Update the saved report settings $savedReportSettings = get_option('hm_psr_report_settings'); $savedReportSettings[0] = array_merge(hm_psrf_default_report_settings(), $newSettings); update_option('hm_psr_report_settings', $savedReportSettings); // Check if no fields are selected or if not downloading if (empty($_POST['fields']) || empty($_POST['hm_sbp_download'])) return; // Assemble the filename for the report download $filename = 'Product Sales - '; if (!empty($_POST['cat']) && is_numeric($_POST['cat'])) { $cat = get_term($_POST['cat'], 'product_cat'); if (!empty($cat->name)) $filename .= addslashes(html_entity_decode($cat->name)).' - '; } $filename .= date('Y-m-d', current_time('timestamp')).'.csv'; // Send headers header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); // Output the report header row (if applicable) and body $stdout = fopen('php://output', 'w'); if (!empty($_POST['include_header'])) hm_sbpf_export_header($stdout); hm_sbpf_export_body($stdout); exit; } } // This function outputs the report header row function hm_sbpf_export_header($dest, $return=false) { $header = array(); foreach ($_POST['fields'] as $field) { switch ($field) { case 'order_id': $header[] = 'Order ID'; break; case 'product_name': $header[] = 'Product Name'; break; case 'quantity_sold': $header[] = 'Quantity Sold'; break; case 'gross_sales': $header[] = 'Gross Sales'; break; case 'product_categories': $header[] = 'Schools'; break; case 'customer_name': $header[] = 'Customer Name'; break; case 'city': $header[] = 'City'; break; case 'address': $header[] = 'Address'; break; case 'ceremony_date': $header[] = 'Ceremony Date'; break; case 'ceremony_time': $header[] = 'Ceremony Time'; break; } } if ($return) return $header; fputcsv($dest, $header); } // This function generates and outputs the report body rows function hm_sbpf_export_body($dest, $return=false) { global $woocommerce, $wpdb; $product_ids = array(); if ($_POST['products'] == 'cats') { $cats = array(); foreach ($_POST['product_cats'] as $cat) if (is_numeric($cat)) $cats[] = $cat; $product_ids = get_objects_in_term($cats, 'product_cat'); } else if ($_POST['products'] == 'ids') { foreach (explode(',', $_POST['product_ids']) as $productId) { $productId = trim($productId); if (is_numeric($productId)) $product_ids[] = $productId; } } // Calculate report start and end dates (timestamps) switch ($_POST['report_time']) { case '0d': $end_date = strtotime('midnight', current_time('timestamp')); $start_date = $end_date; break; case '1d': $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date; break; case '7d': $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date - (86400 * 6); break; case '1cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight -1month'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '0cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '+1cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight +1month'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '+7d': $start_date = strtotime('midnight', current_time('timestamp')) + 86400; $end_date = $start_date + (86400 * 6); break; case '+30d': $start_date = strtotime('midnight', current_time('timestamp')) + 86400; $end_date = $start_date + (86400 * 29); break; case 'custom': $end_date = strtotime('midnight', strtotime($_POST['report_end'])); $start_date = strtotime('midnight', strtotime($_POST['report_start'])); break; default: // 30 days is the default $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date - (86400 * 29); } // Assemble order by string $orderby = (in_array($_POST['orderby'], array('product_id', 'gross', 'gross_after_discount')) ? $_POST['orderby'] : 'quantity'); $orderby .= ' '.($_POST['orderdir'] == 'asc' ? 'ASC' : 'DESC'); // Create a new WC_Admin_Report object include_once($woocommerce->plugin_path().'/includes/admin/reports/class-wc-admin-report.php'); $wc_report = new WC_Admin_Report(); $wc_report->start_date = $start_date; $wc_report->end_date = $end_date; //echo(date('Y-m-d', $end_date)); $where_meta = array(); if ($_POST['products'] != 'all') { $where_meta[] = array( 'type' => 'order_item_meta', 'meta_key' => '_product_id', 'operator' => 'in', 'meta_value' => $product_ids ); } if (!empty($_POST['exclude_free'])) { $where_meta[] = array( 'meta_key' => '_line_total', 'meta_value' => 0, 'operator' => '!=', 'type' => 'order_item_meta' ); } // Get report data // Avoid max join size error $wpdb->query('SET SQL_BIG_SELECTS=1'); // Prevent plugins from overriding the order status filter add_filter('woocommerce_reports_order_statuses', 'hm_psrf_report_order_statuses', 9999); // Based on woocoommerce/includes/admin/reports/class-wc-report-sales-by-product.php $sold_products = $wc_report->get_order_report_data(array( 'data' => array( '_product_id' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'product_id' ), '_qty' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'quantity' ), '_line_subtotal' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'gross' ), '_line_total' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'gross_after_discount' ), /*usama*/ 'order_id' => array( 'type' => 'order_item', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'order_id' ) /*usama*/ ), 'query_type' => 'get_results', 'group_by' => 'order_id', 'where_meta' => $where_meta, 'order_by' => $orderby, 'limit' => (!empty($_POST['limit_on']) && is_numeric($_POST['limit']) ? $_POST['limit'] : ''), 'filter_range' => ($_POST['report_time'] != 'all'), 'order_types' => wc_get_order_types('order_count'), 'order_status' => hm_psrf_report_order_statuses() )); // Remove report order statuses filter remove_filter('woocommerce_reports_order_statuses', 'hm_psrf_report_order_statuses', 9999); if ($return) $rows = array(); // Output report rows foreach ($sold_products as $product) { $row = array(); /*usama*/ $order = wc_get_order($product->order_id); $customerName = $order->get_billing_first_name().' '.$order->get_billing_last_name(); $billingCity = $order->get_billing_city(); $billingAddress1 = $order->get_billing_address_1(); //echo $product->order_id; //echo $customerName.$city.$billingAddress1; //echo '<pre>';print_r($order);exit; /*usama*/ foreach ($_POST['fields'] as $field) { switch ($field) { case 'order_id': $row[] = $product->order_id; break; case 'product_name': $row[] = html_entity_decode(get_the_title($product->product_id)); break; case 'quantity_sold': $row[] = $product->quantity; break; case 'gross_sales': $row[] = $product->gross; break; /*case 'variation_id': $row[] = (empty($product->variation_id) ? '' : $product->variation_id); break; case 'product_sku': $row[] = get_post_meta($product->product_id, '_sku', true); break;*/ case 'product_categories': $terms = get_the_terms($product->product_id, 'product_cat'); if (empty($terms)) { $row[] = ''; } else { $categories = array(); foreach ($terms as $term) $categories[] = $term->name; $row[] = implode(', ', $categories); } break; case 'customer_name': $row[] = $customerName; break; case 'city': $row[] = $billingCity; break; case 'address': $row[] = $billingAddress1; break; /*case 'gross_after_discount': $row[] = $product->gross_after_discount; break;*/ /*usama*/ case 'ceremony_date': $row[] = $order->get_meta( '_billing_myfield12', true ); break; case 'ceremony_time': $row[] = $order->get_meta( '_billing_myfield13', true ); break; } } if ($return) $rows[] = $row; else fputcsv($dest, $row); } if ($return) return $rows; } add_action('admin_enqueue_scripts', 'hm_psrf_admin_enqueue_scripts'); function hm_psrf_admin_enqueue_scripts() { wp_enqueue_style('hm_psrf_admin_style', plugins_url('css/hm-product-sales-report.css', __FILE__)); wp_enqueue_style('pikaday', plugins_url('css/pikaday.css', __FILE__)); wp_enqueue_script('moment', plugins_url('js/moment.min.js', __FILE__)); wp_enqueue_script('pikaday', plugins_url('js/pikaday.js', __FILE__)); } // Schedulable email report hook add_filter('pp_wc_get_schedulable_email_reports', 'hm_psrf_add_schedulable_email_reports'); function hm_psrf_add_schedulable_email_reports($reports) { $reports['hm_psr'] = array( 'name' => 'Product Sales Report', 'callback' => 'hm_psrf_run_scheduled_report', 'reports' => array( 'last' => 'Last used settings' ) ); return $reports; } function hm_psrf_run_scheduled_report($reportId, $start, $end, $args=array(), $output=false) { $savedReportSettings = get_option('hm_psr_report_settings'); if (!isset($savedReportSettings[0])) return false; $prevPost = $_POST; $_POST = $savedReportSettings[0]; $_POST['report_time'] = 'custom'; $_POST['report_start'] = date('Y-m-d', $start); $_POST['report_end'] = date('Y-m-d', $end); $_POST = array_merge($_POST, array_intersect_key($args, $_POST)); if ($output) { echo('<table><thead><tr>'); foreach (hm_sbpf_export_header(null, true) as $heading) { echo("<th>$heading</th>"); } echo('</tr></thead><tbody>'); foreach (hm_sbpf_export_body(null, true) as $row) { echo('<tr>'); foreach ($row as $cell) echo('<td>'.htmlspecialchars($cell).'</td>'); echo('</tr>'); } echo('</tbody></table>'); $_POST = $prevPost; return; } $filename = get_temp_dir().'/Product Sales Report.csv'; $out = fopen($filename, 'w'); if (!empty($_POST['include_header'])) hm_sbpf_export_header($out); hm_sbpf_export_body($out); fclose($out); $_POST = $prevPost; return $filename; } function hm_psrf_report_order_statuses() { $wcOrderStatuses = wc_get_order_statuses(); $orderStatuses = array(); if (!empty($_POST['order_statuses'])) { foreach ($_POST['order_statuses'] as $orderStatus) { if (isset($wcOrderStatuses[$orderStatus])) $orderStatuses[] = substr($orderStatus, 3); } } return $orderStatuses; } /* Review/donate notice */ register_activation_hook(__FILE__, 'hm_psrf_first_activate'); function hm_psrf_first_activate() { $pre = 'hm_psr'; $firstActivate = get_option($pre.'_first_activate'); if (empty($firstActivate)) { update_option($pre.'_first_activate', time()); } } if (is_admin() && get_option('hm_psr_rd_notice_hidden') != 1 && time() - get_option('hm_psr_first_activate') >= (14*86400)) { add_action('admin_notices', 'hm_psrf_rd_notice'); add_action('wp_ajax_hm_psrf_rd_notice_hide', 'hm_psrf_rd_notice_hide'); } function hm_psrf_rd_notice() { $pre = 'hm_psr'; $slug = 'product-sales-report-for-woocommerce'; echo(' <div id="'.$pre.'_rd_notice" class="updated notice is-dismissible"><p>Do you use the <strong>Product Sales Report</strong> plugin? Please support our free plugin by <a href="" target="_blank">making a donation</a>!product-sales-report-for-woocommerce Thanks!</p></div> <script>jQuery(document).ready(function($){$(\'#'.$pre.'_rd_notice\').on(\'click\', \'.notice-dismiss\', function(){jQuery.post(ajaxurl, {action:\'hm_psrf_rd_notice_hide\'})});});</script> '); } function hm_psrf_rd_notice_hide() { $pre = 'hm_psr'; update_option($pre.'_rd_notice_hidden', 1); } ?>
hey guys, I'm in the process of transforming my static html website into "something" more dynamic. I came across an article on bilingual website (http://www.jacksonengineering.net/proj_phplanguage.php) and I basically used the same idea for my project. Everything works fine except for one thing - links to different language web pages are generated correctly page.php?lang=pl but when I click on the link, the url loses the variable and looks like page.pl.php What to do? Code: [Select] language.php <?php //the url ? language declaration should have preference over the page name $pagename = basename($_SERVER['PHP_SELF'],".php"); $pagenamearray = explode(".",$pagename); if (count($pagenamearray) == 2){ //there is currently a bi-lingual site page loaded $_SESSION['language'] = $pagenamearray[1]; $urllang = $pagenamearray[1]; }else{ //this page must be a non bi-lingual page $urllang = 'en'; } //check for a language selection on the url if(isset($_GET["lang"])){//language has been passed via url $_SESSION['language'] = htmlspecialchars($_GET["lang"]); //set it what was found } ///if there still is no language set, go with english for a default if(!isset($_SESSION['language'])){ $_SESSION['language'] = 'en'; } //now we think we have the session language figured out // //now check for a version of the current page in the desired language //lets make some things clear first //the current page url is either en or pl from $urllang if($urllang != $_SESSION['language']){ //if the url isn't the same as the $_SESSION if($_SESSION['language'] == 'en'){//if it should be english then load the english header("Location: $pagenamearray[0].php"); exit; } if($_SESSION['language'] == 'pl'){ //construct the name of the file if it existed filename.pl.php $plVersion = $pagenamearray[0] . ".pl.php"; //we have to check if a pl version actually exists of this page if(file_exists($plVersion)){//redirect if it exists header("Location: $plVersion"); exit;//stop executing things }else{$pagelangnotfound = true;} } } ?> Code: [Select] header.php <?php if ($_SESSION['language'] != 'en'){ echo 'Select Language: <a href="'. $_SERVER['PHP_SELF'] . '?lang=en"><img src="img/gb.gif" alt="English" class="off" /></a>'; }else{echo 'Wybierz J&#281;zyk: <img src="img/gb.gif" alt="English" />';} ?> <?php if ($_SESSION['language'] != 'pl'){ echo '<a href="'. $_SERVER['PHP_SELF'] . '?lang=pl"><img src="img/pl.gif" alt="Polish" class="off" /></a>'; }else{ echo '<img src="img/pl.gif" alt="Polish" />'; } ?> Code: [Select] menu.php <?php if($pageOn == 'index.php'){?> id="selected"<?php }?>> <a href="index.php">Main Page</a> Code: [Select] page.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> English content Code: [Select] page.pl.php <?php session_start(); include "language.php"; $pageOn = basename($_SERVER['PHP_SELF']); $mItem = $pageOn; ?> <?php include("header.php"); ?> <?php include("menu.php"); ?> Polish content I'm trying to do a simple PHP form with Securimage Captcha and whenever I add this variable "$securimage = new Securimage();" the page displays nothing. Could someone please help me with this? My php file is already in the securimage directory so that's why I'm pointing directly to the file. I'm trying to expand my knowledge on some more str type functions, and I've always wanted to learn implode and explode, but I was just too lazy. Anyways, for some reason, if I type in: salad,pizza,apples - the first value in the array, salad, doesn't show up. o.O <?php $favorite_food = $_POST['favorite_food']; if(!$favorite_food) { ?> <form action="words.php" method="POST"> <input type="text" name="favorite_food"> <input type="submit"> </form> <?php } else { $ex = explode(",", $favorite_food); $amount = count($ex) + 1; while($i < $amount) { echo $ex[$i]."<br/>"; ++$i; } } ?> I know arrays start at 0, so thats why I added 1 to the count. Hi im trying to pass a variable through a url. Here's the code : echo"<td class='tableContent'><span onmouseover=\"tooltip.show('Click to add details to ".$result['workObject']."');\" onmouseout=\"tooltip.hide();\"><a href='addRemarksBucc.php?workObject=".$result['workObject']."'>".$result['systemRemarks']."</a></span></td>"; and here's the code to the next page: <table width="550" border="0" cellspacing="5" cellpadding="0"> <tr> <td width="78" valign="top">Work Object</td> <td><input name="workObject" id="workObject" type="text" value="<?php $_GET['workObject']; ?>" /></td> </tr> <tr> <td valign="top">Remark Details</td> <td><textarea name="errorMessage2" cols="50" rows="10" id="errorMessage2" accesskey="p" tabindex="1"></textarea> <input name="workObject2" type="hidden" value="" /></td> </tr> <tr> <td valign="top"> </td> <td> </td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" class="btn" id="submit" accesskey="R" tabindex="11" value="Submit" /> <input name="reset" type="reset" class="btn" id="reset" accesskey="e" tabindex="12" value="Reset" /></td> </tr> </table> What am I doing wrong? The address bar shows the right url but the second page doesn't display any value for workObject. Thanks! Hi, I have this script that returns the entire table including column names and the row data. However I only want certain column names and the corresponding data to be returned. Code: [Select] <?php include_once("data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database"); mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database"); // sending query $result = mysql_query("SELECT * FROM members"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: members</h1>"; echo "<table border='1'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_query($result); ?> Any help is always appreciated I have a page that shows entries in a guestbook I'm making, and below the entries there is supposed to be a form to write an entry. Except, none of the HTML after the script to show the entries shows up on the page. I have no clue what's wrong. Here is the script to show the entries. $n is name, $d is date, $s is site (optional), and $m is message. $file = fopen("posts.txt", 'rb'); flock($file, LOCK_SH); while(!feof($file)){ $entry = fgetcsv($file, 0, '|'); if(empty($entry)){exit;} $d = $entry[1]; $n = $entry[2]; $s = $entry[3]; $m = $entry[4]; echo ' <table style="border: #3399AA 1px solid;"><tr style="background: #3399AA; font: bold 10px verdana,sans-serif; color: #FFFFFF;"> <td width="170">'.$n.'</td> <td align="right" width="170">'.$d.'</td> </tr> '; if($s != 'none'){ echo ' <tr><td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;"> <b>Site: </b><a href="'.$s.'">'.$s.'</a> <center><div style="width: 250; height: 1px; background: #3399AA; margin: 10px;"></div></center></td></tr> '; } echo ' <tr> <td colspan="2" style="font: 10px verdana,sans-serif; color: #3399AA;">'.$m.'</td> </tr></table><br> '; } flock($file, LOCK_UN); fclose($file); The file it is reading looks like this: Code: [Select] |11:51 am, 3rd Nov 2010|Memoria|none|Hello. :) |11:51 am, 3rd Nov 2010|Memoria|http://sitehere|Hello again. |11:51 am, 3rd Nov 2010|Memoria|none|How are you doing? Thanks! Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. Greetings! I'm a newbie in php programming started with learning wordpress. I'm working on a local machine and trying to modifying a woocommerce order report plugin. The issue i'm facing is this order report plugin shows only 1 product name even though customer ordered multiple products. I want to show all product names. Your help will be much appreciated
<?php // Add the Product Sales Report to the WordPress admin add_action('admin_menu', 'hm_psrf_admin_menu'); function hm_psrf_admin_menu() { add_submenu_page('woocommerce', 'Custom Order Report', 'Custom Order Report', 'view_woocommerce_reports', 'hm_sbpf', 'hm_sbpf_page'); } function hm_psrf_default_report_settings() { return array( 'report_time' => '30d', 'report_start' => date('Y-m-d', current_time('timestamp') - (86400 * 31)), 'report_end' => date('Y-m-d', current_time('timestamp') - 86400), 'order_statuses' => array('wc-processing', 'wc-on-hold', 'wc-completed'), 'products' => 'all', 'product_cats' => array(), 'product_ids' => '', 'variations' => 0, 'orderby' => 'quantity', 'orderdir' => 'desc', 'fields' => array('product_id', 'product_sku', 'product_name', 'quantity_sold', 'gross_sales'), 'limit_on' => 0, 'limit' => 10, 'include_header' => 1, 'exclude_free' => 0 ); } // This function generates the Product Sales Report page HTML function hm_sbpf_page() { $savedReportSettings = get_option('hm_psr_report_settings'); if (isset($_POST['op']) && $_POST['op'] == 'preset-del' && !empty($_POST['r']) && isset($savedReportSettings[$_POST['r']])) { unset($savedReportSettings[$_POST['r']]); update_option('hm_psr_report_settings', $savedReportSettings); $_POST['r'] = 0; echo('<script type="text/javascript">location.href = location.href;</script>'); } $reportSettings = (empty($savedReportSettings) ? hm_psrf_default_report_settings() : array_merge(hm_psrf_default_report_settings(), $savedReportSettings[ isset($_POST['r']) && isset($savedReportSettings[$_POST['r']]) ? $_POST['r'] : 0 ] )); // For backwards compatibility with pre-1.4 versions if (!empty($reportSettings['cat'])) { $reportSettings['products'] = 'cats'; $reportSettings['product_cats'] = array($reportSettings['cat']); } $fieldOptions = array( 'order_id' => 'Order ID', /*'product_id' => 'Product ID',*/ 'customer_name' => 'Customer Name', /*'variation_id' => 'Variation ID',*/ 'city' => 'City', 'address' => 'Address', 'product_name' => 'Product Name', 'quantity_sold' => 'Quantity Sold', /*'product_sku' => 'Product SKU',*/ 'gross_sales' => 'Gross Sales', 'product_categories' => 'Schools', /*'variation_attributes' => 'Variation Attributes',*/ /*'gross_after_discount' => 'Gross Sales (After Discounts)'*/ 'ceremony_date' => 'Ceremony Date', 'ceremony_time' => 'Ceremony Time', 'customer_note' => 'Additional Information', ); include(dirname(__FILE__).'/admin.php'); } // Hook into WordPress init; this function performs report generation when // the admin form is submitted add_action('init', 'hm_sbpf_on_init', 9999); function hm_sbpf_on_init() { global $pagenow; // Check if we are in admin and on the report page if (!is_admin()) return; if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'hm_sbpf' && !empty($_POST['hm_sbp_do_export'])) { // Verify the nonce check_admin_referer('hm_sbpf_do_export'); $newSettings = array_intersect_key($_POST, hm_psrf_default_report_settings()); foreach ($newSettings as $key => $value) if (!is_array($value)) $newSettings[$key] = htmlspecialchars($value); // Update the saved report settings $savedReportSettings = get_option('hm_psr_report_settings'); $savedReportSettings[0] = array_merge(hm_psrf_default_report_settings(), $newSettings); update_option('hm_psr_report_settings', $savedReportSettings); // Check if no fields are selected or if not downloading if (empty($_POST['fields']) || empty($_POST['hm_sbp_download'])) return; // Assemble the filename for the report download $filename = 'Product Sales - '; if (!empty($_POST['cat']) && is_numeric($_POST['cat'])) { $cat = get_term($_POST['cat'], 'product_cat'); if (!empty($cat->name)) $filename .= addslashes(html_entity_decode($cat->name)).' - '; } $filename .= date('Y-m-d', current_time('timestamp')).'.csv'; // Send headers header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$filename.'"'); // Output the report header row (if applicable) and body $stdout = fopen('php://output', 'w'); if (!empty($_POST['include_header'])) hm_sbpf_export_header($stdout); hm_sbpf_export_body($stdout); exit; } } // This function outputs the report header row function hm_sbpf_export_header($dest, $return=false) { $header = array(); foreach ($_POST['fields'] as $field) { switch ($field) { case 'order_id': $header[] = 'Order ID'; break; case 'product_name': $header[] = 'Product Name'; break; case 'quantity_sold': $header[] = 'Quantity Sold'; break; case 'gross_sales': $header[] = 'Gross Sales'; break; case 'product_categories': $header[] = 'Schools'; break; case 'customer_name': $header[] = 'Customer Name'; break; case 'city': $header[] = 'City'; break; case 'address': $header[] = 'Address'; break; case 'ceremony_date': $header[] = 'Ceremony Date'; break; case 'ceremony_time': $header[] = 'Ceremony Time'; break; case 'customer_note': $header[] = 'Additional Information'; break; } } if ($return) return $header; fputcsv($dest, $header); } // This function generates and outputs the report body rows function hm_sbpf_export_body($dest, $return=false) { global $woocommerce, $wpdb; $product_ids = array(); if ($_POST['products'] == 'cats') { $cats = array(); foreach ($_POST['product_cats'] as $cat) if (is_numeric($cat)) $cats[] = $cat; $product_ids = get_objects_in_term($cats, 'product_cat'); } else if ($_POST['products'] == 'ids') { foreach (explode(',', $_POST['product_ids']) as $productId) { $productId = trim($productId); if (is_numeric($productId)) $product_ids[] = $productId; } } // Calculate report start and end dates (timestamps) switch ($_POST['report_time']) { case '0d': $end_date = strtotime('midnight', current_time('timestamp')); $start_date = $end_date; break; case '1d': $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date; break; case '7d': $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date - (86400 * 6); break; case '1cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight -1month'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '0cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '+1cm': $start_date = strtotime(date('Y-m', current_time('timestamp')).'-01 midnight +1month'); $end_date = strtotime('+1month', $start_date) - 86400; break; case '+7d': $start_date = strtotime('midnight', current_time('timestamp')) + 86400; $end_date = $start_date + (86400 * 6); break; case '+30d': $start_date = strtotime('midnight', current_time('timestamp')) + 86400; $end_date = $start_date + (86400 * 29); break; case 'custom': $end_date = strtotime('midnight', strtotime($_POST['report_end'])); $start_date = strtotime('midnight', strtotime($_POST['report_start'])); break; default: // 30 days is the default $end_date = strtotime('midnight', current_time('timestamp')) - 86400; $start_date = $end_date - (86400 * 29); } // Assemble order by string $orderby = (in_array($_POST['orderby'], array('product_id', 'gross', 'gross_after_discount')) ? $_POST['orderby'] : 'quantity'); $orderby .= ' '.($_POST['orderdir'] == 'asc' ? 'ASC' : 'DESC'); // Create a new WC_Admin_Report object include_once($woocommerce->plugin_path().'/includes/admin/reports/class-wc-admin-report.php'); $wc_report = new WC_Admin_Report(); $wc_report->start_date = $start_date; $wc_report->end_date = $end_date; //echo(date('Y-m-d', $end_date)); $where_meta = array(); if ($_POST['products'] != 'all') { $where_meta[] = array( 'type' => 'order_item_meta', 'meta_key' => '_product_id', 'operator' => 'in', 'meta_value' => $product_ids ); } if (!empty($_POST['exclude_free'])) { $where_meta[] = array( 'meta_key' => '_line_total', 'meta_value' => 0, 'operator' => '!=', 'type' => 'order_item_meta' ); } // Get report data // Avoid max join size error $wpdb->query('SET SQL_BIG_SELECTS=1'); // Prevent plugins from overriding the order status filter add_filter('woocommerce_reports_order_statuses', 'hm_psrf_report_order_statuses', 9999); // Based on woocoommerce/includes/admin/reports/class-wc-report-sales-by-product.php $sold_products = $wc_report->get_order_report_data(array( 'data' => array( '_product_id' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'product_id' ), '_qty' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'quantity' ), '_line_subtotal' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'gross' ), '_line_total' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'gross_after_discount' ), /*usama*/ 'order_id' => array( 'type' => 'order_item', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'order_id' ) /*usama*/ ), 'query_type' => 'get_results', 'group_by' => 'order_id', 'where_meta' => $where_meta, 'order_by' => $orderby, 'limit' => (!empty($_POST['limit_on']) && is_numeric($_POST['limit']) ? $_POST['limit'] : ''), 'filter_range' => ($_POST['report_time'] != 'all'), 'order_types' => wc_get_order_types('order_count'), 'order_status' => hm_psrf_report_order_statuses() )); // Remove report order statuses filter remove_filter('woocommerce_reports_order_statuses', 'hm_psrf_report_order_statuses', 9999); if ($return) $rows = array(); // Output report rows foreach ($sold_products as $product) { $row = array(); /*usama*/ $order = wc_get_order($product->order_id); $customerName = $order->get_billing_first_name().' '.$order->get_billing_last_name(); $billingCity = $order->get_billing_city(); $billingAddress1 = $order->get_billing_address_1(); $note = $order->get_customer_note(); //echo $product->order_id; //echo $customerName.$city.$billingAddress1; //echo '<pre>';print_r($order);exit; /*usama*/ foreach ($_POST['fields'] as $field) { switch ($field) { case 'order_id': $row[] = $product->order_id; break; case 'product_name': $row[] = html_entity_decode(get_the_title($product->product_id)); break; case 'quantity_sold': $row[] = $product->quantity; break; case 'gross_sales': $row[] = $product->gross; break; /*case 'variation_id': $row[] = (empty($product->variation_id) ? '' : $product->variation_id); break; case 'product_sku': $row[] = get_post_meta($product->product_id, '_sku', true); break;*/ case 'product_categories': $terms = get_the_terms($product->product_id, 'product_cat'); if (empty($terms)) { $row[] = ''; } else { $categories = array(); foreach ($terms as $term) $categories[] = $term->name; $row[] = implode(', ', $categories); } break; case 'customer_name': $row[] = $customerName; break; case 'city': $row[] = $billingCity; break; case 'address': $row[] = $billingAddress1; break; case 'customer_note': $row[] = $note; break; /*case 'gross_after_discount': $row[] = $product->gross_after_discount; break;*/ /*usama*/ case 'ceremony_date': $row[] = $order->get_meta( '_billing_myfield12', true ); break; case 'ceremony_time': $row[] = $order->get_meta( '_billing_myfield13', true ); break; case 'customer_note': $row[] = $order->get_meta( '_billing_myfield14', true ); break; } } if ($return) $rows[] = $row; else fputcsv($dest, $row); } if ($return) return $rows; } add_action('admin_enqueue_scripts', 'hm_psrf_admin_enqueue_scripts'); function hm_psrf_admin_enqueue_scripts() { wp_enqueue_style('hm_psrf_admin_style', plugins_url('css/hm-product-sales-report.css', __FILE__)); wp_enqueue_style('pikaday', plugins_url('css/pikaday.css', __FILE__)); wp_enqueue_script('moment', plugins_url('js/moment.min.js', __FILE__)); wp_enqueue_script('pikaday', plugins_url('js/pikaday.js', __FILE__)); } // Schedulable email report hook add_filter('pp_wc_get_schedulable_email_reports', 'hm_psrf_add_schedulable_email_reports'); function hm_psrf_add_schedulable_email_reports($reports) { $reports['hm_psr'] = array( 'name' => 'Product Sales Report', 'callback' => 'hm_psrf_run_scheduled_report', 'reports' => array( 'last' => 'Last used settings' ) ); return $reports; } function hm_psrf_run_scheduled_report($reportId, $start, $end, $args=array(), $output=false) { $savedReportSettings = get_option('hm_psr_report_settings'); if (!isset($savedReportSettings[0])) return false; $prevPost = $_POST; $_POST = $savedReportSettings[0]; $_POST['report_time'] = 'custom'; $_POST['report_start'] = date('Y-m-d', $start); $_POST['report_end'] = date('Y-m-d', $end); $_POST = array_merge($_POST, array_intersect_key($args, $_POST)); if ($output) { echo('<table><thead><tr>'); foreach (hm_sbpf_export_header(null, true) as $heading) { echo("<th>$heading</th>"); } echo('</tr></thead><tbody>'); foreach (hm_sbpf_export_body(null, true) as $row) { echo('<tr>'); foreach ($row as $cell) echo('<td>'.htmlspecialchars($cell).'</td>'); echo('</tr>'); } echo('</tbody></table>'); $_POST = $prevPost; return; } $filename = get_temp_dir().'/Product Sales Report.csv'; $out = fopen($filename, 'w'); if (!empty($_POST['include_header'])) hm_sbpf_export_header($out); hm_sbpf_export_body($out); fclose($out); $_POST = $prevPost; return $filename; } function hm_psrf_report_order_statuses() { $wcOrderStatuses = wc_get_order_statuses(); $orderStatuses = array(); if (!empty($_POST['order_statuses'])) { foreach ($_POST['order_statuses'] as $orderStatus) { if (isset($wcOrderStatuses[$orderStatus])) $orderStatuses[] = substr($orderStatus, 3); } } return $orderStatuses; } /* Review/donate notice */ register_activation_hook(__FILE__, 'hm_psrf_first_activate'); function hm_psrf_first_activate() { $pre = 'hm_psr'; $firstActivate = get_option($pre.'_first_activate'); if (empty($firstActivate)) { update_option($pre.'_first_activate', time()); } } if (is_admin() && get_option('hm_psr_rd_notice_hidden') != 1 && time() - get_option('hm_psr_first_activate') >= (14*86400)) { add_action('admin_notices', 'hm_psrf_rd_notice'); add_action('wp_ajax_hm_psrf_rd_notice_hide', 'hm_psrf_rd_notice_hide'); } function hm_psrf_rd_notice() { $pre = 'hm_psr'; $slug = 'product-sales-report-for-woocommerce'; echo(' <div id="'.$pre.'_rd_notice" class="updated notice is-dismissible"><p>Do you use the <strong>Product Sales Report</strong> plugin? Please support our free plugin by <a href="" target="_blank">making a donation</a>!product-sales-report-for-woocommerce Thanks!</p></div> <script>jQuery(document).ready(function($){$(\'#'.$pre.'_rd_notice\').on(\'click\', \'.notice-dismiss\', function(){jQuery.post(ajaxurl, {action:\'hm_psrf_rd_notice_hide\'})});});</script> '); } function hm_psrf_rd_notice_hide() { $pre = 'hm_psr'; update_option($pre.'_rd_notice_hidden', 1); } ?>
Hi Everyone
I'm working with the woo commerece plugin and i'd like to have a sub heading under the title of each product.
Style and format is sorted however i want a particular Category to show in the sub heading section. I've managed to get as far as showing all categories but i want to narrow this down to just one category that is under a parent category.
Below is the code i am using, could anyone suggest how i could achieve showing any child category selected under a parent category.
Thanks
<?php /** * Single Product title * * @author WooThemes * @package WooCommerce/Templates * @version 1.6.4 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $post, $product; $cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) ); ?> <h1 itemprop="name" class="product_title entry-title"><?php the_title(); ?></h1> <?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Artist:', 'Artist:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?> HI,
I have a wordpress site that uses WooCommerce and also WooThemes "Wish list" extension as part of a shop.
I am wanting to hide the "add to cart" button when a price is 0.00 but retain the "Add to Wish List" button.
I have already spoken to WooThemes and there responce is they do not offer coding assistance, i would have to employee someone to look at this for me..
I do have some code that kind of works... in that it does hide the "add to cart" button but it also hides the "add to wish list" button
<?php /* * Swop the 'Free!' price notice and hide the cart with 'Subscription Item' in WooCommerce */ add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' ); add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' ); add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' ); function hide_free_price_notice( $price ) { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); return 'Subscription Item'; } ?>I'm no programmer so i have no idea if this is a complex fix or something that maybe you guys on a forum can help out with. If it's out of the scope of general foum help i will have to post a job somewhere to see if i can get some help that way. Many Thanks... Hello, I am trying to make the buy product button on all single product pages to open in a popup iframe or simular! I am new to java, php and such and I am looking for how to achieve this?
I have been researching this for over a month and nothing seems to work. I am affiliated with Amazon so I need my woocommerce buy product buttons to open a new smaller popup window in front of my site!
I have already had it set to open as _blank, But I really need all my external product button links to open as a popup! Is this possible? I have tried editing cart.php and I know nothing about java. Please help!!
Thank you in advance,
Dee
Simple question but I couldn't find any straight forward answers.
I have a customer details table with: customer ID, name, address, email.
I also have an delivery table with delivery ID, customer ID, order ID.
How can I link the customer ID column from the customer table to the delivery table so that when changes occur on the customer table they subsequently alter all other tables?
I know it might use foreign keys but I couldn't find any online resource that explained how to use them properly.
Cheers
Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 I'm trying to show on my order printed receipt some checkout fields and extras from the products. The website is www.prontoitaliano.co.uk/shop What needs to appear on the receipt are all the extras options from all the products(See checkboxes in all pasta dishes and checkboxes toppings in "create your own pizza") and 2 fields from the checkout page (Pick up Date, Pick up Time). To send the order to the printer I'm using the "Star cloud PRNT woocommerce" plugin and for the pickup date and time fields "ultimate woocommerce delivery and pickup date time", I've attached below the code that needs to be edited to add more fields to the receipt. I know that probably it's not difficult to solve my issue but I don't have any knowledge of php and I hope you guys can assist me. Also, I've attached a picture showing what is missing on the printed receipt and what result I'm trying to get. Thanks for your time!
<?php function star_cloudprnt_get_column_separated_data($columns) { $max_chars = STAR_CLOUDPRNT_MAX_CHARACTERS_THREE_INCH; $total_columns = count($columns); if ($total_columns == 0) return ""; if ($total_columns == 1) return $columns[0]; if ($total_columns == 2) { $total_characters = strlen($columns[0])+strlen($columns[1]); $total_whitespace = $max_chars - $total_characters; if ($total_whitespace < 0) return ""; return $columns[0].str_repeat(" ", $total_whitespace).$columns[1]; } $total_characters = 0; foreach ($columns as $column) { $total_characters += strlen($column); } $total_whitespace = $max_chars - $total_characters; if ($total_whitespace < 0) return ""; $total_spaces = $total_columns-1; $space_width = floor($total_whitespace / $total_spaces); $result = $columns[0].str_repeat(" ", $space_width); for ($i = 1; $i < ($total_columns-1); $i++) { $result .= $columns[$i].str_repeat(" ", $space_width); } $result .= $columns[$total_columns-1]; return $result; } function star_cloudprnt_get_seperator() { $max_chars = STAR_CLOUDPRNT_MAX_CHARACTERS_THREE_INCH; return str_repeat('_', $max_chars); } function star_cloudprnt_parse_order_status($status) { if ($status === 'wc-pending') return 'Pending Payment'; else if ($status === 'wc-processing') return 'Processing'; else if ($status === 'wc-on-hold') return 'On Hold'; else if ($status === 'wc-completed') return 'Completed'; else if ($status === 'wc-cancelled') return 'Cancelled'; else if ($status === 'wc-refunded') return 'Refunded'; else if ($status === 'wc-failed') return 'Failed'; else return "Unknown"; } function star_cloudprnt_get_codepage_1252_currency_symbol() { $symbol = get_woocommerce_currency_symbol(); if ($symbol === "£") return "\xA3"; // £ pound else if ($symbol === "$") return "\x24"; // $ dollar else if ($symbol === "€") return "\x80"; // € euro return ""; // return blank by default } function star_cloudprnt_get_formatted_variation($variation, $order, $item_id) { $return = ''; if (is_array($variation)) { $variation_list = array(); foreach ($variation as $name => $value) { // If the value is missing, get the value from the item if (!$value) { $meta_name = esc_attr(str_replace('attribute_', '', $name)); $value = $order->get_item_meta($item_id, $meta_name, true); } // If this is a term slug, get the term's nice name if (taxonomy_exists(esc_attr(str_replace('attribute_', '', $name)))) { $term = get_term_by('slug', $value, esc_attr(str_replace('attribute_', '', $name))); if (!is_wp_error($term) && ! empty($term->name)) { $value = $term->name; } } else { $value = ucwords(str_replace( '-', ' ', $value )); } $variation_list[] = wc_attribute_label(str_replace('attribute_', '', $name)) . ': ' . rawurldecode($value); } $return .= implode('||', $variation_list); } return $return; } function star_cloudprnt_create_receipt_items($order, &$printer) { $order_items = $order->get_items(); foreach ($order_items as $item_id => $item_data) { $product_name = $item_data['name']; $product_id = $item_data['product_id']; $variation_id = $item_data['variation_id']; $item_qty = $order->get_item_meta($item_id, "_qty", true); $item_total_price = floatval($order->get_item_meta($item_id, "_line_total", true)) +floatval($order->get_item_meta($item_id, "_line_tax", true)); $item_price = floatval($item_total_price) / intval($item_qty); $currencyHex = star_cloudprnt_get_codepage_1252_currency_symbol(); $formatted_item_price = number_format($item_price, 2, '.', ''); $formatted_total_price = number_format($item_total_price, 2, '.', ''); $printer->set_text_emphasized(); $printer->add_text_line(str_replace('–', '-', $product_name)." - ID: ".$product_id.""); $printer->cancel_text_emphasized(); if ($variation_id != 0) { $product_variation = new WC_Product_Variation( $variation_id ); $variation_data = $product_variation->get_variation_attributes(); $variation_detail = star_cloudprnt_get_formatted_variation($variation_data, $order, $item_id); $exploded = explode("||", $variation_detail); foreach($exploded as $exploded_variation) { $printer->add_text_line(" ".ucwords($exploded_variation)); } } $printer->add_text_line(star_cloudprnt_get_column_separated_data(array(" Qty: ". $item_qty." x Cost: ".$currencyHex.$formatted_item_price, $currencyHex.$formatted_total_price))); } } function star_cloudprnt_create_address($order, $order_meta, &$printer) { $fname = $order_meta[_shipping_first_name][0]; $lname = $order_meta[_shipping_last_name][0]; $a1 = $order_meta[_shipping_address_1][0]; $a2 = $order_meta[_shipping_address_2][0]; $city = $order_meta[_shipping_city][0]; $state = $order_meta[_shipping_state][0]; $postcode = $order_meta[_shipping_postcode][0]; $tel = $order_meta[_billing_phone][0]; $printer->set_text_emphasized(); if ($a1 == '') { $printer->add_text_line("Billing Address:"); $printer->cancel_text_emphasized(); $fname = $order_meta[_billing_first_name][0]; $lname = $order_meta[_billing_last_name][0]; $a1 = $order_meta[_billing_address_1][0]; $a2 = $order_meta[_billing_address_2][0]; $city = $order_meta[_billing_city][0]; $state = $order_meta[_billing_state][0]; $postcode = $order_meta[_billing_postcode][0]; } else { $printer->add_text_line("Shipping Address:"); $printer->cancel_text_emphasized(); } $printer->add_text_line($fname." ".$lname); $printer->add_text_line($a1); if ($a2 != '') $printer->add_text_line($a2); if ($city != '') $printer->add_text_line($city); if ($state != '') $printer->add_text_line($state); if ($postcode != '') $printer->add_text_line($postcode); $printer->add_text_line("Tel: ".$tel); } function star_cloudprnt_print_order_summary($selectedPrinter, $file, $order_id) { $order = wc_get_order($order_id); $shipping_items = @array_shift($order->get_items('shipping')); $order_meta = get_post_meta($order_id); $printer = new Star_CloudPRNT_Star_Line_Mode_Job($selectedPrinter, $file); $printer->set_codepage("20"); // 20 hex == 32 decimal == 1252 Windows Latin-1 if (get_option('star-cloudprnt-print-logo-top-input')) $printer->add_nv_logo(esc_attr(get_option('star-cloudprnt-print-logo-top-input'))); $printer->set_text_emphasized(); $printer->set_text_center_align(); $printer->add_text_line("ORDER NOTIFICATION"); $printer->set_text_left_align(); $printer->cancel_text_emphasized(); $printer->add_new_line(1); $printer->add_text_line(star_cloudprnt_get_column_separated_data(array("Order #".$order_id, date("d-m-y H:i:s", time())))); $printer->add_new_line(1); $printer->add_text_line("Order Status: ".star_cloudprnt_parse_order_status($order->post->post_status)); $printer->add_text_line("Order Date: ".$order->order_date); if (isset($shipping_items['name'])) { $printer->add_new_line(1); $printer->add_text_line("Shipping Method: ".$shipping_items['name']); } $printer->add_text_line("Payment Method: ".$order_meta[_payment_method_title][0]); $printer->add_new_line(1); $printer->add_text_line(star_cloudprnt_get_column_separated_data(array('ITEM', 'TOTAL'))); $printer->add_text_line(star_cloudprnt_get_seperator()); star_cloudprnt_create_receipt_items($order, $printer); $printer->add_new_line(1); $printer->set_text_right_align(); $formatted_overall_total_price = number_format($order_meta[_order_total][0], 2, '.', ''); $printer->add_text_line("TOTAL ".star_cloudprnt_get_codepage_1252_currency_symbol().$formatted_overall_total_price); $printer->set_text_left_align(); $printer->add_new_line(1); $printer->add_text_line("All prices are inclusive of tax (if applicable)."); $printer->add_new_line(1); star_cloudprnt_create_address($order, $order_meta, $printer); $printer->add_new_line(1); $printer->set_text_emphasized(); $printer->add_text_line("Customer Provided Notes:"); $printer->cancel_text_emphasized(); $printer->add_text(empty($order->post->post_excerpt) ? "None" : $order->post->post_excerpt); if (get_option('star-cloudprnt-print-logo-bottom-input')) $printer->add_nv_logo(esc_attr(get_option('star-cloudprnt-print-logo-bottom-input'))); $printer->printjob(); } function star_cloudprnt_woo_on_thankyou($order_id) { $file = STAR_CLOUDPRNT_PRINTER_PENDING_SAVE_PATH.star_cloudprnt_get_os_path("/order_".$order_id."_".time().".bin"); $selectedPrinter = ""; $printerList = star_cloudprnt_get_printer_list(); if (!empty($printerList)) { foreach ($printerList as $printer) { if (get_option('star-cloudprnt-printer-select') == $printer['name']) { $selectedPrinter = $printer['printerMAC']; break; } } if ($selectedPrinter === "" && count($printerList) === 1) $selectedPrinter = $printer['printerMAC']; if ($selectedPrinter !== "") star_cloudprnt_print_order_summary($selectedPrinter, $file, $order_id); } } function star_cloudprnt_setup_order_handler() { if (selected(get_option('star-cloudprnt-select'), "enable", false) !== "" && star_cloudprnt_is_woo_activated()) { add_action('woocommerce_thankyou', 'star_cloudprnt_woo_on_thankyou', 1, 1); } }
Dear forum, I`m always trying hard, but after 5 hours I really need some help in php coding. My problem deals with my checkout page for woocommerce. At the moment, my legal terms are above the total-order-table where u can find the booked product, order-subtotal, order-total and tex-total. But I need to display the legal terms under my total-order table. I need the terms directly above the "Buy now" button. Do you guys know which file to modify ? I tried everything. Nothing worked for me. You will find a picture in this post. There you can see my problem. Would be pretty nice if you can give me some information. Kind regards,
Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; |