soflyy / breakdance-bugs

Bug reports from Breakdance users.
38 stars 5 forks source link

WooCommerce Product Structure/Schema Missing #1076

Open hagedigital opened 1 month ago

hagedigital commented 1 month ago

The standard WooCommerce product schema is missing from Breakdance when using a custom single product template. I am using the Breakdance Zero Theme as well

Using the below function to add the schema back in

add_action('wp_footer', 'add_woocommerce_default_schema', 5);
function add_woocommerce_default_schema() {
    if (is_product()) {
        global $post;
        $product = wc_get_product($post->ID);

        $product_structured_data = new WC_Structured_Data();
        $structured_data = $product_structured_data->generate_product_data($product);

        // Output the structured data as JSON-LD
        if (!empty($structured_data)) {
            echo '<script type="application/ld+json">' . wp_json_encode($structured_data) . '</script>';
        }
    }
}