Additional fields in the print
-
In version 5.1.2 the shipping fields are not copied to the order.
In the previous version I had inserted this code in the fuctions and it worked. Now it no longer worksadd_action(‘woocommerce_email_after_order_table’, ‘wooccm_order_receipt_checkout_details’, 10, 3);
function wooccm_order_receipt_checkout_details($order, $sent_to_admin, $plain_text = ”) {
if (class_exists(‘WOOCCM’)) {
$billing_defaults = WOOCCM()->billing->get_defaults();
$shipping_defaults = WOOCCM()->shipping->get_defaults();
$additional_defaults = WOOCCM()->additional->get_defaults();$billing = WOOCCM()->billing->get_fields();
$shipping = WOOCCM()->shipping->get_fields();
$additional = WOOCCM()->additional->get_fields();if (!empty($billing)) {
foreach ($billing as $btn) {
if (!in_array($btn[‘name’], $billing_defaults)) {
if (( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’] . ‘: ‘ . nl2br(get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true));
echo “<br/>”;
} elseif (
!empty($btn[‘label’]) &&
$btn[‘type’] == ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’];
echo “<br/>”;
} elseif (
( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘file’ &&
(
$btn[‘type’] == ‘multiselect’ || $btn[‘type’] == ‘multicheckbox’
)
) {
$value = get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true);
$strings = maybe_unserialize($value);
echo $btn[‘label’] . ‘: ‘;
if (!empty($strings)) {
if (is_array($strings)) {
$iww = 0;
$len = count($strings);
foreach ($strings as $key) {
if ($iww == $len – 1) {
echo $key;
} else {
echo $key . ‘, ‘;
}
$iww++;
}
} else {
echo $strings;
}
} else {
echo ‘-‘;
}
echo “<br/>”;
}
}
}
}if (!empty($shipping)) {
foreach ($shipping as $btn) {
if (!in_array($btn[‘name’], $shipping_defaults)) {
if (( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’] . ‘: ‘ . nl2br(get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true));
echo “<br/>”;
} elseif (
!empty($btn[‘label’]) &&
$btn[‘type’] == ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’];
echo “<br/>”;
} elseif (
( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘file’ &&
(
$btn[‘type’] == ‘multiselect’ || $btn[‘type’] == ‘multicheckbox’
)
) {
$value = get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true);
$strings = maybe_unserialize($value);
echo $btn[‘label’] . ‘: ‘;
if (!empty($strings)) {
if (is_array($strings)) {
$iww = 0;
$len = count($strings);
foreach ($strings as $key) {
if ($iww == $len – 1) {
echo $key;
} else {
echo $key . ‘, ‘;
}
$iww++;
}
} else {
echo $strings;
}
} else {
echo ‘-‘;
}
echo “<br/>”;
}
}
}
}if (!empty($additional)) {
foreach ($additional as $btn) {
if (!in_array($btn[‘name’], $additional_defaults)) {
if (( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’] . ‘: ‘ . nl2br(get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true));
echo “<br/>”;
} elseif (
!empty($btn[‘label’]) &&
$btn[‘type’] == ‘heading’ &&
$btn[‘type’] !== ‘multiselect’ &&
$btn[‘type’] !== ‘file’ &&
$btn[‘type’] !== ‘multicheckbox’
) {
echo $btn[‘label’];
echo “<br/>”;
} elseif (
( get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true) !== ” ) &&
!empty($btn[‘label’]) &&
$btn[‘type’] !== ‘heading’ &&
$btn[‘type’] !== ‘file’ &&
(
$btn[‘type’] == ‘multiselect’ || $btn[‘type’] == ‘multicheckbox’
)
) {
$value = get_post_meta($order->get_id(), sprintf(‘_%s’, $btn[‘key’]), true);
$strings = maybe_unserialize($value);
echo $btn[‘label’] . ‘: ‘;
if (!empty($strings)) {
if (is_array($strings)) {
$iww = 0;
$len = count($strings);
foreach ($strings as $key) {
if ($iww == $len – 1) {
echo $key;
} else {
echo $key . ‘, ‘;
}
$iww++;
}
} else {
echo $strings;
}
} else {
echo ‘-‘;
}
echo “<br/>”;
}
}
}
}
}
}How can it be solved?
The topic ‘Additional fields in the print’ is closed to new replies.