Modify WooCommerce orders page - php

I need to modify my WooCommerce orders page but I don't have the experience for this. At the moment (like in normal case) my orders page looks like this:
Yesterday I've added a second id attribute to each order where I can set a custom customer id (user_id in Wordpress). This field is named "second_customer".
I'm doing this because I want to show the order taken by customer one to an other customer too in case the "second_customer" has his user_id as value.
Now I need to modify the orders.php and modify it so that the orders gets loaded to for the "second_customer" on his account and the normal way too. So my question is: How can I get exacly the row like in the picture (the order) for the user id defined in my custom attribute?

As your question:
How can I get exacly the row like in the picture
use the table HTML elements like will result like the screen shoot above with 5 headings rows with table headings- and table rows- :
<table style="width:100%">
<tr>
<th>Product Id</th>
<th>Date</th>
<th>Status</th>
<th>Address</th>
<th>Name</th>
</tr>
<tr>
<td>#356</td>
<td>30 September</td>
<td>Customer</td>
<td>10 Address st, China</td>
<td>John Doe</td>
</tr>
<tr>
<td>#357</td>
<td>30 September</td>
<td>Customer</td>
<td>32 Address st, Porland</td>
<td>Sarah smith</td>
</tr>
<tr>
<td>#358</td>
<td>29 September</td>
<td>Customer</td>
<td>55 Address st, New York</td>
<td>Ben Barber</td>
</tr>
</table>

Related

PHP & SQL - select all from a db but loop through results by grouped content

I am creating an ecommerce site where we have suppliers that give us prices in different currencies. We might have one supplier that gives us prices in £-GBP and another that gives us prices in €-EUR and other suppliers where they give us prices in both currencies. If they provide prices in both currencies then our GBP customers get the GBP prices and our EUR customers get the EUR prices. If the price is given to us in just one currency then we do the exchange ourselves.
So my database with all of the pricing looks something similar to this table, with two records for the same product if the supplier gives us prices in both currencies:
thead{
background-color:#bbb;
}
td{
padding:10px;
}
<table border='1'>
<thead>
<tr>
<td>Supplier Type</td>
<td>Currency</td>
<td>Product</td>
<td>Attribute</td>
<td>Cost</td>
</tr>
</thead>
<tr>
<td>Supplier-£</td>
<td>£</td>
<td>Hat</td>
<td>Red</td>
<td>10</td>
</tr>
<tr>
<td>Supplier-£</td>
<td>£</td>
<td>Hat</td>
<td>Blue</td>
<td>9</td>
</tr>
<tr>
<td>Supplier-€</td>
<td>€</td>
<td>Shoes</td>
<td>Large</td>
<td>50</td>
</tr>
<tr>
<td>Supplier-€</td>
<td>€</td>
<td>Shoes</td>
<td>Small</td>
<td>45</td>
</tr>
<tr>
<td>Supplier-Both</td>
<td>£</td>
<td>Suit</td>
<td>Large</td>
<td>150</td>
</tr>
<tr>
<td>Supplier-Both</td>
<td>€</td>
<td>Suit</td>
<td>Large</td>
<td>160</td>
</tr>
<tr>
<td>Supplier-Both</td>
<td>£</td>
<td>Suit</td>
<td>Small</td>
<td>100</td>
</tr>
<tr>
<td>Supplier-Both</td>
<td>€</td>
<td>Suit</td>
<td>Small</td>
<td>110</td>
</tr>
</table>
I am looping through this table then to generate a form to update this. However, the way I'm doing it at the moment is creating a line for each line in the DB, I would like to be able to loop through this in a way that is not creating a new line for the same product just because it is another currency. Instead I would like to loop through this so that it creates a line for each product but if that product has costs in both currencies then it should just create two inputs on the one line.
so i would create line for each product and create a dropdown list with the currency values ( can be added dynamic ). its not the easiest way but make it possible to manage the data in consumer way
strcture setup : Example
Old answer :
you should split the table into a product table and a price table. So you can join all prices to the product without handling the association.
Prices
-
PriceID PK int
Price float
Currency money
ProductID int FK >- Product.ProductID
Product
------------
ProductID PK int
Name varchar(200) UNIQUE
EDIT: as mentioned in the comment, the table is splitted

