Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
Created April 12, 2022 11:35
Show Gist options
  • Save GreatPotato/31559b5d5ec6628ea0a64cd95850b120 to your computer and use it in GitHub Desktop.
Save GreatPotato/31559b5d5ec6628ea0a64cd95850b120 to your computer and use it in GitHub Desktop.
Add event to customize product weight
<?php
public function total_weight()
{
$result = $this->om('weight')*$this->quantity;
$extras = $this->get_extra_option_objects();
foreach ($extras as $option)
$result += $option->weight*$this->quantity;
$weight_adjusted = Backend::$events->fire_event(['name' => 'shop:onGetOrderItemWeight', 'type'=>'filter'], $this);
return ($weight_adjusted) ? $weight_adjusted : $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment