Skip to main content

Hooks

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

Reading properties

By default reading all properties have an 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 Euros';
} );

Assuming the value of cost is 10 the value will return in Euros instead.

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

'10 in Euros'

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 not used anymore.

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;
}