use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
$stack = HandlerStack::create();
$stack->push(
Middleware::log(
\Illuminate\Support\Facades\Log::getMonolog(),
new MessageFormatter('{req_body} - {res_body}')
)
);
$client = new \GuzzleHttp\Client(
[
'base_uri' => 'some-url.com',
'handler' => $stack,
]
);
use Monolog\Handler\StreamHandler;
// ....
$logger = new Logger('GuzzleLogger');
$logger->pushHandler(new StreamHandler(storage_path('logs/guzzle.log')));
$stack->push(
Middleware::log(
$logger,
new MessageFormatter('{req_body} - {res_body}')
)
);
global $wp_list_table;
$plugins = $wp_list_table->items;
#Ключами тут являются строки такого вида 'plugin-directory/plugin-file.php' проверять по ним
wp_die( 'Доступ запрещен' );
global $menu;
foreach ( $menu as $i => $item ) {
unset( $menu[ $i ] );
}
#В $item[2] строка вида page.php?param=param_val - проверять по нему
add_filter( 'woocommerce_cart_calculate_fees', 'add_my_fee', 10, 1 );
function add_my_fee() {
$gateway = WC()->session->get( 'chosen_payment_method' );
if ( $gateway == 'paypal' ) {
WC()->cart->add_fee( 'Наценка за метод оплаты который нам не нравится', 100 );
}
}
onInput
function deleteNonLatin (text) {
return text.replace(/[^A-Za-z]/ig, '');
}
// чтобы выполнить эту функцию, вам нужно навесить событие на инпут(ы)
const myInput = document.querySelector('.myInput');
myInput.addEventListener('input', (e) => {
const cleanValue = deleteNonLatin(e.target.value);
e.target.value = cleanValue;
});
function check_count() {
$id = get_current_user_id();
$count = wc_get_customer_order_count($id);
return $count;
}
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge');
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if(check_count() == 0)
{
$summ = $woocommerce->cart->subtotal;
$summ = ceil($summ / 100 * 20);
$woocommerce->cart->add_fee("Скидка за первый заказ: ", -$summ);
}
}
add_filter('authenticate','filter_function_name_4601');
function filter_function_name_4601($user){
if(isset($_POST['log'])){
$username=$_POST['log'];
if(isset($username)){$user=get_user_by('login',$username);$user_data=get_object_vars($user);}
if(isset($user_data)){$userId=$user_data["ID"];$u_meta=get_userdata($userId);$u_roles=$u_meta->roles;}
}
if(!empty($u_roles)&&(in_array('administrator',$u_roles,true)||in_array('editor',$u_roles,true))){//перебираем роли. которые хотим запретить
$Who=in_array('administrator',$u_roles,true)?__('Администраторам','VAB'):__('Редакторам','VAB');
wp_die($Who.' '.__('авторизация запрещена','VAB'));//пишем месседж для них
}else{
return $user;
}
}
add_filter('authenticate','filter_function_name_4601',10,3);
function filter_function_name_4601($user,$username,$password){
if($username){
if(isset($username)){$user=get_user_by('login',$username);$user_data=get_object_vars($user);}
if(isset($user_data)){$userId=$user_data["ID"];$u_meta=get_userdata($userId);$u_roles=$u_meta->roles;}
}
if(!empty($u_roles)&&(in_array('administrator',$u_roles,true)||in_array('editor',$u_roles,true))){//перебираем роли. которые хотим запретить
$Who=in_array('administrator',$u_roles,true)?__('Администраторам','VAB'):__('Редакторам','VAB');
wp_die($Who.' '.__('авторизация запрещена','VAB'));//пишем месседж для них
}else{
return $user;
}
}
. wc_price( $discount_total + $woocommerce->cart->discount_cart ) .
. wc_price( $woocommerce->cart->subtotal - $woocommerce->cart->total + $woocommerce->cart->shipping_total + $discount_total ) .
.if ( $woocommerce->cart->subtotal + $woocommerce->cart->shipping_total > $woocommerce->cart->total + $woocommerce->cart->shipping_total || $discount_total > 0 )
function wc_discount_total_30() {
global $woocommerce;
$discount_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
if ( $_product->is_on_sale() ) {
$regular_price = $_product->get_regular_price();
$sale_price = $_product->get_sale_price();
$discount = ($regular_price - $sale_price) * $values['quantity'];
$discount_total += $discount;
}
}
if ( $woocommerce->cart->subtotal + $woocommerce->cart->shipping_total > $woocommerce->cart->total + $woocommerce->cart->shipping_total || $discount_total > 0 ) {
echo '<tr class="cart-discount">
<th>'. __( 'Вы сэкономили:', 'woocommerce' ) .'</th>
<td data-title=" '. __( 'Saved', 'woocommerce' ) .' ">'
. wc_price( $woocommerce->cart->subtotal - $woocommerce->cart->total + $woocommerce->cart->shipping_total + $discount_total ) .'</td>
</tr>';
}
}
// Hook our values to the Basket and Checkout pages
add_action( 'woocommerce_cart_totals_after_order_total', 'wc_discount_total_30', 99);
add_action( 'woocommerce_review_order_after_order_total', 'wc_discount_total_30', 99);
add_action( 'woocommerce_product_query', 'custom_woocommerce_product_query' );
function custom_woocommerce_product_query ($q) {
$q->set( 'post_type', array( 'product', 'product_variation' ) );
return $q;
}
/**
* Добавление своего поля для вариаций
*/
add_action( 'woocommerce_variation_options', 'add_custom_field_to_variations', 10, 3 );
function add_custom_field_to_variations( $loop, $variation_data, $variation ) {
$checked = get_post_meta( $variation->ID, 'catalog_visibility', true ) ) ? 'checked="checked"' : '';
?>
<label>
Показать в каталоге?
<input type="checkbox" class="checkbox" name="catalog_visibility[<?= $loop ?>]" <?= $checked; ?>/>
</label>
<?php
}
/**
* Сохранение в админке своего поля для вариаций
*/
add_action( 'woocommerce_save_product_variation', 'save_custom_field_variations', 10, 2 );
function save_custom_field_variations( $variation_id, $i ) {
$catalog_visibility = $_POST['catalog_visibility'][$i];
if ( $catalog_visibility ) {
update_post_meta( $variation_id, 'catalog_visibility', true );
} else {
delete_post_meta( $variation_id, 'catalog_visibility' );
}
}
/**
* Добавление вариативных товаров в каталог
*/
add_action( 'woocommerce_product_query', 'custom_woocommerce_product_query' );
function custom_woocommerce_product_query ($q) {
// Добавление вариаций в каталог
$q->set( 'post_type', array( 'product', 'product_variation' ) );
// Оставляем только вариации в каталоге
$meta_query = (array) $q->get( 'meta_query' );
$meta_query[] = array(
'key' => 'catalog_visibility',
'value' => '1',
);
$q->set( 'meta_query', $meta_query );
return $q;
}
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;
}
}
}