get_status() && ! Product_Settings::is_hidden( $product ) && self::can_buy( $product ); /** * Filters whether the bar shows on a product page. * * @param bool $show Whether to show it. * @param \WC_Product $product Product. */ return (bool) apply_filters( 'satcbar_show_for_product', $show, $product ); } /** * Whether shoppers can buy the product from its page right now. * * @param \WC_Product $product Product. * @return bool */ private static function can_buy( $product ) { if ( $product->is_type( 'external' ) ) { return '' !== (string) $product->get_product_url(); } if ( $product->is_type( 'grouped' ) ) { foreach ( $product->get_children() as $child_id ) { $child = wc_get_product( $child_id ); if ( $child && 'publish' === $child->get_status() && $child->is_purchasable() && $child->is_in_stock() ) { return true; } } return false; } return $product->is_purchasable() && $product->is_in_stock(); } /** * Loads the bar's CSS and JS (single product pages with a bar only). */ public static function assets() { $s = Settings::get(); wp_enqueue_style( 'satcbar', SATCBAR_URL . 'assets/css/bar.css', array(), SATCBAR_VERSION ); if ( $s['button_color'] ) { wp_add_inline_style( 'satcbar', '.satcbar{--satcbar-btn:' . $s['button_color'] . ';--satcbar-btn-text:' . Settings::text_color_for( $s['button_color'] ) . ';}' ); } wp_enqueue_script( 'satcbar', SATCBAR_URL . 'assets/js/bar.js', array(), SATCBAR_VERSION, array( 'in_footer' => true, 'strategy' => 'defer', ) ); /** * Fires after the bar's files are queued. Add-ons queue theirs here. * * @param \WC_Product $product Product. */ do_action( 'satcbar_enqueue_assets', self::$product ); } /** * Settings the bar's script needs. * * @param \WC_Product $product Product. * @return array */ public static function config( $product ) { $s = Settings::get(); $type = $product->get_type(); if ( ! in_array( $type, array( 'simple', 'variable', 'grouped', 'external' ), true ) ) { $type = 'other'; } $config = array( 'id' => $product->get_id(), 'type' => $type, 'trigger' => $s['trigger'], 'position' => $s['position'], 'text' => array( 'add' => self::button_text( $product ), 'choose' => __( 'Choose options', 'cartpin' ), 'chooseItems' => __( 'Choose items', 'cartpin' ), 'outOfStock' => __( 'Out of stock', 'cartpin' ), 'unavailable' => __( 'Unavailable', 'cartpin' ), ), /** * Filters fixed bars at the bottom of the screen that the sticky bar sits above (CSS selectors). * * @param string[] $selectors Selectors. */ 'avoid' => array_values( (array) apply_filters( 'satcbar_bottom_avoid', array( '.storefront-handheld-footer-bar' ) ) ), ); /** * Filters the settings passed to the bar's script. * * @param array $config Settings. * @param \WC_Product $product Product. */ return apply_filters( 'satcbar_bar_config', $config, $product ); } /** * Text on the bar's button. * * @param \WC_Product $product Product. * @return string */ public static function button_text( $product ) { $s = Settings::get(); if ( '' !== $s['button_text'] && ! $product->is_type( 'external' ) ) { return $s['button_text']; } return wp_strip_all_tags( $product->single_add_to_cart_text() ); } /** * CSS classes of the bar. * * @param array $s Settings. * @return string[] */ public static function classes( array $s ) { $classes = array( 'satcbar', 'satcbar--' . $s['position'], 'satcbar--' . $s['style'] ); if ( ! $s['desktop'] ) { $classes[] = 'satcbar--no-desktop'; } if ( ! $s['mobile'] ) { $classes[] = 'satcbar--no-mobile'; } $classes[] = $s['button_color'] ? 'satcbar--own-button' : 'satcbar--theme-button'; /** * Filters the bar's CSS classes. * * @param string[] $classes Classes. * @param array $s Settings. */ return array_map( 'sanitize_html_class', (array) apply_filters( 'satcbar_bar_classes', $classes, $s ) ); } /** * Prints the bar (hidden until the shopper scrolls past the real button). */ public static function render() { $product = self::$product; if ( ! $product ) { return; } $s = Settings::get(); $show_qty = $s['show_qty'] && in_array( $product->get_type(), array( 'simple', 'variable' ), true ) && ! $product->is_sold_individually(); $image_id = $product->get_image_id(); $btn_class = $s['button_color'] ? 'satcbar__button' : 'satcbar__button button alt wp-element-button'; $min = max( 1, (int) $product->get_min_purchase_quantity() ); $max = (int) $product->get_max_purchase_quantity(); ?>