Skip to content

Instantly share code, notes, and snippets.

@DxDiagDx
Created July 21, 2021 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DxDiagDx/8f43cc090f013655f68152a03f936e0e to your computer and use it in GitHub Desktop.
Save DxDiagDx/8f43cc090f013655f68152a03f936e0e to your computer and use it in GitHub Desktop.
Woo: вывести в карточке товара ссылки на другие товары (через апсейл)
/* Карточка товара */
// Короткое описание
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
function woocommerce_template_single_excerpt() {
global $product;
$upsale_products = $product->get_upsell_ids();
if ( !empty($upsale_products) ) {
?>
<div class="other_models">
<div class="other_models_heading">Другие размеры этой модели</div>
<div class="other_models_content">
<?php
foreach ( $upsale_products as $upsale_product_id ) {
$product_new = new WC_Product($upsale_product_id);
$product_attribute = $product_new->get_attribute( 'pa_size' );
$terms = get_the_terms( $upsale_product_id, 'product_cat' );
foreach ($terms as $term) {
$product_cat = $term->name;
break;
}
$product_name = $product_new->get_name();
$product_price = $product_new->get_price();
$product_url = $product_new->get_permalink();
$product_thumbnail = $product_new->get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true );
$product_name_short = $product_cat . ' ' . $product_attribute;
?>
<div class="other_model">
<?php echo($product_thumbnail) ?>
<a class="model_name" href="<?php echo($product_url) ?>"><?php echo($product_name_short) ?></a>
<span class="woocommerce-Price-amount amount">
<bdi><?php echo($product_price) ?> <span class="woocommerce-Price-currencySymbol">₽</span></bdi>
</span>
</div>
<?php
}
?>
</div>
</div>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment