English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Take-Away Orders  >  Translate Details

apply_filters( 'vikrestaurants_translate_takeaway_order_details', bool $status, object $order, string $langtag )

Fires while translating the details of the take-away order into a specific language.


Description

External plugins can use this event to apply the translations to additional details manually included within the order object.

Since the query used to load the details can be extended, this method offers the possibility to translate any additional data in the right way.


Parameters

$status

(bool)  True on success, false otherwise.

$order

(object)  The object holding the details of the order.

$langtag

(string)  The language tag.


Example

The example below explains how the internal translation system works.

/**
 * External plugins can use this event to apply the translations to
 * additional details manually included within the order object.
 *
 * @param   boolean  $status   True on success, false otherwise.
 * @param   object   $order    The order details object.
 * @param   string   $langtag  The requested language tag.
 */
add_filter('vikrestaurants_translate_takeaway_order_details', function($status, $order, $langtag)
{
    // get translator
    $translator = VREFactory::getTranslator();

    // The products translation is already handled by the system, this is
    // just an explanation of how the translation system works.

    foreach ($order->items as &$item)
    {
        // translate product
        $tx = $translator->translate('tkentry', $item->id, $langtag);

        if ($tx)
        {
            // inject translation within item details
            $item->productName = $tx->name;
        }
    }

    return true;
}, 10, 3);

Changelog

Version Description
1.2.1 Introduced.
Last Update: 2021-03-03
Helpful?
See Also:
This site uses cookies. By continuing to browse you accept their use. Further information