<?php
/**
* Hook: woocommerce_before_single_product_summary.
*
* @hooked woocommerce_show_product_sale_flash - 10
* @hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary entry-summary">
<?php
/**
* Hook: woocommerce_single_product_summary.
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
* @hooked WC_Structured_Data::generate_product_data() - 60
*/
do_action( 'woocommerce_single_product_summary' );
?>
</div>
<?php
/**
* Hook: woocommerce_after_single_product_summary.
*
* @hooked woocommerce_output_product_data_tabs - 10
* @hooked woocommerce_upsell_display - 15
* @hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
</div>
if (isset($query_args['tax_query'])) {
foreach ($query_args['tax_query'] as $key => $tax) {
if ( $tax['taxonomy'] === 'product_visibility') {
unset($query_args['tax_query'][$key]);
}
}
$query_args['tax_query'] = array_values($query_args['tax_query']);
}
add_filter('woocommerce_structured_data_product', 'add_missing_structured_data_fields', 10, 2);
function add_missing_structured_data_fields($markup, $product) {
$reviews = get_comments(array(
'post_id' => $product->get_id(),
'status' => 'approve',
'type' => 'review'
));
if ($reviews) {
$markup['review'] = array();
foreach ($reviews as $review) {
$rating = get_comment_meta($review->comment_ID, 'rating', true);
$markup['review'][] = array(
'@type' => 'Review',
'author' => array(
'@type' => 'Person',
'name' => get_comment_author($review->comment_ID)
),
'datePublished' => get_comment_date('c', $review->comment_ID),
'description' => get_comment_text($review->comment_ID),
'reviewRating' => array(
'@type' => 'Rating',
'ratingValue' => $rating ? $rating : 5,
'bestRating' => 5,
'worstRating' => 1
)
);
}
}
if ($product->get_rating_count() > 0) {
$markup['aggregateRating'] = array(
'@type' => 'AggregateRating',
'ratingValue' => $product->get_average_rating(),
'reviewCount' => $product->get_review_count(),
'bestRating' => '5',
'worstRating' => '1'
);
}
$markup['shippingDetails'] = array(
'@type' => 'OfferShippingDetails',
'shippingRate' => array(
'@type' => 'MonetaryAmount',
'value' => '0',
'currency' => get_woocommerce_currency()
),
'shippingDestination' => array(
'@type' => 'DefinedRegion',
'addressCountry' => 'RU'
)
);
$markup['hasMerchantReturnPolicy'] = array(
'@type' => 'MerchantReturnPolicy',
'applicableCountry' => 'RU',
'returnPolicyCategory' => 'https://schema.org/MerchantReturnFiniteReturnWindow',
'merchantReturnDays' => 14,
'returnMethod' => 'https://schema.org/ReturnByMail',
'returnFees' => 'https://schema.org/FreeReturn'
);
return $markup;
}
add_action('woocommerce_thankyou', 'wpp_auto_complete_free_fully_downloadable_orders');
function wpp_auto_complete_free_fully_downloadable_orders($order_id) {
$order = wc_get_order($order_id);
if (!$order || !in_array($order->get_status(), ['pending', 'on-hold', 'processing'])) {
return;
}
if ($order->get_total() != 0) {
return;
}
$all_downloadable = true;
foreach ($order->get_items() as $item) {
$product = $item->get_product();
if (!$product || !$product->is_downloadable()) {
$all_downloadable = false;
break;
}
}
if ($all_downloadable) {
$order->update_status(
'completed',
'All items are free and downloadable. Order completed automatically.'
);
}
}
foreach( $order->get_items() as $item_id => $item ) :
//$item - это и будет ваш продукт
wp_kses_post($item->get_name());
endforeach;
add_action( 'woocommerce_after_shop_loop_item', 'ruta_custom_product_card_details', 6 );
function ruta_custom_product_card_details() {
global $post;
if ( has_term( [ 'exclusive' ], 'product_cat', $post->ID ) ) {
printf( '<div class="product-card__badges_exclusive">%s</div>', __( 'Exclusive', 'text-domain' ) );
}
}
//функция для изменения цен с помощью числа
function wpp_price_plus() {
return 100;
}
add_filter('woocommerce_product_variation_get_regular_price', 'wpp_custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'wpp_custom_price', 99, 2 );
function wpp_custom_price( $price, $product ) {
return (float) $price + wpp_price_plus();
}
add_filter('woocommerce_variation_prices_price', 'wpp_custom_variable_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'wpp_custom_variable_price', 99, 3 );
function wpp_custom_variable_price( $price, $variation, $product ) {
// Удаление кэшированной цены продукта
wc_delete_product_transients($variation->get_id());
return (float) $price + wpp_price_plus();
}
// Обработка кэширования цен
add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_plus_to_variation_prices_hash', 99, 3 );
function add_price_plus_to_variation_prices_hash( $price_hash, $product, $for_display ) {
$price_hash[] = wpp_price_plus();
return $price_hash;
}