How to get submit button in different table rows to perform different SQL queries?

So I'm having a problem that I've been trying to work on for quite a while now but I don't really know how to do it.
I have multiple submit buttons in a table (one per row). How do I get each submit button to perform a different SQL task? To explain further...
So I have a table that looks something like this (This is the HTML code from View Source, without the underlying PHP code that generates the table contents):
<table class='table table-striped'>
<thead>
<tr>
<th>Date/Time</th>
<th>Exchange</th>
<th>Amount</th>
<th>Current reversed ex. rate</th>
<th>Arbitrage opportunity</th>
<th>Change</th>
</tr>
</thead>
<tbody>
<form action='arbitrage.php' method='post'>
<tr>
<td> 2015-12-24 22:32:50 </td>
<td>JPY to GBP</td>
<td>¥18,000.00 --> £100.80</td>
<td>179.48 GBP / JPY</td>
<td><font color='green'>¥<b>91.584</b> <b><u>PROFIT</u></b> on original ¥18,000.00 if you exchange now. <br/> (Total after change: ¥<b>18,091.584</b>).
</font></td>
<td><button type='submit'>Change</button></td>
</tr></form></tbody>
<tbody>
<form action='arbitrage.php' method='post'>
<tr>
<td> 2015-12-24 22:33:07</td>
<td>GBP to EUR</td>
<td>£15,000.00 --> €20,359.50</td>
<td>0.7365 EUR / GBP</td>
<td><font color='red'>£<b>5.228</b> <b><u>LOSS</u></b> on original £15,000.00 if you exchange now. <br> (Total after change: £<b>14,994.772</b>).
</font></td>
<td><button type='submit'>Change</button></td>
</tr></form></tbody>
To understand even better, this is an image of what the table looks like:
http://i.imgur.com/niyuT14.jpg
Now, when the 'Change' button is pressed, I want the information FROM THAT SPECIFIC ROW to be deleted from my SQL table called 'history'.
At the moment, I have tried things such as:
$query = "DELETE FROM history WHERE currency = ?", $row["currency"];
//row["currency"] is the stuff below the 'Exchange' header in the table.
When I press the 'Change' button however, all the existing rows of the HTML table get deleted from the 'history' SQL table. How do I get only one row to be deleted (the one where the button is pressed) while the others stay exactly where they are?
Please help!
Many thanks guys!
you can add hidden inputs with name='currency' for each row or more easily you can use ajax to submit your query
Change the form action form:
<form action='arbitrage.php' method='post'>
To
<form action='arbitrage.php?id=99' method='post'>
And update your query as:
$id = isset($_GET['id']) ? $_GET['id'] : ''; //This will give you--> id = 99;
$query = "DELETE FROM history WHERE currency = ?", $id;
The value 99 will be of course dynamic from db table.
I see that values are hardcoded and for both the buttons or forms you are using the same arbitrage.php action page. Use different pages for each form or button and write your mysql code as per your wish. And if it is dynamic then you will have to use the JS onClick event.
Instead of having so many forms, have just one. And then in the arbitrage.php, delete the submitted row and come back to the same page, may be..
<form action='arbitrage.php' name='changeForm' method='post'>
<input type="hidden" name="currency">
<table class='table table-striped'>
<thead>
<tr>
<th>Date/Time</th>
<th>Exchange</th>
<th>Amount</th>
<th>Current reversed ex. rate</th>
<th>Arbitrage opportunity</th>
<th>Change</th>
</tr>
</thead>
<tbody>
<tr>
<td> 2015-12-24 22:32:50 </td>
<td>JPY to GBP</td>
<td>¥18,000.00 --> £100.80</td>
<td>179.48 GBP / JPY</td>
<td><font color='green'>¥<b>91.584</b> <b><u>PROFIT</u></b> on original ¥18,000.00 if you exchange now. <br/> (Total after change: ¥<b>18,091.584</b>).
</font></td>
<td><button type='button' onclick="chg_currency('GBP / JPY');">Change</button></td>
</tr></tbody>
<tbody>
<tr>
<td> 2015-12-24 22:33:07</td>
<td>GBP to EUR</td>
<td>£15,000.00 --> €20,359.50</td>
<td>0.7365 EUR / GBP</td>
<td><font color='red'>£<b>5.228</b> <b><u>LOSS</u></b> on original £15,000.00 if you exchange now. <br> (Total after change: £<b>14,994.772</b>).
</font></td>
<td><button type='button' onclick="chg_currency('EUR / GBP');">Change</button></td>
</tr></tbody>
</table>
</form>
<script>
function chg_currency(c) {
document.forms['changeForm'].currency.value = c;
document.foms['changeForm'].submit();
}
</script>

