add_action( 'woocommerce_new_order', 'new_order_send_tg', 1, 1 );
function new_order_send_tg( $order_id ) {
$order = new WC_Order( $order_id );
$order_data = $order->get_data();
$products_post_title_in_cart = array();
foreach(WC()->cart->get_cart() as $cart_item) {
$products_post_title_in_cart[] = $cart_item['data']->post->post_title;
}
$product_name = implode("\n", $products_post_title_in_cart);
$order_billing_first_name = $order_data['billing']['first_name'];
$msg = '*Магазин myshop.ru*';
$msg .= ' Новый заказ: '.$order_id;
$msg .= ' Имя: '.$order_billing_first_name;
$msg .= '*Название товара:* '."\n".$product_name;
$userId = '*********'; // Ваш id в телеграм
$token = '*************************************'; // Token бота
file_get_contents('https://api.telegram.org/bot'. $token .'/sendMessage?chat_id='. $userId .'&text=' . urlencode($msg) . '&parse_mode=markdown'); // Отправляем сообщение
}
add_filter( 'woocommerce_template_loader_files','add_shop_template_loader_files', 10, 1 );
function add_shop_template_loader_files($default_file){
if( is_shop()){
$default_file[] = WC()->template_path() .'shop.php';
}
return $default_file;
}
add_action( 'product_cat_edit_form_fields', 'wpm_taxonomy_edit_meta_field', 10, 2 );
function wpm_taxonomy_edit_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$content = $term_meta['custom_term_meta'] ? wp_kses_post( $term_meta['custom_term_meta'] ) : '';
$settings = array( 'textarea_name' => 'term_meta[custom_term_meta]' );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]">Дополнительное описание</label></th>
<td>
<?php wp_editor( $content, 'product_cat_details', $settings ); ?>
</td>
</tr>
<?php
}
add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = wp_kses_post( stripslashes($_POST['term_meta'][$key]) );
}
}
update_option( "taxonomy_$t_id", $term_meta );
}
}
add_action( 'woocommerce_after_shop_loop', 'wpm_product_cat_archive_add_meta' );
function wpm_product_cat_archive_add_meta() {
$t_id = get_queried_object()->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$term_meta_content = $term_meta['custom_term_meta'];
if ( $term_meta_content != '' ) {
if ( is_tax( array( 'product_cat', 'product_tag' ) ) && 0 === absint( get_query_var( 'paged' ) ) ) {
echo '<div class="woo-sc-box normal rounded full">';
echo apply_filters( 'the_content', $term_meta_content );
echo '</div>';
}
}
}
add_filter( 'woocommerce_add_to_cart_validation', 'one_cart_item_at_the_time', 10, 3 );
function one_cart_item_at_the_time( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty())
WC()->cart->empty_cart();
return $passed;
}
add_filter('woocommerce_add_to_cart_validation', 'one_cart_item_at_the_time', 10, 3);
function one_cart_item_at_the_time( $passed, $product_id, $quantity ) {
if(! WC()->cart->is_empty()) {
$cartId = WC()->cart->generate_cart_id($product_id);
$cartItemKey = WC()->cart->find_product_in_cart($cartId);
if ($cartItemKey) {
return $passed;
} else {
$woocommerce->cart->add_to_cart( $product_id );
return $passed;
}
}
}