Last active
June 17, 2020 09:35
-
-
Save rizqinizamil/e0e6d170e4c2863a1087227494e7c327 to your computer and use it in GitHub Desktop.
Use content-product.php template for Woocommerce product block
This file contains hidden or 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
// Source: https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/891#issuecomment-568752116 | |
// ========================================= | |
function _wc_get_template_part_str($template_name, $part_name=null) { | |
ob_start(); | |
wc_get_template_part($template_name, $part_name); | |
$var = ob_get_contents(); | |
ob_end_clean(); | |
return $var; | |
} | |
function woo_block_product_grid_item_html($html, $block_attr, $_product) { | |
global $product, $post; | |
$is_woo_block_product_grid_item = true; | |
$orig_product = $product; | |
$orig_post = $post; | |
$product = $_product; | |
$post = get_post( $_product->get_id() ); | |
$html = _wc_get_template_part_str( 'content', 'product' ); | |
$product = $orig_product; | |
$post = $orig_post; | |
return $html; | |
} | |
add_filter( 'woocommerce_blocks_product_grid_item_html', __NAMESPACE__ . '\\woo_block_product_grid_item_html', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment