Automattic\WooCommerce\Blocks\Templates
SingleProductTemplate::update_single_product_content
Add the block template objects to be used.
Method of the class: SingleProductTemplate{}
No Hooks.
Returns
Array.
Usage
$SingleProductTemplate = new SingleProductTemplate(); $SingleProductTemplate->update_single_product_content( $query_result );
- $query_result(array) (required)
- Array of template objects.
SingleProductTemplate::update_single_product_content() SingleProductTemplate::update single product content code WC 10.3.3
public function update_single_product_content( $query_result ) {
$query_result = array_map(
function ( $template ) {
if ( str_contains( $template->slug, self::SLUG ) ) {
// We don't want to add the compatibility layer on the Editor Side.
// The second condition is necessary to not apply the compatibility layer on the REST API. Gutenberg uses the REST API to clone the template.
// More details: https://github.com/woocommerce/woocommerce-blocks/issues/9662.
if ( ( ! is_admin() && ! ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) && ! BlockTemplateUtils::template_has_legacy_template_block( $template ) ) {
// Add the product class to the body. We should move this to a more appropriate place.
add_filter(
'body_class',
function ( $classes ) {
return array_merge( $classes, wc_get_product_class() );
}
);
global $product;
if ( ! $product instanceof \WC_Product ) {
$product_id = get_the_ID();
if ( $product_id ) {
wc_setup_product_data( $product_id );
}
}
if ( post_password_required() ) {
$template->content = $this->add_password_form( $template->content );
} else {
$template->content = SingleProductTemplateCompatibility::add_compatibility_layer( $template->content );
}
}
}
return $template;
},
$query_result
);
return $query_result;
}