Displaying Student Attendance from mysql database

I have 4 tables for student attendance.
Students (sid, name, regno)
classes (classid, startdate, enddate)
Student to Classes (sid, classid)
class attendance (classid, sid, attendance, date)
I want to display attendance data of a class as:
<table>
<tr>
<th>RegNo</th>
<th>Name</th>
<th>Date 1</th>
<th>Date 2</th>
<th>so on</th>
</tr>
<tr>
<td>1</td>
<td>ABC</td>
<td>Present</td>
<td>Absent</td>
<td>So on</td>
</tr>
</table>
Date range is from classes table. I want to query the tables with date range as well as for all record of a class.
Kindly help me with the query. Thanks in advance.

Split mysql retrieved data into headers and rows

I retrieve data from DB and I need to insert all of them in a table.
I have some constant headers and some that depends on the query results.
Below you can see a table; how i want it to look like:
I did prepare the HTML structure:
<table class="table-fill">
<thead>
<tr>
<th>ID</th>
<th>CODE</th>
<th colspan=2>TREND A</th>
<th colspan=2>TREND B</th>
<th colspan=2>TREND C</th>
</tr>
<tr>
<th></th>
<th></th>
<th>Items</th>
<th>Revenue</th>
<th>Items</th>
<th>Revenue</th>
<th>Items</th>
<th>Revenue</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td>1</td>
<td>A</td>
<td>10</td>
<tD>150</td>
<td>5</td>
<tD>200</td>
<td>8</td>
<tD>120</td>
</tr>
</tbody>
No problem so far. The hard part is to use actual data from DB and insert them to the table.
Headers "trend a", "trend b" etc are not constants. The below tables will be displayed on different countries. Some countries have specific trend names. Let's say England has "Trend A", "Trend B" and "Trend D". Italy has only "Trend A" etc.
Is it possible to write php code and in some way auto generate the table headers based on the query results?
And then split the results by trend so that correct values will go to correct trend?
I know how to do a simple table like:
$sql_r = "SELECT o.id, o.code, tl.name, ts.items, ts.revenue
FROM overview o, trend_stats ts, trend_lang tl
WHERE o.id_shop = '1'
AND o.id = ts.id
AND ts.id_trend = tl.id_trend";
$data_to_output = Db::getInstance()->ExecuteS($sql_r);
foreach ($data_to_output as $data) {
echo '
<tr>
<td>'.$data['id'].'</td>
<td>'.$data['code'].'</td>
<td>'.$data['trend'].'</td>
<td>'.$data['items'].'</td>
<td>'.$data['revenue'].'</td>
</tr>
';
}
But I'm not sure how to split and structure them the way I want them to be. If there's any tutorial or anything online related to what I'm asking I'm happy to check it out. Thank you
I don't think you can do that other than rewrite your headers. The fact that you want to retrieve your informations from your database tells that you'll have to work with any kind of loop. So you first have to display your headers and then display your informations. The only way is to store somewhere in your loop the value that will change your headers when it changes, and add another line of header when the value actually changes. You can do that with just a simple if condition.

xPath, getting tabular data

I have a HTML thus like:
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
</tr>
<tr>
<td>Joe Bloggs</td>
<td>joe#bloggs.com</td>
<td>40</td>
</tr>
<tr>
<td>John Doe</td>
<td>john#doe.com</td>
<td>40</td>
</tr>
</table>
Is there a way using xPath to get the first 2 columns, i.e the Name and Email fields?
I can get the table data using $data = $xpath->query( '//table'); just unsure how to get only the first 2 columns.
Many thanks
Get the first two td's:
//table/tr/td[position() <= 2]

Categories