Created
August 21, 2025 11:54
-
-
Save esedic/9571f68f9e1c49000ca3062a714eb685 to your computer and use it in GitHub Desktop.
WooCommerce template override
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
<?php | |
/** | |
* The template for displaying product content within loops | |
* | |
* This template can be overridden by copying it to yourtheme/woocommerce/content-product.php. | |
* | |
* HOWEVER, on occasion WooCommerce will need to update template files and you | |
* (the theme developer) will need to copy the new files to your theme to | |
* maintain compatibility. We try to do this as little as possible, but it does | |
* happen. When this occurs the version of the template file will be bumped and | |
* the readme will list any important changes. | |
* | |
* @see https://woocommerce.com/document/template-structure/ | |
* @package WooCommerce\Templates | |
* @version 9.4.0 | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
global $product; | |
// Remove WooCommerce's default actions from hooks | |
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); | |
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 ); | |
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); | |
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); | |
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); | |
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 ); | |
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); | |
// Check if the product is a valid WooCommerce product and ensure its visibility before proceeding. | |
if ( ! is_a( $product, WC_Product::class ) || ! $product->is_visible() ) { | |
return; | |
} | |
// Get product properties | |
$product_id = get_the_ID(); | |
$product_title = get_the_title(); | |
$product_brand = get_the_term_list( get_the_ID(), 'product_brand', '<div class="product-brand">', ', ', '</div>' ); | |
$product_brand = strip_tags( $product_brand ); | |
$product_price = $product->get_price(); | |
$product_permalink = get_permalink(); | |
$product_image = wp_get_attachment_image(get_post_thumbnail_id($product_id), 'thumbnail'); | |
$product_short_description = apply_filters('woocommerce_short_description', $post->post_excerpt); | |
$currency_symbol = get_woocommerce_currency_symbol(); | |
// Get partner price | |
$meta_data = $product->get_meta('_role_based_pricing_rules'); | |
if (!empty($meta_data) && isset($meta_data['Partner']['regular_price'])) { | |
$partner_price = $meta_data['Partner']['regular_price']; | |
} else { | |
$partner_price = pll__('No partner price is set for this product!'); | |
} | |
?> | |
<div class="product"> | |
<div <?php wc_product_class( 'uk-card uk-card-default uk-card-body product-grid uk-text-center uk-flex uk-flex-column', $product ); ?>> | |
<?php | |
/** | |
* Hook: woocommerce_before_shop_loop_item. | |
* | |
* @hooked woocommerce_template_loop_product_link_open - 10 | |
*/ | |
do_action( 'woocommerce_before_shop_loop_item' ); | |
/** | |
* Hook: woocommerce_before_shop_loop_item_title. | |
* | |
* @hooked woocommerce_show_product_loop_sale_flash - 10 | |
* @hooked woocommerce_template_loop_product_thumbnail - 10 | |
*/ | |
do_action( 'woocommerce_before_shop_loop_item_title' ); | |
/** | |
* Hook: woocommerce_shop_loop_item_title. | |
* | |
* @hooked woocommerce_template_loop_product_title - 10 | |
*/ | |
do_action( 'woocommerce_shop_loop_item_title' ); | |
/** | |
* Hook: woocommerce_after_shop_loop_item_title. | |
* | |
* @hooked woocommerce_template_loop_rating - 5 | |
* @hooked woocommerce_template_loop_price - 10 | |
*/ | |
do_action( 'woocommerce_after_shop_loop_item_title' ); | |
/** | |
* Hook: woocommerce_after_shop_loop_item. | |
* | |
* @hooked woocommerce_template_loop_product_link_close - 5 | |
* @hooked woocommerce_template_loop_add_to_cart - 10 | |
*/ | |
do_action( 'woocommerce_after_shop_loop_item' ); | |
?> | |
<div class="uk-card-media uk-flex uk-flex-center uk-flex-1"> | |
<?php if ($product_image) : ?> | |
<a href="<?php echo esc_url($product_permalink); ?>" title="<?php echo esc_html($product_title); ?>"> | |
<?php echo $product_image; ?> | |
</a> | |
<?php endif; ?> | |
</div> | |
<div class="uk-flex uk-flex-1 uk-flex-column uk-margin-top"> | |
<div class="product-brand"><?php echo $product_brand;?></div> | |
<h3 class="uk-card-title uk-margin-remove-top"> | |
<a href="<?php echo esc_url($product_permalink); ?>"> | |
<?php echo esc_html($product_title); ?> | |
</a> | |
</h3> | |
<div class="uk-panel uk-flex-1"> | |
<div class="product-short_desc"><?php echo $product_short_description; ?></div> | |
<div class="product-price"> | |
<?php if (user_has_role('Partner')) : ?> | |
<div class="product-price-partner"><?php echo $partner_price . ' ' . $currency_symbol; ?></div> | |
<?php elseif ($product_price !== '') : ?> | |
<div class="product-price-regular"><?php echo wc_price($product_price) . ' + ' . esc_html__( 'VAT', 'woocommerce' ) ?></div> | |
<?php else : ?> | |
<div class="product-price-regular"><?php pll_e('Partner-Only Pricing'); ?></div> | |
<?php endif; ?> | |
</div> | |
<?php if (!user_has_role('Partner')) : ?> | |
<div class="product-partner-link uk-margin-top"> | |
<a href="https://www.1home.io/partner-shop-signup" target="_blank" class="uk-flex uk-flex-middle uk-flex-center"> | |
<?php pll_e('Access partner pricing'); ?> <span uk-icon="icon: arrow-right; ratio: .9" style="margin-right: 3px"></span> | |
</a> | |
</div> | |
<?php endif; ?> | |
</div> | |
<div class="product-addtocart uk-flex uk-flex-wrap uk-margin-medium-top"> | |
<div> | |
<a href="<?php echo esc_url($product_permalink); ?>" class="uk-button uk-button-default"> | |
<?php pll_e('View'); ?> | |
</a> | |
</div> | |
<div> | |
<a href="<?php echo esc_url( $product->add_to_cart_url()); ?>" | |
class="button add_to_cart_button uk-button uk-button-primary" | |
data-product_id="<?php echo $product_id; ?>" | |
data-quantity="1"> | |
<?php echo esc_html($product->add_to_cart_text()); ?> | |
</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment