foreach(WC()->cart->get_cart() as $cart_item ){
$sale = get_post_meta( $cart_item['product_id'], '_sale_price', true );
if(! isset($sale) ) :
$product_price = get_post_meta( $cart_item['product_id'], 'woo_second_price', true );
$products_total += $product_price * $cart_item['quantity'];
endif:
}
add_action( 'woocommerce_cart_calculate_fees', 'wpp_custom_surcharge' );
function wpp_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$percentage = 0.15;
$time = date( 'H' );
if ( 11 <= (int) $time && 12 > (int) $time ) :
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Счастливый час', - $surcharge, true, '' );
endif;
}
'order' => 'DESC',
'orderby' => 'meta_value_num',
'meta_query' => [
[
'relation' => 'OR',
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS'
],
[
'key' => '_thumbnail_id',
'compare' => '!NOT EXISTS'
]
]
$out = '';
$html = <<<HTML
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--%s">
<th class="woocommerce-product-attributes-item__label">%s</th>
<td class="woocommerce-product-attributes-item__value">%s</td>
</tr>
HTML;
$i = 1;
foreach ( $product_attributes as $attribute ):
$attribute_data = $attribute->get_data();
if ( $i !== 3 ) {
$out .= sprintf( $html, esc_attr( $attribute_data['name'] ), wc_attribute_label( $attribute_data['name'], $product->get_attribute( $attribute_data['name'] ) ) );
} else {
printf( $html, esc_attr( $attribute_data['name'] ), wc_attribute_label( $attribute_data['name'], $product->get_attribute( $attribute_data['name'] ) ) );
}
$i ++;
endforeach;
echo $out;
WC()->cart->add_to_cart( $product_id );
$product_cart_id = WC()->cart->generate_cart_id( $product_id );
$in_cart = WC()->cart->find_product_in_cart( $product_cart_id );
function wpp_change_wc_block() {
global $post;
if ( has_term( [ $term_1_ID, $term_2_ID ], 'product_cat', $post ) ) {
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 6 );
}
}
add_action( 'init', 'pp_change_wc_block' );