Skip to content

Commit 3c10b59

Browse files
committed
Order attributes: use getter methods to get value
Previously we were using the generic getter, `get_meta()`, which is not the correct approach and doesn't return values during checkout. Fixes #46
1 parent 83ce920 commit 3c10b59

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/classes/entity/order/attr.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ protected function get_attr_value_from_entity( WordPoints_Entity $entity ) {
6262
return null;
6363
}
6464

65+
$method = "get_{$this->attr_key}";
66+
67+
if ( method_exists( $order, $method ) ) {
68+
return $order->{$method}();
69+
}
70+
6571
return $order->get_meta( $this->attr_key );
6672
}
6773
}

tests/phpunit/tests/classes/entities.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function data_provider_entities() {
6161
),
6262
),
6363
'the_context' => array( 'site' => 1, 'network' => 1 ),
64-
'create_func' => 'WC_Helper_Order::create_order',
64+
'create_func' => array( $this, 'create_order' ),
6565
'delete_func' => 'WC_Helper_Order::delete_order',
6666
'children' => array(
6767
'cart_tax' => array(
@@ -249,6 +249,23 @@ public function data_provider_entities() {
249249
return $entities;
250250
}
251251

252+
/**
253+
* Creates an order.
254+
*
255+
* @since 1.3.1
256+
*
257+
* @return WC_Order The order.
258+
*/
259+
public function create_order() {
260+
261+
$order = WC_Helper_Order::create_order();
262+
$order->update_status( 'completed' );
263+
$order->set_date_paid( time() );
264+
$order->save();
265+
266+
return $order;
267+
}
268+
252269
/**
253270
* Gets the ID from an order.
254271
*

0 commit comments

Comments
 (0)