[英]get custom checkout field woocommerce in Email
I added a field to the woocommerce checkout form which has the ID: # billing_wooccm13.我在 woocommerce 结帐表单中添加了一个字段,其 ID 为:# billing_wooccm13。 Now I try to retrieve this value and to send it in sending the email.
现在我尝试检索这个值并将其发送到 email 中。 for that I have the following function:
为此,我有以下 function:
function action_after_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
$order_id = $order->get_id(); /*sample order ID*/
$pickup = get_post_meta($order_id, 'billing_wooccm13', true);
$pickup_date = get_post_meta( $order->get_id(), 'billing_wooccm13', true );
$ordered_date = $order->get_date_created()->format ('d-m-Y');
echo '<table class="custom-table">';
echo '<tr>';
echo '<td>Bestelnummer: WEB-' .$pickup_date.'</td>';
echo '<td colspan="2">Besteldatum: '.$ordered_date.'</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Product</th>';
echo '<th>Stuks</th>';
echo '<th>Prijs</th>';
echo '</tr>';
foreach ($order->get_items() as $item_key => $item ) {
// WC_Product_Simple Object
// https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html
// WC_Order_Item_Product Object
// https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html
// The WC_Product object
$product = $item->get_product();
$attributes = $product->get_attribute('pa_formaat');
// Get product name
$product_name = $product->get_name();
// Get product id
$product_id1 = $product->get_id();
// Get product id
$total = $item->get_total() * 1.21;
// Get variation id
$product_id3 = $item->get_variation_id();
// The quantity
$quantity = $item->get_quantity();
echo '<tr>';
echo '<td><b>' . $product_name . '</b><br><b>Formaat: </b>' . $attributes .'</td>';
echo '<td>' . $quantity . '</td>';
echo '<td> € ' . number_format($total,2) . '</td>';
echo '</tr>';
}
$order_subtotal = $order->get_subtotal();
$order_BTW = $order_subtotal *0.21;
$total_order = $order->get_total();
echo '<tr>';
echo '<td><b>Subtoaal:</b></td>';
echo '<td colspan="2"> € '. number_format($order_subtotal,2) .' Excl. BTW </td>';
echo '</tr>';
echo '<tr>';
echo '<td><b>BTW:</b></td>';
echo '<td colspan="2"> € '. number_format($order_BTW,2) .'</td>';
echo '</tr>';
echo '<tr>';
echo '<td><b>Totaal bedrag:</b></td>';
echo '<td colspan="2"> € '. number_format($total_order ,2) .' Incl. BTW</td>';
echo '</tr>';
echo '<tr>';
echo '<td><b>Leverdatum:</b></td>';
echo '<td colspan="2">'. $delivery_date_formatted .'</td>';
echo '</tr>';
echo '</table>';
}
add_action('woocommerce_email_order_details', 'action_after_email_order_details', 10, 4 );
Just if I apply at the top of this line:就像我在这一行的顶部申请一样:
$ pickup = get_post_meta ($ order_id, 'billing_wooccm13', true);
or或者
$ pickup_date = get_post_meta ($ order-> get_id (), 'billing_wooccm13', true);
both don't show a variable, is there anyone who knows how to get this visible in the email?两者都没有显示变量,有没有人知道如何在 email 中看到这个? For now I place this behind 'Bestel Nummer'
现在我把它放在“Bestel Nummer”后面
If understood correctly you've added a woocommerce_form_field
如果理解正确,您添加了一个
woocommerce_form_field
If you want that filed in your email you can add this filter:如果你想在你的 email 中归档,你可以添加这个过滤器:
add_filter('woocommerce_email_order_meta_keys', 'your_order_meta_keys');
function your_order_meta_keys( $keys ) {
$keys['YOUR-FILED-TITLE-HERE'] = 'YOUR-FILED-NAME-HERE';
return $keys;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.