How to add custom macro?

 
You can add custom macro by using 'rp_wcec_custom_macros' filter.
 
Here's the example of using this:
add_filter('rp_wcec_custom_macros', 'rp_wcec_add_custom_macros', 10, 2);

function rp_wcec_add_custom_macros($custom_macros, $args) {

$custom_macros['macro_key'] = array(
'value' => 'macro_value',
);

return $custom_macros;
}
Note that you will need to replace macro_key and macro_value with actual key and value of your macro.
And of course you can call for your own methods/functions to get that key or value, and use the parameters being sent in this filter ($custom_macros, $args).
 
Here's the more advanced example that allows to extract some meta data from the order and use that as macro's value:
add_filter('rp_wcec_custom_macros', 'rp_wcec_add_custom_macros', 10, 2);

function rp_wcec_add_custom_macros($custom_macros, $args) {

    // Configure the parameters
    $custom_macro_key = 'custom_macro_key';
    $custom_macro_label = __('custom_macro_label');
    $custom_macro_value = 'no value'; // default value
    
    // Get the order in args
    $order = $args['order'];
    
    // Check if order is actually an object
    if (is_object($order)) {
        
        // Get order id correctly
        $id = RightPress_WC_Legacy::order_get_id($order);
        
        // Change the value to needed order/post meta
        $custom_macro_value = get_post_meta($id, 'YOUR_META_KEY_HERE', true);
    }
    
    // Add custom macro and return the whole array
    $custom_macros[$custom_macro_key] = array(
        'label' => $custom_macro_label,
        'value' => $custom_macro_value,
    );
    
    return $custom_macros;  
}
 
Have more questions? Submit a request