get_var( "SELECT iso_alpha2 FROM " . $wpdb->prefix . "speedy_countries WHERE id = '" . $_POST['country_id'] . "'" );
WC()->session->set( 'speedy_chosen_country_code', $country_code);
}
$response = json_encode($result, JSON_UNESCAPED_UNICODE);
echo $response;
exit();
}
function speedy_country_cod_scripts_ajax() {
if(is_checkout()){
?>
' . $html . '';
return $html;
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
// Mrejanet mod add COD fee
add_action( 'woocommerce_cart_calculate_fees','cod_fee' );
function cod_fee() {
global $woocommerce, $woocommerce_wpml;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// get your payment method
$chosen_gateway = WC()->session->chosen_payment_method;
$cart_total = (float)WC()->cart->get_cart_contents_total();
$fee = 0.50;
if ( $chosen_gateway == 'cod' ) {
WC()->cart->add_fee( __('Такса наложен платеж ', 'bambukifamily'), $fee, false, '' ) ;
} else {
$fees = WC()->cart->get_fees();
foreach ($fees as $key => $f) {
if($fees[$key]->name === 'Такса наложен платеж :') {
unset($fees[$key]);
}
}
}
}
add_action( 'wp_footer', 'checkout_update_fee_script' );
function checkout_update_fee_script() {
if (is_checkout()){
?>
'Австрия', 'BE' => 'Белгия', 'BG' => 'България', 'RO' => 'Румъния', 'DE' => 'Германия', 'GR' => 'Гърция',
'DK' => 'Дания', 'EE' => 'Естония', 'IE' => 'Ирландия', 'ES' => 'Испания', 'IT' => 'Италия', 'CY' => 'Кипър',
'LV' => 'Латвия', 'LT' => 'Литва', 'LU' => 'Люксембург', 'MT' => 'Малта', 'NL' => 'Холандия', 'PL' => 'Полша',
'PT' => 'Португалия', 'SK' => 'Словакия', 'SI' => 'Словения', 'HU' => 'Унгария', 'FI' => 'Финландия', 'HR' => 'Хърватия',
'CZ' => 'Чехия', 'SE' => 'Швеция', 'AL' => 'Албания', 'AD' => 'Андора', 'BA' => 'Босна и Херцеговина', 'IS' => 'Исландия',
'IC' => 'Канарските острови', 'LI' => 'Лихтенщайн', 'MC' => 'Монако', 'NO' => 'Норвегия', 'MK' => 'Северна Македония',
'RS' => 'Сърбия', 'TR' => 'Турция', 'ME' => 'Черна гора', 'CH' => 'Швейцария',
);
} else {
$countries = array(
'' => '', 'AT' => 'Austria', 'BE' => 'Belgium', 'BG' => 'Bulgaria', 'RO' => 'Romania', 'DE' => 'Germany', 'GR' => 'Greece',
'DK' => 'Denmark', 'EE' => 'Estonia', 'IE' => 'Ireland', 'ES' => 'Spain', 'IT' => 'Italy', 'CY' => 'Cyprus',
'LV' => 'Latvia', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MT' => 'Malta', 'NL' => 'Netherlands', 'PL' => 'Poland',
'PT' => 'Portugal', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'HU' => 'Hungary', 'FI' => 'Finland', 'HR' => 'Croatia',
'CZ' => 'Czech Republic', 'SE' => 'Sweden', 'AL' => 'Albania', 'AD' => 'Andorra', 'BA' => 'Bosnia and Herzegovina',
'IS' => 'Iceland', 'IC' => 'The Canary Islands', 'LI' => 'Liechtenstein', 'MC' => 'Monaco', 'NO' => 'Norway',
'MK' => 'North Macedonia', 'RS' => 'Serbia', 'TR' => 'Turkey', 'ME' => 'Montenegro', 'CH' => 'Switzerland',
);
}
return $countries;
}
// Woocommerce quantity buttons fix
add_filter( 'woocommerce_quantity_input_args', 'custom_quantity_input_args', 20, 2 );
function custom_quantity_input_args( $args, $product ) {
if( $product->get_stock_quantity() == 1 && is_product() ){
$args['max_value'] = '';
}
return $args;
}
add_action('wp_head', 'fregata_scripts');
function fregata_scripts(){
?>
$filter_array ) {
if ( isset( $filter_array['function'] ) && is_array( $filter_array['function'] ) ) {
if ( is_object( $filter_array['function'][0] ) && get_class( $filter_array['function'][0] ) && $filter_array['function'][1] == $method_name ) {
if ( is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) {
unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $unique_id ] );
} else {
unset( $wp_filter[ $hook_name ][ $priority ][ $unique_id ] );
}
}
}
}
return false;
}
function bambuki_filter_related_products_primary_category_only($terms, $product_id) {
$prodterms = get_the_terms($product_id, 'product_cat');
$primary_category = bambuki_get_post_primary_category($product_id);
if(!empty($primary_category) && isset($primary_category['primary_category'])){
$terms = array();
foreach ($prodterms as $k => $prodterm) {
if ($primary_category['primary_category']->term_id == $prodterm->term_id) {
$terms[] = $prodterm->term_id;
break;
}
}
}
return $terms;
}
add_filter( 'woocommerce_get_related_product_cat_terms', 'bambuki_filter_related_products_primary_category_only', 20, 2 );
function bambuki_get_post_primary_category($post_id, $term='product_cat', $return_all_categories=false){
$return = array();
if (class_exists('WPSEO_Primary_Term')){
$wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id );
$primary_term = get_term($wpseo_primary_term->get_primary_term());
if (!is_wp_error($primary_term)){
$return['primary_category'] = $primary_term;
}
}
if (empty($return['primary_category']) || $return_all_categories){
$categories_list = get_the_terms($post_id, $term);
if (empty($return['primary_category']) && !empty($categories_list)){
$return['primary_category'] = $categories_list[0];
}
if ($return_all_categories){
$return['all_categories'] = array();
if (!empty($categories_list)){
foreach($categories_list as &$category){
$return['all_categories'][] = $category->term_id;
}
}
}
}
return $return;
}
/* Related products in cart based on selected items */
add_action('woocommerce_after_cart', 'bambuki_get_related_products_base_cart_items');
function bambuki_get_related_products_base_cart_items() {
$cart = WC()->cart;
if ( empty( $cart ) || $cart->is_empty() ) {
return;
}
$cart_items = $cart->get_cart();
$product_ids = [];
foreach ( $cart_items as $item ) {
$related_products = wc_get_related_products( $item['product_id'], -1 );
foreach ($related_products as $key => $product_id) {
$prodterms = get_the_terms($product_id, 'product_cat');
$primary_category = bambuki_get_post_primary_category($item['product_id']);
if(!empty($primary_category) && isset($primary_category['primary_category'])){
foreach ($prodterms as $k => $prodterm) {
if ($primary_category['primary_category']->term_id == $prodterm->term_id) {
$product_ids[] = $product_id;
break;
}
}
}
}
}
$product_ids = array_slice($product_ids, 0, 8);
echo '
' . __('Може да харесате и тези', 'bambuki') . ' ';
$args = [
'post_type' => 'product',
'posts_per_page' => -1,
'post__in' => $product_ids
];
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
wc_get_template_part( 'content', 'product' );
}
}
echo ' ';
}
/**
* Change number of related products output
*/
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args', 99 );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 20;
$args['columns'] = 4;
return $args;
}
// Disable Gutenberg
add_filter( 'use_block_editor_for_post', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );
add_action( 'wp_enqueue_scripts', function() {
wp_dequeue_style( 'wp-block-library' );
wp_dequeue_style( 'wp-block-library-theme' );
wp_dequeue_style( 'global-styles' );
wp_dequeue_style( 'classic-theme-styles' );
}, 20 );
/* Change thumbnail quality in woocommerce */
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
return array(
'width' => 400,
'height' => 400,
'crop' => 0,
);
} );
/* Change placeholder text in search form */
function custom_search_placeholder_script() {
?>
customer->get_billing_country();
if ($billing_country !== 'BG') {
unset($available_gateways['cod']);
}
}
return $available_gateways;
}
add_filter('woocommerce_available_payment_gateways', 'disable_cod_for_non_bg');
/* Fix for coupon codes with fixed amount */
/**
* Detect YITH Gift Card "coupon codes" so our custom coupon restrictions don't affect them.
*/
function bambuki_is_yith_gift_card_coupon( $coupon ) {
if ( ! $coupon || ! is_object( $coupon ) || ! method_exists( $coupon, 'get_code' ) ) {
return false;
}
if ( ! class_exists( 'YITH_YWGC_Cart_Checkout' ) && ! class_exists( 'YITH_YWGC_Gift_Card' ) ) {
return false;
}
$code = strtoupper( trim( (string) $coupon->get_code() ) );
if ( preg_match( '/^[A-F0-9]{4}(?:-[A-F0-9]{4}){3}$/', $code ) ) {
return true;
}
if ( isset( WC()->session ) ) {
$applied = WC()->session->get( 'applied_gift_cards', array() );
if ( ! empty( $applied ) && is_array( $applied ) ) {
$applied = array_map( 'strtoupper', array_map( 'strval', $applied ) );
if ( in_array( $code, $applied, true ) ) {
return true;
}
}
}
return false;
}
add_filter('woocommerce_coupon_is_valid', function ($is_valid, $coupon, $discount) {
if ( bambuki_is_yith_gift_card_coupon( $coupon ) ) {
return $is_valid;
}
$excluded_coupons = ['bmbk1529', 'bmbk1068', 'vipdiscount', 'bmbk3000'];
if (in_array($coupon->get_code(), $excluded_coupons, true)) {
return $is_valid;
}
if ($coupon->get_discount_type() !== 'fixed_cart') {
return $is_valid;
}
$coupon_generated_by = $coupon->get_meta('coupon_generated_by');
if ($coupon_generated_by === 'woo-cart-abandonment-recovery') {
return $is_valid;
}
$non_sale_total = 0;
foreach (WC()->cart->get_cart() as $cart_item) {
$product = $cart_item['data'];
if (!$product->is_on_sale()) {
$non_sale_total += $cart_item['line_subtotal'];
}
}
if ($non_sale_total <= 0) {
wc_add_notice(__('Този код важи само за продукти без отстъпка.', 'woocommerce'), 'error');
return false;
}
$min_amount = (float) $coupon->get_minimum_amount();
if ($min_amount > 0 && $non_sale_total < $min_amount) {
wc_add_notice(sprintf(__('Минималната стойност на продуктите без отстъпка трябва да е поне %s, за да използвате този код.', 'woocommerce'), wc_price($min_amount)), 'error');
return false;
}
return true;
}, 10, 3);
add_filter('woocommerce_coupon_get_discount_amount', function ($discount, $discounting_amount, $cart_item, $single, $coupon) {
if ( bambuki_is_yith_gift_card_coupon( $coupon ) ) {
return $discount;
}
$excluded_coupons = ['bmbk1529', 'bmbk1068', 'vipdiscount', 'bmbk3000'];
if (in_array($coupon->get_code(), $excluded_coupons, true)) {
return $discount;
}
if ($coupon->get_discount_type() !== 'fixed_cart') {
return $discount;
}
$product = $cart_item['data'];
if ($product->is_on_sale()) {
return 0;
}
$cart = WC()->cart;
$total = 0;
foreach ($cart->get_cart() as $item) {
$p = $item['data'];
if (!$p->is_on_sale()) {
$total += $item['line_subtotal'];
}
}
if ($total <= 0) {
return 0;
}
$proportion = $cart_item['line_subtotal'] / $total;
$fixed_discount = $coupon->get_amount();
return round($fixed_discount * $proportion, wc_get_price_decimals());
}, 10, 5);
// NOTE: Duplicate filter for percentage coupons (Abandonment recovery)
add_filter('woocommerce_coupon_get_discount_amount', function ($discount, $discounting_amount, $cart_item, $single, $coupon) {
if ( bambuki_is_yith_gift_card_coupon( $coupon ) ) {
return $discount;
}
$excluded_coupons = ['bmbk1529', 'bmbk1068', 'vipdiscount' , 'bmbk3000'];
if (in_array($coupon->get_code(), $excluded_coupons, true)) {
return $discount;
}
$coupon_generated_by = $coupon->get_meta('coupon_generated_by');
if ($coupon_generated_by !== 'woo-cart-abandonment-recovery') {
return $discount;
}
$product = $cart_item['data'];
if ($product->is_on_sale()) {
return 0;
}
$percentage = $coupon->get_amount();
$discount_amount = $discounting_amount * ($percentage / 100);
return round($discount_amount, wc_get_price_decimals());
}, 10, 5);
if (!function_exists('write_log')) {
function write_log ( $log ) {
if ( true === WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
}
add_filter('woocommerce_available_payment_gateways', 'disable_cod_for_virtual_products');
function disable_cod_for_virtual_products($available_gateways) {
if (is_admin() || !is_checkout()) return $available_gateways;
$virtual_product_in_cart = false;
foreach (WC()->cart->get_cart() as $cart_item) {
if ($cart_item['data']->is_virtual()) {
$virtual_product_in_cart = true;
break;
}
}
if ($virtual_product_in_cart && isset($available_gateways['cod'])) {
unset($available_gateways['cod']);
}
return $available_gateways;
}
// No mixing Virtual and physical products in the cart
add_filter('woocommerce_add_to_cart_validation', 'strictly_prevent_virtual_physical_mixing', 10, 4);
function strictly_prevent_virtual_physical_mixing($passed, $product_id, $quantity, $variation_id = 0) {
if (is_admin()) return $passed;
$product_to_add = wc_get_product($variation_id ? $variation_id : $product_id);
$is_virtual_to_add = $product_to_add->is_virtual();
$cart_has_virtual = false;
$cart_has_physical = false;
foreach (WC()->cart->get_cart() as $cart_item) {
$cart_product = $cart_item['data'];
$is_virtual = $cart_product->is_virtual() || $cart_product->get_type() === 'yith_gift_card';
if ($is_virtual) {
$cart_has_virtual = true;
} else {
$cart_has_physical = true;
}
}
if ( ($is_virtual_to_add && $cart_has_physical) || (!$is_virtual_to_add && $cart_has_virtual) ) {
wc_add_notice(__('Не можете да смесвате виртуални и физически продукти в една и съща поръчка.', 'woocommerce'), 'error');
return false;
}
return $passed;
}
// When a virtual product in cart - send directly to checkout
add_action('template_redirect', 'redirect_virtual_cart_to_checkout');
function redirect_virtual_cart_to_checkout() {
if (is_cart() && !is_admin() && !WC()->cart->is_empty()) {
$all_virtual = true;
foreach (WC()->cart->get_cart() as $cart_item) {
if (!$cart_item['data']->is_virtual()) {
$all_virtual = false;
break;
}
}
if ($all_virtual) {
wp_safe_redirect(wc_get_checkout_url());
exit;
}
}
}
// 1. Hide BOX NOW if cart contains products with 'heavy-products' shipping class
add_filter('woocommerce_package_rates', 'hide_boxnow_for_heavy_products_safe', 10, 2);
function hide_boxnow_for_heavy_products_safe($rates, $package) {
if (!WC()->cart) return $rates;
foreach ($package['contents'] as $item) {
$product = $item['data'];
if ($product->get_shipping_class() === 'heavy-products') {
foreach ($rates as $rate_id => $rate) {
if ($rate->method_id === 'box_now_delivery') {
unset($rates[$rate_id]);
}
}
break;
}
}
return $rates;
}
// 2. Clear BOX NOW selection if it's invalid (due to heavy product)
add_action('template_redirect', 'reset_boxnow_shipping_method_if_heavy');
function reset_boxnow_shipping_method_if_heavy() {
if (!is_checkout() || is_wc_endpoint_url()) return;
if (!WC()->cart || WC()->cart->is_empty()) return;
foreach (WC()->cart->get_cart_contents() as $item) {
$product = $item['data'];
if ($product->get_shipping_class() === 'heavy-products') {
$chosen_methods = WC()->session->get('chosen_shipping_methods');
if (!empty($chosen_methods) && is_array($chosen_methods)) {
if (strpos($chosen_methods[0], 'box_now_delivery') !== false) {
WC()->session->set('chosen_shipping_methods', array(''));
}
}
break;
}
}
}
// 3. Disable free Speedy delivery for heavy products
add_filter('speedy_shipping_price', 'disable_free_speedy_for_heavy_products', 10, 5);
function disable_free_speedy_for_heavy_products($shipping_price, $speedy_options, $data, $price, $service_id) {
if (!WC()->cart || WC()->cart->is_empty()) return $shipping_price;
foreach (WC()->cart->get_cart() as $item) {
$product = $item['data'];
if ($product->get_shipping_class() === 'heavy-products') {
$shipping_price['recipient'] = $shipping_price['total'];
break;
}
}
return $shipping_price;
}
// 4. Disable bank transfer when BOX NOW is selected
add_filter('woocommerce_available_payment_gateways', 'disable_bank_transfer_when_boxnow');
function disable_bank_transfer_when_boxnow($available_gateways) {
if (!is_checkout() || !WC()->session) return $available_gateways;
$chosen_methods = WC()->session->get('chosen_shipping_methods');
if (!empty($chosen_methods) && is_array($chosen_methods)) {
if (strpos($chosen_methods[0], 'box_now_delivery') !== false) {
unset($available_gateways['bacs']);
}
}
return $available_gateways;
}
// Scroll to BoxNow Map
add_action('wp_footer', function () {
?>
cart && ! WC()->cart->needs_shipping() ) {
return;
}
echo '';
wc_cart_totals_shipping_html();
echo '
';
}, 5 );
add_filter( 'woocommerce_update_order_review_fragments', function ( $fragments ) {
if ( ! function_exists( 'wc_cart_totals_shipping_html' ) ) {
return $fragments;
}
ob_start();
echo '';
wc_cart_totals_shipping_html();
echo '
';
$fragments['#bambuki-shipping-top'] = ob_get_clean();
return $fragments;
} );
add_action( 'wp_enqueue_scripts', function () {
if ( ! function_exists( 'is_checkout' ) || ! is_checkout() || is_order_received_page() ) {
return;
}
$css = '
/* Default: hide cloned */
#bambuki-shipping-top { display: none; }
.woocommerce-checkout-review-order .woocommerce-shipping-totals.shipping { display: block; }
/* Mobile only: show cloned at top, hide original in order review */
@media (max-width: 767px) {
#bambuki-shipping-top { display: block; }
.woocommerce-checkout-review-order .woocommerce-shipping-totals.shipping { display: none !important; }
#bambuki-shipping-top .woocommerce-shipping-methods {
list-style: none; margin: 0; padding: 0;
}
#bambuki-shipping-top .woocommerce-shipping-methods li {
list-style: none; margin: 0 0 10px 0; padding: 0;
}
}
';
$handle = wp_style_is( 'woocommerce-inline', 'enqueued' ) ? 'woocommerce-inline' : 'woocommerce-general';
wp_add_inline_style( $handle, $css );
}, 99 );
// Site-wide attribute label override
add_filter( 'woocommerce_attribute_label', function( $label, $name, $product ) {
$map = array(
'pa_size' => 'ИЗБЕРЕТЕ РАЗМЕР',
'pa_hat-size' => 'ИЗБЕРЕТЕ РАЗМЕР',
'pa_color' => 'ИЗБЕРЕТЕ ЦВЯТ',
'pa_material' => 'ИЗБЕРЕТЕ МАТЕРИЯ',
);
if ( isset( $map[ $name ] ) ) {
return $map[ $name ];
}
return $label;
}, 10, 3 );
// Remove the VI WPVS "blank" swatch
add_action( 'wp_footer', function () {
if ( ! is_product() ) {
return;
}
?>
'РАЗМЕР', 'pa_hat-size' => 'РАЗМЕР',
'pa_color' => 'ЦВЯТ', 'pa_colour' => 'ЦВЯТ',
'pa_material' => 'МАТЕРИЯ',
);
$noun = isset($map[$slug]) ? $map[$slug]
: (preg_match('/color|colour/i',$slug) ? 'ЦВЯТ'
: (preg_match('/size|hat-size|razmer/i',$slug) ? 'РАЗМЕР' : 'ОПЦИЯ'));
$args['show_option_none'] = 'ИЗБЕРЕТЕ ' . $noun;
return $args;
}, 999 );
// Edit a string in checkout
add_filter( 'gettext', 'my_mailchimp_newsletter_text', 20, 3 );
function my_mailchimp_newsletter_text( $translated, $original, $domain ) {
if ( $original === 'Subscribe to our newsletter' ) {
return 'Абонирай се за нашия бюлетин';
}
return $translated;
}
/**
* Add BoxNow logo before its shipping label text (PHP version - Preferred)
*/
add_filter('woocommerce_cart_shipping_method_full_label', function ($label, $method) {
if ($method->id === 'box_now_delivery') {
$logo = ' ';
$label = $logo . $label;
}
return $label;
}, 10, 2);
// Remove "Архиви" from category and tag titles
add_filter('get_the_archive_title', function ($title) {
if (is_category()) {
$title = single_cat_title('', false);
} elseif (is_tag()) {
$title = single_tag_title('', false);
} elseif (is_tax()) {
$title = single_term_title('', false);
}
return $title;
});
// Prevent WooCommerce from pre-selecting a shipping method by default
add_filter('woocommerce_shipping_chosen_method', 'no_default_shipping_method', 10, 3);
function no_default_shipping_method($method, $available_methods, $chosen_method) {
if (isset($_POST['shipping_method'])) {
return $method;
}
return '';
}
/**
* Checkout (mobile only): show "Цена за доставка" above the order total
*/
add_action( 'woocommerce_review_order_before_order_total', function () {
if ( ! WC()->cart ) {
return;
}
if ( ! WC()->cart->needs_shipping() || ! WC()->cart->show_shipping() ) {
return;
}
$shipping_total = (float) WC()->cart->get_shipping_total();
$shipping_tax = (float) WC()->cart->get_shipping_tax();
if ( WC()->cart->display_prices_including_tax() ) {
$shipping_total += $shipping_tax;
}
echo '
Доставка
' . wc_price( $shipping_total ) . '
';
}, 20 );
/**
* Hide the shipping totals block on mobile (checkout only).
*/
add_action( 'wp_head', function () {
if ( ! function_exists( 'is_checkout' ) || ! is_checkout() || is_wc_endpoint_url( 'order-received' ) ) {
return;
}
?>
Размер:
Ширина:20cm.
Височина:16cm.
what are you looking for?
затвори
Този сайт използва "бисквитки", за да улесним Вашето сърфиране и да Ви покажем съдържание, което може да ви заинтересува. Използвайки този сайт, Вие се съгласявате с нашите условия СЪГЛАСЕН СЪМ