array(), ); } public function enqueue_front() { if ( ! is_product() ) { return; } global $product; $product_id = 0; if ( $product instanceof WC_Product ) { $product_id = $product->get_id(); } elseif ( get_the_ID() ) { $product_id = (int) get_the_ID(); } wp_enqueue_style( 'sclt-front', SCLT_PLUGIN_URL . 'assets/admin.css', array(), SCLT_VERSION ); wp_enqueue_style( 'sclt-options', SCLT_PLUGIN_URL . 'assets/options.css', array(), SCLT_VERSION ); // Live price preview for options pricing. $pricing_fields = $product_id ? SCLT_Product_Options::pricing_config_for_product( $product_id ) : array(); $qty_tiers = ( $product_id && class_exists( 'SCLT_Qty_Tiers' ) ) ? SCLT_Qty_Tiers::live_price_config( $product_id ) : array(); $tier_product = ( $qty_tiers && ! $pricing_fields ) ? wc_get_product( $product_id ) : null; if ( $tier_product && $tier_product->is_type( 'variable' ) ) { // The preview only knows one base price, so it would show a wrong figure for a // variable product. The tier table on the page still lists the discounts. $qty_tiers = array(); } if ( $pricing_fields || $qty_tiers ) { $wc_product = $product_id ? wc_get_product( $product_id ) : null; $base = $wc_product ? (float) $wc_product->get_price() : 0.0; wp_enqueue_script( 'sclt-live-price', SCLT_PLUGIN_URL . 'assets/live-price.js', array(), SCLT_VERSION, true ); wp_localize_script( 'sclt-live-price', 'scltLivePrice', array( 'productId' => $product_id, 'basePrice' => $base, 'fields' => $pricing_fields, 'tiers' => $qty_tiers, 'symbol' => get_woocommerce_currency_symbol(), 'currencyPos' => get_option( 'woocommerce_currency_pos', 'left' ), 'decimals' => wc_get_price_decimals(), 'i18n' => array( 'base' => __( 'Base', 'storecanvas-lite' ), 'extras' => __( 'options', 'storecanvas-lite' ), 'line' => __( 'line', 'storecanvas-lite' ), 'tier' => __( 'quantity discount', 'storecanvas-lite' ), ), ) ); } } public function enqueue_admin( $hook ) { global $post; $on_group_screen = is_string( $hook ) && false !== strpos( $hook, self::CPT_OPTION_GROUP ); $on_product = in_array( $hook, array( 'post.php', 'post-new.php' ), true ) && $post && 'product' === get_post_type( $post ); if ( ! $on_group_screen && ! $on_product ) { return; } wp_enqueue_style( 'sclt-admin', SCLT_PLUGIN_URL . 'assets/admin.css', array(), SCLT_VERSION ); if ( ! $on_product ) { return; } wp_enqueue_script( 'sclt-admin', SCLT_PLUGIN_URL . 'assets/admin.js', array( 'jquery' ), SCLT_VERSION, true ); wp_add_inline_script( 'sclt-admin', 'window.scltBuilderTypes = ' . wp_json_encode( array( 'fields' => SCLT_Product_Options::field_types(), 'prices' => SCLT_Product_Options::price_types(), ) ) . ';', 'before' ); } }