plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. */ public function enqueue_styles() { // Only enqueue on WooCommerce pages. if ( ! is_woocommerce() && ! is_product() && ! is_shop() && ! is_cart() ) { return; } wp_enqueue_style( $this->plugin_name, DP_AICOSO_PLUGIN_URL . 'public/css/dp-aicoso-public.css', array(), $this->version, 'all' ); // Enqueue product price styles on product pages. if ( is_product() ) { wp_enqueue_style( $this->plugin_name . '-product-price', DP_AICOSO_PLUGIN_URL . 'assets/css/product-price.css', array(), $this->version, 'all' ); } } /** * Register the JavaScript for the public-facing side of the site. */ public function enqueue_scripts() { // Only enqueue on WooCommerce pages. if ( ! is_woocommerce() && ! is_product() && ! is_shop() && ! is_cart() ) { return; } wp_enqueue_script( $this->plugin_name, DP_AICOSO_PLUGIN_URL . 'public/js/dp-aicoso-public.js', array( 'jquery' ), $this->version, true ); // Localize script. wp_localize_script( $this->plugin_name, 'dp_aicoso_public', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'dp_aicoso_public' ), ) ); // Enqueue Blocks cart fix on cart pages. if ( is_cart() ) { wp_enqueue_script( $this->plugin_name . '-blocks-cart', DP_AICOSO_PLUGIN_URL . 'assets/js/blocks-cart-fix.js', array( 'wp-data', 'wp-element' ), $this->version, true ); } // Enqueue product price update script on single product pages. if ( is_product() ) { wp_enqueue_script( $this->plugin_name . '-product-price', DP_AICOSO_PLUGIN_URL . 'assets/js/product-price-force-update.js', array( 'jquery' ), time(), // Use time() for cache busting during development. true ); // Also localize for this script. wp_localize_script( $this->plugin_name . '-product-price', 'dp_aicoso_public', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'dp_aicoso_public' ), 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, ) ); } } /** * Modify product price based on dynamic pricing rules. * * @param float $price The original price. * @param WC_Product $product The product object. * @return float The modified price. */ public function modify_product_price( $price, $product ) { // Skip if in admin and not doing AJAX. if ( is_admin() && ! wp_doing_ajax() ) { return $price; } // Skip if no price. if ( empty( $price ) ) { return $price; } // Get current user. $user = wp_get_current_user(); // For now, return the original price. // Full implementation will query rules and calculate dynamic price. return $price; } /** * Apply dynamic pricing to cart items. * * @param WC_Cart $cart The cart object. */ public function apply_cart_pricing( $cart ) { // Skip if cart is empty. if ( $cart->is_empty() ) { return; } // Skip in admin. if ( is_admin() && ! wp_doing_ajax() ) { return; } // Get price calculator instance. $calculator = DP_AICOSO_Price_Calculator::get_instance(); // Iterate through cart items. foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { $product = $cart_item['data']; $quantity = $cart_item['quantity']; // Calculate dynamic price based on quantity and rules. $original_price = $product->get_price(); $new_price = $calculator->calculate_price( $product, $quantity ); // If price changed, update the product price. if ( false !== $new_price && $original_price != $new_price ) { $product->set_price( $new_price ); } } } /** * Display bulk pricing table on product page. */ public function display_bulk_pricing_table() { global $product; // Check if product exists. if ( ! $product ) { return; } // Check if bulk pricing is enabled. $settings = get_option( 'dp_aicoso_settings', array() ); if ( empty( $settings['show_bulk_table'] ) ) { return; } // For now, display a placeholder. // Full implementation will query rules and display pricing table. ?>