WooCommerce Subscriptions get Billing Interval & ID - hook-woocommerce

I am using a stripe "wc_gateway_stripe_process_response" to get payment information. What is needed is what is the payment interval for that product and what the user's subscription id is. This is the code I have to date:
function woointerface_ProcessOrder($order_id)
{
$order = new WC_Order( $order_id );
$TransactionId = $order->get_transaction_id();
$szOrderId = $order->get_order_number();
// Find all products associated with this order
$order_data = $order->get_data();
$order_billing_email = $order->get_billing_email();
$payment_method = $order->get_payment_method_title();
$PaymentDate = $order->get_date_paid();
$OrderNumber = $order->get_order_number();
$User = get_user_by( 'email', $order_billing_email );
$FirstName = $User->first_name;
$LastName = $User->last_name;
$UserId = $User->ID;
$PayerName = $FirstName . ' ' . $LastName;
$items = $order->get_items();
foreach( $items as $item_id => $product )
{
$ProductName = $product->get_name();
$ProductId = $product->get_product_id();
$PaymentAmount = $product->get_total();
$ProductIndex = wc_get_product($ProductId);
if(! WC_Subscriptions_Product::is_subscription( $ProductIndex ) )
continue;
$UserSubscriptionId = ??
$BillingCycle = ??
// Store in local table.
}
Looking for how to get the User subscription id and billing cycle for this order.

Found the solution for billing and Id. The following calls give you the billing and user subscription id information:
$BillingCycle = WC_Subscriptions_Product::get_interval($ProductIndex); // how many times within the period to bill
$BillingPeriod = WC_Subscriptions_Product::get_period($ProductIndex); // Month/week/Year
$subscriptions = wcs_get_subscriptions(array('order_id' => $order->id, 'product_id' => $ProductId));
if (!empty($subscriptions))
{
$subscription = array_pop($subscriptions);
$PaidSubscriptionId = $subscription->id;
}

Related

LINQ query with sub-query list

The query below should be selecting a list of information from different tables, and should also bring back a list of VehicleNames that are related to each ID coming back from db.Reservations
The query brings back data, but the list of VehicleNames only has one record, and it should bring back anywhere up to 5 records, depending on how many vehicles were reserved for that specific instance. I have tried adding a foreach to the VehicleName line in the select but I don't think I am using it right. Does anyone have any ideas as to how I can retrieve the list of values I need?
var query = from r in db.Reservations
let e = db.Employees.Where(x => r.RequestorID == x.ColleagueID).FirstOrDefault()
let rtv = db.ReservationToVehicle.Where(x => r.ID == x.ReservationID).FirstOrDefault()
let rs = db.ReservationStatus.Where(x => r.ID == x.ReservationID).FirstOrDefault()
let rst = db.ReservationStatusTypes.Where(x => rs.ReservationStatusTypeID == x.ID).FirstOrDefault()
select new
{
StartDate = r.StartDate,
EndDate = r.EndDate,
Destination = r.Destination,
PurposeOfTrip = r.PurposeOfTrip,
TransportingStudents = r.TransportStudentsFG,
EmployeeName = e.FirstName + " " + e.LastName,
ApprovalStatus = rst.StatusType,
ThemeColor = r.ThemeColor,
VehicleName = (from v in db.Vehicles
where v.ID == rtv.VehicleID
select v.VehicleName).ToList()
};
EDIT: Updated query, still uncertain how to get back list of Vehicles that have been reserved
var query = from r in db.Reservations
let e = db.Employees.Where(x => r.RequestorID == x.ColleagueID).FirstOrDefault()
let rtv = db.ReservationToVehicle.Where(x => r.ID == x.ReservationID).Select(y => y.VehicleID).ToList()
let rs = db.ReservationStatus.Where(x => r.ID == x.ReservationID).FirstOrDefault()
let rst = db.ReservationStatusTypes.Where(x => rs.ReservationStatusTypeID == x.ID).FirstOrDefault()
select new
{
StartDate = r.StartDate,
EndDate = r.EndDate,
Destination = r.Destination,
PurposeOfTrip = r.PurposeOfTrip,
TransportingStudents = r.TransportStudentsFG,
EmployeeName = e.FirstName + " " + e.LastName,
ApprovalStatus = rst.StatusType,
ThemeColor = r.ThemeColor,
VehicleName = (from v in db.Vehicles
where v.ID == rtv.VehicleID
select v.VehicleName).ToList()
};
rtv.VehicleID does not exist anymore, now rtv comes back with a list of IDs....I need to be able to get into that list to find where v.ID is IN the rtv list
Looks like people already told you this in the comments, but here's the code that ought to work:
var query = from r in db.Reservations
let e = db.Employees.Where(x => r.RequestorID == x.ColleagueID).FirstOrDefault()
let rtv = db.ReservationToVehicle.Where(x => r.ID == x.ReservationID).Select(y => y.VehicleID)
let rs = db.ReservationStatus.Where(x => r.ID == x.ReservationID).FirstOrDefault()
let rst = db.ReservationStatusTypes.Where(x => rs.ReservationStatusTypeID == x.ID).FirstOrDefault()
select new
{
StartDate = r.StartDate,
EndDate = r.EndDate,
Destination = r.Destination,
PurposeOfTrip = r.PurposeOfTrip,
TransportingStudents = r.TransportStudentsFG,
EmployeeName = e.FirstName + " " + e.LastName,
ApprovalStatus = rst.StatusType,
ThemeColor = r.ThemeColor,
VehicleName = (from v in db.Vehicles
where rtv.Contains(v.ID)
select v.VehicleName).ToList()
};
I'd also recommend looking at setting up navigation properties between your entities. Your query could be much simpler, something like this:
var query = from r in db.Reservations
let e = r.Requestor
let rs = r.ReservationStatus
let rst = rs.ReservationStatusType
select new
{
StartDate = r.StartDate,
EndDate = r.EndDate,
Destination = r.Destination,
PurposeOfTrip = r.PurposeOfTrip,
TransportingStudents = r.TransportStudentsFG,
EmployeeName = e.FirstName + " " + e.LastName,
ApprovalStatus = rst.StatusType,
ThemeColor = r.ThemeColor,
VehicleName = r.Vehicles.Select(v => v.VehicleName).ToList()
};

Do not include the database column when query string is NULL

I'm trying to make a search functionality. The code below says that if Port, Status and TIN are not null then query the database.
E.g 1. If User has chosen the port and status but not the TIN then the
TIN should not be included when searching the database.
E.g 2. If User has chosen the port only then the Status and TIN should
not be included when searching the database.
Code
int Port = Convert.ToInt32(Request.QueryString["Port"]);
var Status = Request.QueryString["Status"];
var TIN = Request.QueryString["TIN"];
List<Transaction> QueriedTransactionList;
QueriedTransactionList = db.Transactions.ToList();
TransactionViewModel TransactionViewModel = new TransactionViewModel();
List<TransactionViewModel> TransactionDataList = QueriedTransactionList.Select(x => new TransactionViewModel{
TTransactionID = x.TTransactionID,
BatchID = x.BatchID,
TransactionDateTime = x.TransactionDateTime,
TransactionStatus = x.TransactionStatus,
TaxPayerName = x.Card.TaxPayer.TaxPayerName,
TaxPayerEmail = x.Card.TaxPayer.TaxPayerEmail,
TaxPayerTIN = x.Card.TaxPayer.TaxPayerTIN,
DispatchBy = x.User.UserName,
DestinationPort = x.Card.Port.PortName,
BatchCards = Helper.GetBatchQtyByBatchID(x.BatchID)
}).GroupBy(x => x.BatchID).Select(x => x.LastOrDefault()).Where(x => Status.IndexOf(x.TransactionStatus, StringComparison.OrdinalIgnoreCase) >= 0 && TIN.IndexOf(x.Card.TaxPayerTIN, StringComparison.OrdinalIgnoreCase) >= 0).OrderByDescending(x => x.TTransactionID).ToList();

TYPO3 Show fe_user with Hyperlink and GET parameter

I'm using TYPO3 7.6 and I'd like to send an email with a Hyperlink to my TYPO3-Website (page=123). On this page I've listed all fe_users with the following TypoScript, but I'll only show one specific user, f.e. uid=20.
I have two questions:
How can I show only this user (uid) on my page?
How do I call my hyperlink?
Show all users:
lib.feUserLink = CONTENT
lib.feUserLink {
table = fe_users
select.pidInList = 10
select.max = 10
select.orderBy = last_name DESC
where = disable = 0
renderObj = COA
renderObj {
10 = TEXT
10.field = first_name
10.wrap = wq<p><strong>|
...
14 = TEXT
14.field = email
14.wrap = |</p>
}
}
-> 1. Then I have to edit my WHEREclause, but i dont't know how? All of my tests won't work.
lib.feUserLink = CONTENT
lib.feUserLink {
table = fe_users
...
andWhere.dataWrap = uid={GP:fe_users|uid}
#andWhere.data = GP:feuseruid
#andWhere.data = GP:fe_user|uid
#andWhere.intval = 1
#andWhere.wrap = uid=|
...
-> 2. And how can I show only the User from the GET-Parameter?
http://my.domain.tld/index.php?id=123&uid=20
http://my.domain.tld/index.php?id=123&feuser=20
http://my.domain.tld/index.php?id=123&fe_users[uid]=20
...
I hope someone can give me a crucial tip ...
... thank you.
Regards
Stefan
my solution was
lib.feuserLink = CONTENT
lib.feUserLink {
table = fe_users
select {
pidInList = 10
orderBy = last_name DESC
where = uid = ###field_uid###
markers.field_uid.data = GP:user
markers.field_uid.intval = 1
max = 1
}
...
Thanks for helping ...
2) Build link to page 123 with uid parameter from fe_user. Adds something like
?id=123&user=456&cHash=789
lib.feUserLink = CONTENT
lib.feUserLink {
table = fe_users
select {
pidInList = 10
max = 10
orderBy = last_name DESC
}
renderObj = COA
renderObj {
10 = TEXT
10.field = username
10.typolink {
parameter = 123
additionalParams.dataWrap = &user={field:uid}
useCacheHash = 1
}
10.wrap = |</br>
}
}
1) To show only selected user in given list, adapt your select like
[globalVar = GP:user > 0]
lib.feUserLink.select {
where = uid = ###field_uid###
markers.field_uid.data = GP:user
markers.field_uid.intval = 1
max = 1
}
[global]
You don't need clause where = disable = 0. Its already included in the SQL query by default.

IE11 clears password fields on page refresh:

Happens only in IE (Chrome and Firefox, no issues... go figure)
I have a page where customer's can update their details (name, address,password etc.) and everything is working fine, however if the customer submits the form (which also works fine) and then presses the back button all the customer's information will repopulate the form except for the password field.
My boss would like this to repopulate as well, like it does in Chrome and Firefox, but IE won't do it. I'm hoping it's something simple I've missed but I can't see it. I've tried adjusting the lines where the text fields are populated to match the rest of the form, but that just results in empty fields. Code below.
Page_Load
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Response.Redirect("default.aspx")
End If
If Not Page.IsPostBack Then
If c.CustomerID > 0 Then
'populate the table
lblAccountName.Text = c.AccountName
txtFirstName.Text = c.FirstName
txtLastName.Text = c.LastName
txtEmail.Text = c.Email
txtAddress.Text = c.Address
txtSuburb.Text = c.Suburb
txtCityTown.Text = c.City
txtPostcode.Text = c.PostCode
txtPhone.Text = c.Phone
txtMobile.Text = c.Mobile
'chkNewsletter.checked = c.Newsletter
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
'txtPassword.Text = c.GeneratedPassword
'txtConfirmPassword.Text = c.GeneratedPassword
Dim subscriptions As ContactSubscriptions = New ContactSubscriptions(c.CustomerID)
chkGenernalNewsletters.Checked = subscriptions.IsGenernalNewsletters
End If
Else
End If
Update Button
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Exit Sub
End If
c.AccountName = lblAccountName.Text
c.FirstName = txtFirstName.Text
c.LastName = txtLastName.Text
c.Email = txtEmail.Text
c.Address = txtAddress.Text
c.Suburb = txtSuburb.Text
c.City = txtCityTown.Text
c.PostCode = txtPostcode.Text
c.Phone = txtPhone.Text
c.Mobile = txtMobile.Text
'c.Newsletter = chkNewsletter.Checked
c.GeneratedPassword = txtPassword.Text
c.CustomerUpdatedRequired = false
'Update password field
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
GPCUser.AddUpdateCustomer(c)
subscriptions.IsGenernalNewsletters = chkGenernalNewsletters.Checked
subscriptions.Save()
Session("Customer") = c
lblMessage.Text = "Your details have been successfully updated."
pnlUpdateAccount.Visible = False

dao recordset updating the wrong record

I'm trying to have a form usable for both creating a new record or updating another. Currently it is doing it through the value of a textbox (new or edit). The structure works fine, but for some reason, when it is performing the edit function, it is saving changes to the wrong record. For instance, if I am editing record 1027, when i submit it, it'll update record 1073. Its consistent, it'll always update the same, wrong record. Edit 1000, it'll update 1073; if i update 1081, it'll update 1073, and so on. Is there a way to specify which record it should be editing? yes, the record number is the primary key/id. Heres the code:
Private Sub btnSubmit_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strTable As String
Dim strField As String
Dim ID As Long
Dim newID As Long
strTable = "record_holdData"
Set db = CurrentDb
Set rs = db.OpenRecordset(strTable)
'button has 2 modes
If txtMode.Value = "NEW" Then
With rs
.AddNew
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("holdStatus") = 1
.Fields("dateOpened") = Now()
.Update
.Bookmark = .LastModified
newID = !ID
End With
MsgBox ("Hold information saved!")
btnPrintTag.Enabled = True
DoCmd.OpenReport "Holdtag", acViewPreview, , "[ID] = " & newID
DoCmd.Close
ElseIf txtMode.Value = "EDIT" Then
'do editing stuff
With rs
.Edit
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("lastEditDate") = Now()
.Update
End With
MsgBox ("Information Updated")
End If
End Sub
Sorry i caught it. Problem was I was basically redefining the recordset each time the subroutine was called. I changed the second block to the following:
ElseIf txtMode.Value = "EDIT" Then
'do editing stuff
Set rs = db.OpenRecordset("SELECT * FROM record_holdData WHERE ID=" & txtID)
With rs
.Edit
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("lastEditDate") = Now()
.Update
End With

Resources