Skip to main content

Hooks

Using hooks, you can edit data throughout the plugin when it is processed, displayed, or stored.

Reading properties

By default, reading any property has a hook available.

// Model name can be either 'product' or 'variant', the key is the slug of the custom field.
'eduframe_{$model_name}_get_{$prop}'

You can then add a custom hook that runs when that field is called upon.

add_filter( 'eduframe_product_get_cost', function ( $price ) {
return $price . ' in dollars';
} );

Assuming the value of cost is 10, it will return 10 in dollars instead.

global $product;
$field = $product->get_cost();
echo $field;

'10 in dollars'

You can disable hooks when getting values by setting the view as 'edit' like so:

global $product;
$field = $product->get_cost( 'edit' );
echo $field;

'10'

Common hooks

Use case:
Don't show course locations on the website that have the string archived in the name, since these course_locations are no longer used.

The code below achieves this by adding a filter before the course_location_widget makes a query:

add_filter( 'eduframe_course_location_widget_query_args', 'remove_archived_locations' );

function remove_archived_locations($query) {
$query['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'name',
'value' => 'archived',
'compare' => 'NOT LIKE'
)
);

return $query;
}