true, 'strategy' => 'defer', ) ); wp_localize_script( 'objeka-toolkit', 'objekaToolkit', array( 'api' => esc_url_raw( rest_url( 'wc/store/v1/' ) ), 'cartUrl' => wc_get_cart_url(), 'checkoutUrl' => wc_get_checkout_url(), 'currency' => get_woocommerce_currency(), 'locale' => str_replace( '_', '-', get_locale() ), 'i18n' => array( 'empty' => __( 'Your bag is waiting for something good.', 'objeka-toolkit' ), 'error' => __( 'We could not update your bag. Please try again or open the cart page.', 'objeka-toolkit' ), 'quantity' => __( 'Quantity', 'objeka-toolkit' ), 'remove' => __( 'Remove', 'objeka-toolkit' ), 'add' => __( 'Add to bag', 'objeka-toolkit' ), 'added' => __( 'Your bag has been updated.', 'objeka-toolkit' ), 'expired' => __( 'This countdown has ended.', 'objeka-toolkit' ), 'qualify' => __( 'Your subtotal meets this zone’s free shipping minimum. Confirm delivery options at checkout.', 'objeka-toolkit' ), /* translators: %s: formatted amount remaining to the configured shipping minimum. */ 'shipping' => __( '%s to this zone’s free shipping minimum.', 'objeka-toolkit' ), 'bump' => __( 'A considered addition', 'objeka-toolkit' ), ), ) ); } /** * Calculate volume prices from the stored product price on every totals pass. * * @param WC_Cart $cart Cart being recalculated. */ public static function discounts( $cart ) { if ( is_admin() && ! wp_doing_ajax() ) { return; } foreach ( $cart->get_cart() as $item ) { $product = $item['data']; $parent = $product->get_parent_id() ? wc_get_product( $product->get_parent_id() ) : $product; if ( ! $parent || 'yes' !== $parent->get_meta( '_objeka_bundles' ) || $product->is_sold_individually() ) { continue; } $stored = wc_get_product( $product->get_id() ); if ( ! $stored ) { continue; } $quantity = (int) $item['quantity']; $factor = $quantity >= 3 ? 0.75 : ( $quantity >= 2 ? 0.85 : 1 ); $product->set_price( (float) $stored->get_price( 'edit' ) * $factor ); } } /** * Render progressive enhancements inside the standard purchase form. */ public static function product_tools() { global $product; if ( ! $product || ! $product->is_purchasable() || ! $product->is_in_stock() || ! $product->is_type( array( 'simple', 'variable' ) ) ) { return; } include OBJEKA_TOOLKIT_DIR . 'templates/product-tools.php'; } /** Render optional guides after the purchase control so they do not delay it. */ public static function product_guides() { global $product; if ( $product ) { include OBJEKA_TOOLKIT_DIR . 'templates/product-guides.php'; } } /** * Render a purchase bar that JavaScript reveals only after the form leaves view. */ public static function sticky() { global $product; if ( ! $product || ! $product->is_purchasable() || ! $product->is_in_stock() || ! $product->is_type( array( 'simple', 'variable' ) ) ) { return; } ?>

↗
\Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema::IDENTIFIER, 'namespace' => 'objeka', 'data_callback' => array( __CLASS__, 'cart_context' ), 'schema_callback' => static function () { return array( 'shipping' => array( 'description' => 'Shipping minimum for the current zone.', 'type' => array( 'object', 'null' ), 'readonly' => true, 'properties' => array( 'minimum' => array( 'type' => 'number' ), 'subtotal' => array( 'type' => 'number' ), ), ), 'bump' => array( 'description' => 'Optional explicitly selected product addition.', 'type' => array( 'object', 'null' ), 'readonly' => true, 'properties' => array( 'id' => array( 'type' => 'integer' ), 'name' => array( 'type' => 'string' ), 'price' => array( 'type' => 'number' ), ), ), ); }, 'schema_type' => ARRAY_A, ) ); } /** * Calculate honest shipping progress and the first eligible optional addition. */ public static function cart_context() { $context = array( 'shipping' => null, 'bump' => null, ); if ( ! WC()->cart ) { return $context; } $packages = WC()->cart->get_shipping_packages(); // Multi-package eligibility cannot be represented by one honest progress bar. if ( 1 === count( $packages ) ) { $zone = WC_Shipping_Zones::get_zone_matching_package( reset( $packages ) ); foreach ( $zone->get_shipping_methods( true ) as $method ) { if ( 'free_shipping' !== $method->id || 'min_amount' !== $method->get_option( 'requires' ) ) { continue; } $subtotal = WC()->cart->get_displayed_subtotal(); if ( 'no' === $method->get_option( 'ignore_discounts', 'no' ) ) { $subtotal -= WC()->cart->get_discount_total(); if ( WC()->cart->display_prices_including_tax() ) { $subtotal -= WC()->cart->get_discount_tax(); } } $minimum = (float) $method->get_option( 'min_amount', 0 ); if ( $minimum > 0 && ( null === $context['shipping'] || $minimum < $context['shipping']['minimum'] ) ) { $context['shipping'] = array( 'minimum' => $minimum, 'subtotal' => max( 0, (float) $subtotal ), ); } } } $in_cart = array_column( WC()->cart->get_cart(), 'product_id' ); foreach ( WC()->cart->get_cart() as $item ) { $source = wc_get_product( $item['product_id'] ); $bump = $source ? wc_get_product( absint( $source->get_meta( '_objeka_bump_id' ) ) ) : false; if ( $bump && $bump->is_type( 'simple' ) && $bump->is_purchasable() && $bump->is_in_stock() && ! in_array( $bump->get_id(), $in_cart, true ) ) { $context['bump'] = array( 'id' => $bump->get_id(), 'name' => $bump->get_name(), 'price' => (float) wc_get_price_to_display( $bump ), ); break; } } return $context; } }