以下是有效的:
type Individual [][]int
type Population []*Individual
我要做的是向人口添加一个字段,以便我执行以下操作
var p Population
p.Name = "human"
所以我尝试了这个:
type Individual [][]int
type Population struct {
[]*Individual
Name string
}
但它对我不起作用。我该怎么做?
答案 0 :(得分:1)
您应该声明结构字段的名称:
add_action( 'woocommerce_thankyou', 'the_tracking' );
function the_tracking( $order_id ) {
global $woocommerce;
$order = wc_get_order( $order_id );
$total = $order->get_total();
$currency = get_woocommerce_currency();
$subtotal = $woocommerce->cart->subtotal;
$coupons = $order->get_used_coupons();
$coupon_code = '';
$discount = $order->get_total_discount();
foreach ($coupons as $coupon){
$coupon_code = $coupon;
}
$tracking = 'OrderID='.$order.'&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'';
echo $tracking;
}
package main
import (
"fmt"
)
type Individual [][]int
type Population struct {
Individual []*Individual // <- A name for field
Name string
}
func main() {
var p Population
p.Name = "human"
fmt.Printf("%+v", p)
}