User
Forum Replies Created
-
Forum: Plugins
In reply to: [Shiptastic for WooCommerce] Question About “Pick & Pack” Box Fit CalculationThanks! I think I was able to accomplish what I wanted. For reference in case anyone else needs this.
// WooCommerce - Selects the best-fitting shipping box using BoxPacker (https://github.com/dvdoug/BoxPacker) for a WooCommerce order based on item dimensions and weight, and displays this information in the order details
// Last update: 2025-03-20
// Add best package fit inside WooCommerce orders using a custom field - run action once (run on WP Console)
// $orders = wc_get_orders(['limit' => -1]);
// foreach ($orders as $order) {
// calculate_and_store_package_best_fit($order->get_id());
// }
// Requires BoxPacker 4.1.0 (https://github.com/dvdoug/BoxPacker) to be installed in the "wp-content" folder (no Composer needed)
require_once WP_CONTENT_DIR . '/boxpacker/src/Box.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/BoxList.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/BoxSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/DefaultBoxSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/Item.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/ItemList.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/ItemSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/DefaultItemSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/LayerPacker.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/LayerStabiliser.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/OrientatedItem.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/OrientatedItemFactory.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/OrientatedItemSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedBox.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedBoxList.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedBoxSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedItem.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedItemList.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/PackedLayer.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/DefaultPackedBoxSorter.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/Packer.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/Rotation.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/VolumePacker.php';
require_once WP_CONTENT_DIR . '/boxpacker/src/Exception/NoBoxesAvailableException.php';
use DVDoug\BoxPacker\Box;
use DVDoug\BoxPacker\DefaultItemSorter;
use DVDoug\BoxPacker\Item;
use DVDoug\BoxPacker\ItemSorter;
use DVDoug\BoxPacker\Packer;
use DVDoug\BoxPacker\Rotation;
add_action($hook_name = 'woocommerce_checkout_order_processed', $callback = 'calculate_and_store_package_best_fit', $priority = 10, $accepted_args = 1);
add_action($hook_name = 'woocommerce_admin_order_data_after_order_details', $callback = 'display_custom_order_meta', $priority = 10, $accepted_args = 1);
class CustomBox implements DVDoug\BoxPacker\Box
{
public function __construct(
private string $reference,
private int $outerWidth,
private int $outerLength,
private int $outerDepth,
private int $emptyWeight,
private int $innerWidth,
private int $innerLength,
private int $innerDepth,
private int $maxWeight
) {
}
public function getReference(): string
{
return $this->reference;
}
public function getOuterWidth(): int
{
return $this->outerWidth;
}
public function getOuterLength(): int
{
return $this->outerLength;
}
public function getOuterDepth(): int
{
return $this->outerDepth;
}
public function getEmptyWeight(): int
{
return $this->emptyWeight;
}
public function getInnerWidth(): int
{
return $this->innerWidth;
}
public function getInnerLength(): int
{
return $this->innerLength;
}
public function getInnerDepth(): int
{
return $this->innerDepth;
}
public function getMaxWeight(): int
{
return $this->maxWeight;
}
}
class CustomItem implements DVDoug\BoxPacker\Item
{
public function __construct(
private string $description,
private int $width,
private int $length,
private int $depth,
private int $weight
) {
}
public function getDescription(): string
{
return $this->description;
}
public function getWidth(): int
{
return $this->width;
}
public function getLength(): int
{
return $this->length;
}
public function getDepth(): int
{
return $this->depth;
}
public function getWeight(): int
{
return $this->weight;
}
public function getAllowedRotation(): Rotation
{
return Rotation::BestFit;
}
}
function calculate_and_store_package_best_fit($order_id)
{
if (!$order_id) {
return;
}
$order = wc_get_order($order_id);
if (!$order) {
return;
}
$packer = new Packer(new DefaultItemSorter());
// Define available boxes
$boxes = [
new CustomBox('Box S1', 140, 140, 150, 90, 140, 140, 150, 20000),
new CustomBox('Box S2', 140, 140, 250, 101, 140, 140, 250, 20000),
new CustomBox('Box S3', 140, 140, 350, 118, 140, 140, 350, 20000),
new CustomBox('Box M', 250, 350, 150, 172, 250, 350, 150, 20000),
new CustomBox('Box L', 380, 380, 200, 316, 380, 380, 200, 20000)
];
foreach ($boxes as $box) {
$packer->addBox($box);
}
// Add order items to the packer
foreach ($order->get_items() as $item) {
$product = $item->get_product();
if (!$product) {
continue;
}
$length = $product->get_length();
$width = $product->get_width();
$height = $product->get_height();
$weight = $product->get_weight();
if ($length && $width && $height && $weight) {
$packer->addItem(new CustomItem(
$product->get_name(),
(int) ($width * 10), // Convert cm to mm
(int) ($length * 10), // Convert cm to mm
(int) ($height * 10), // Convert cm to mm
(int) ($weight)
));
}
}
// Determine the best fit (only the first packed box)
$packedBoxes = $packer->pack();
// Convert to an array if necessary
if ($packedBoxes instanceof Traversable) {
$packedBoxes = iterator_to_array($packedBoxes);
}
if (!empty($packedBoxes)) {
$packedBox = reset($packedBoxes); // Get the first/smallest box
$boxType = $packedBox->box;
// Flatten the array so that keys match the display function
$package_best_fit = [
'name' => $boxType->getReference(),
'width' => $boxType->getOuterWidth() / 10, // Convert mm back to cm
'length' => $boxType->getOuterLength() / 10, // Convert mm back to cm
'height' => $boxType->getOuterDepth() / 10, // Convert mm back to cm
'weight' => $packedBox->getWeight(),
'items_count' => count($packedBox->items)
];
// Update the order meta with the best fit package
update_post_meta($order_id, 'order_package_best_fit', json_encode($package_best_fit));
}
}
// Custom display function to output package best fit meta
function display_custom_order_meta($order)
{
$package_best_fit = get_post_meta($order->get_id(), 'order_package_best_fit', true);
if ($package_best_fit) {
$package_best_fit = json_decode($package_best_fit, true);
$package_best_fit_name = isset($package_best_fit['name']) ? esc_html($package_best_fit['name']) : '';
$package_best_fit_length = isset($package_best_fit['length']) ? esc_html($package_best_fit['length']) : '';
$package_best_fit_width = isset($package_best_fit['width']) ? esc_html($package_best_fit['width']) : '';
$package_best_fit_height = isset($package_best_fit['height']) ? esc_html($package_best_fit['height']) : '';
$package_best_fit_weight = isset($package_best_fit['weight']) ? esc_html($package_best_fit['weight']) : '';
echo '<div>';
echo '<p> </p>';
echo '<h3>Package Best Fit</h3>';
echo '<p>Package Dimensions (L×W×H) (cm):<br>';
echo $package_best_fit_name . ' (' . $package_best_fit_length . ' x ' . $package_best_fit_width . ' x ' . $package_best_fit_height . ')</p>';
echo '<p>Package Weight (g):<br>';
echo $package_best_fit_weight . '</p>';
echo '</div>';
}
}Prezados – agrade?o pela resposta. Reitero gentilmente o pedido para que implementem essa fun??o, considerando sua importancia para a contabilidade.
Atenciosamente
Now the warning compatibility issue is gone – Thanks!
Thank you for the update. Unfortunately, after upgrading to version 4.3.3, the issue persists: https://imgur.com/FDzKukp
Today, everything is functioning as expected. It seems there might have been an issue with the DHL Rest API connection yesterday.
Yes, unfortunately it did not work, thus I had to change it to the
Old API (SOAP)
.Forum: Plugins
In reply to: [Shiptastic for WooCommerce] Question About “Pick & Pack” Box Fit CalculationThanks for the quick answer! Great to hear that. Is there a shortcode or function that I could enter an order no and retrieve the best fitting package for that order?
Perhapswoocommerce_gzd_shipments_item_fits_packaging
from https://vendidero.de/doc/woocommerce-germanized/shipments-hooks?
Kind regardsThank you for your prompt response. I can confirm that all my plugins were updated, meaning I migrated from the latest previous version of Germanized.
To investigate further, I have tested the following code by running it in WP Code:// Test API endpoint with cURL
function test_dhl_api($url) {
// Set up cURL
$curl = curl_init($url);
// Set options for the request
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json', // Adjust content type if necessary
'Authorization: Bearer YOUR_API_TOKEN_HERE', // Replace with a valid token if required
]);
// Execute the request
$response = curl_exec($curl);
// Check for errors
if (curl_errno($curl)) {
$error_msg = curl_error($curl);
echo 'cURL Error: ' . $error_msg;
} else {
echo 'API Response: ' . $response;
}
// Close the connection
curl_close($curl);
}
// Run the test function
test_dhl_api($url = 'https://api-eu.dhl.com/parcel/de/account/auth/ropc/v1/');The response:
API Response:
{
"amp" : {
"name": "pp-account-auth-ropc",
"version": "v0.9.10",
"rev": "13",
"env": "prod-eu"
}
}So seems that Cloudflare is not blocking it.
Using the
Old API (SOAP)
, it works: https://imgur.com/BRXUrCe
But immediately after switching to theNew API (REST)
it stops working: https://imgur.com/p7nYKn0
Perhaps any other change?
Kind regardsOlá @donatelol,
A equipe de suporte do Mercado Livre me contatou e o problema foi solucionado da seguinte forma: precisei liberar os seguintes IPs (no meu caso, uso o Cloudflare Free):
54.88.218.97
18.215.140.160
18.213.114.129
18.206.34.84
Desde ent?o, tudo está funcionando novamente.
Espero que a equipe desenvolvedora por trás do plugin adicione o ping desses IPs automaticamente na página inicial do plugin, sinalizando a necessidade de liberar esses IPs. Acredito que alguns sejam IPs dos EUA, e por isso tive problemas.
AtenciosamenteHi @femiyb,
Thank you for your quick response.
I am using the latest version (Version 2.9.6). All my plugins are using are updated to the latest version.
I have tested it once again by opening the/wp-admin/admin.php?page=wc-orders
and after clearing cache for Cloudflare and nginx, and Redis cache flush the deprecation warning is not being shown anymore.
Thank you for your support.
Kind regardsPrezados,
Registrei um atendimento por meio do link informado acima, incluindo os logs pertinentes.
Como sugest?o de melhoria: observei que a “Central de Atendimento” n?o oferece uma op??o clara para abertura de tickets relacionados ao plugin WordPress. Além disso, n?o consegui anexar arquivos .log, sendo necessário tirar uma screenshot, o que n?o é o ideal.
Enfrentei o mesmo problema novamente hoje e, sinceramente, estou considerando buscar servi?os alternativos devido a este bug.
AtenciosamenteForum: Plugins
In reply to: [Germanized for WooCommerce] Germanized autoloaded optionsHi Dennis,
Thanks for the update! I appreciate knowing that this is on the roadmap for reevaluation. Looking forward to the upcoming improvements.
Kind regardsForum: Plugins
In reply to: [Germanized for WooCommerce] Order Note to InvoiceHi Dennis,
Adding a “Paragraph” block with the code below and “Typography” size “Tiny” (“S”) worked.[if_order data="customer_note" compare="nempty"]
Bestellhinweise: [order data="customer_note"]
[/if_order]Many thanks!
Estou enfrentando o mesmo problema…
Forum: Plugins
In reply to: [Super Page Cache] “Enable Page Caching Now” does not workHi @kushnamdev, no worries. In the meantime I have changed the cache plugin because of this issue. So this ticket can be closed. Thanks