• Resolved broder

    (@broder)


    I want to add a custom field to the standard product name title, but preferably via filter instead of custom meta fields box. Of course I checked the faq, but couldn’t really tell if standard values can be changed using this filter:

    add_filter('site-reviews/schema/Product', function ($schema) { global $product; $product_id = $product->get_id(); $product_name = $product->get_name(); $product_field = get_field('Inhoud', $product_id); $schema['product'] = [ '@type' => 'Product', 'name' => $product_name . '' . $product_field, ]; return $schema; });

    But it’s not working, do I need to fill all the key / values in the array? Can you please confirm if this can be done? Or to use the metabox functions. Thank you as always.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Do this instead:

    add_filter('site-reviews/schema/Product', function ($schema) {
        if (!function_exists('wc_get_product') || !function_exists('get_field')) {
            return $schema;
        }
        if ($product = wc_get_product()) {
            $product_id = $product->get_id();
            $product_name = $product->get_name();
            $product_field = get_field('Inhoud', $product_id);
            $schema['name'] = trim($product_name.' '.$product_field);
        }
        return $schema;
    });
    Thread Starter broder

    (@broder)

    Works now, thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Schema filter’ is closed to new replies.