<?php
/**
* WooCommerce Compatibility – NewsNight
*/
add_action('after_setup_theme', function () {
add_theme_support('woocommerce');
add_theme_support('wc-product-gallery-zoom');
add_theme_support('wc-product-gallery-lightbox');
add_theme_support('wc-product-gallery-slider');
});
/* Columns */
add_filter('loop_shop_columns', fn() => 3);
/* Disable WC CSS */
add_filter('woocommerce_enqueue_styles', '__return_empty_array');
/* Body Class */
add_filter('body_class', function ($classes) {
$classes[] = 'woocommerce-active';
return $classes;
});
/* Related Products */
add_filter('woocommerce_output_related_products_args', function ($args) {
return [
'posts_per_page' => 3,
'columns' => 3,
];
});
/* Breadcrumb Remove */
add_action('init', function () {
remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20);
});
/* Wrapper Fix */
remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
add_action('woocommerce_before_main_content', function () {
echo '<main id="primary" class="site-main">';
});
add_action('woocommerce_after_main_content', function () {
echo '</main>';
});
/* Mini Cart Fragment */
add_filter('woocommerce_add_to_cart_fragments', function ($fragments) {
ob_start(); ?>
<a class="cart-contents" href="<?php echo esc_url(wc_get_cart_url()); ?>">
<span class="count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
});
/* Safe WC Assets */
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style(
'newsnight-woocommerce',
get_template_directory_uri() . '/woocommerce.css',
[],
wp_get_theme()->get('Version')
);
});