Last active
October 4, 2019 13:39
-
-
Save ValentinGenev/bce05f1121aa9c851be1682a59dcec10 to your computer and use it in GitHub Desktop.
Changes the output markup of the product blocks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('woo_custom_product_block_markup')) { | |
function woo_custom_product_block_markup($data) { | |
$product_markup = new DOMDocument(); | |
$product_markup->loadHTML($data); | |
$product_anchor = $product_markup->getElementsByTagName('a'); | |
$product_id = ''; | |
foreach ($product_anchor as $anchor) { | |
if ($anchor !== '') { | |
$product_id = $anchor->getAttribute('data-product_id'); | |
} | |
} | |
$product = wc_get_product($product_id); | |
// more product data... | |
return ' | |
<li class="' . implode(' ', wc_get_product_class('', $product)) . '"> | |
<h3 class="title">' . get_the_title($product_id) . '</h3> | |
<!-- more html --> | |
</li> | |
'; | |
} | |
} | |
add_filter('woocommerce_blocks_product_grid_item_html', 'woo_custom_product_block_markup'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More on why this is somewhat relevant here: Blocks use custom markup instead of WooCommerce templates / lack of filters