>
>
0 ) { return $per_page; } return $product_number; } } if ( ! function_exists( 'ayyash_wc_hide_page_title' ) ) { /** * Show Title * * @return bool */ function ayyash_wc_hide_page_title() { return ayyash_get_mod( 'woocommerce_shop_archive_title' ) == 1; } } if ( ! function_exists( 'ayyash_remove_wc_breadcrumbs' ) ) { /** * Remove Shop Page Breadcrumbs as we have default * * @return void */ function ayyash_remove_wc_breadcrumbs() { remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 ); } } if ( ! function_exists( 'ayyash_wc_remove_result_count' ) ) { /** * Remove Shop Filter * * @return void */ function ayyash_wc_remove_result_count() { if ( ayyash_get_mod( 'woocommerce_shop_archive_result_count' ) == 0 ) { remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); } else { add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); } } } if ( ! function_exists( 'ayyash_wc_remove_archive_short' ) ) { /** * Remove Shop Page Filter * * @return void */ function ayyash_wc_remove_archive_short() { if ( ayyash_get_mod( 'woocommerce_shop_archive_sort' ) == 0 ) { remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); } else { add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); } } } if ( ! function_exists( 'ayyash_shop_header_open' ) ) { /** * Ayyash Shop header open * * @return void */ function ayyash_shop_header_open() { echo '
'; } } if ( ! function_exists( 'ayyash_get_product_discount' ) ) { /** * Display Product Discount Tag. * * @param int $product_id Product ID. * @param int $precision Numeric round precision. * * @return void */ function ayyash_get_product_discount( $product_id = null, $precision = 0 ) { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_discount' ) ) { return; } $product_id = ! $product_id ? get_the_ID() : $product_id; $product = wc_get_product( $product_id ); $discount = 0; if ( $product instanceof WC_Product ) { $sale_price = $product->get_sale_price(); $regular_price = $product->get_regular_price(); if ( ! empty( $sale_price ) && $regular_price > $sale_price ) { $discount = ( ( (float) $regular_price - (float) $sale_price ) / (float) $regular_price ) * 100; $discount = round( $discount, $precision ); } } if ( class_exists( 'Ayyash_Pro' ) ) { $product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type'); } else { $product_label_type = ''; } if ( $discount > 0 ) { printf( '%2$s%% OFF', esc_attr( $product_label_type ? $product_label_type : 'fill' ), (float) $discount ); } } } if ( ! function_exists( 'ayyash_get_featured_badge' ) ) { /** * Display Product Discount Tag. * * @param int $product_id Product ID. * * @return void */ function ayyash_get_featured_badge( $product_id = null ) { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_featured' ) ) { return; } $product_id = ! $product_id ? get_the_ID() : $product_id; $product = wc_get_product( $product_id ); $is_featured = false; if ( $product instanceof WC_Product ) { $is_featured = $product->is_featured(); } if ( class_exists( 'Ayyash_Pro' ) ) { $product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type'); } else { $product_label_type = ''; } if ( $is_featured ) { printf( 'Featured', esc_attr( $product_label_type ? $product_label_type : 'fill' ) ); } } } if ( ! function_exists( 'ayyash_get_product_badge' ) ) { /** * Get product badge. * * @param int $product_id Product ID. * @param array $check check. * * @return void */ function ayyash_get_product_badge( $product_id = null, $check = array() ) { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_product_badge' ) ) { return; } $product_id = ! $product_id ? get_the_ID() : $product_id; $product = wc_get_product( $product_id ); $check = array( 'hot', 'sale' ); // @TODO check generating badge from product tag is necessary. if ( ! $product ) { return; } $product_tags = array_map( function ( $tag_id ) use ( $check ) { $term = get_term_by( 'id', $tag_id, 'product_tag' ); // @phpstan-ignore-next-line if ( ! $term || is_wp_error( $term ) ) { return null; } /** * @var WP_Term $term */ if ( ! empty( $check ) && ! in_array( $term->slug, $check ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict return null; } if ( class_exists( 'Ayyash_Pro' ) ) { $product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type'); } else { $product_label_type = ''; } return sprintf( '%s', esc_attr( $term->slug ), esc_attr( $product_label_type ? $product_label_type : 'fill' ), esc_html( $term->name ) ); }, $product->get_tag_ids() ); $product_tags = array_filter( $product_tags ); if ( ! empty( $product_tags ) ) { echo implode( '', $product_tags ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } } if ( ! function_exists( 'ayyash_shop_labels' ) ) { /** * Shop labels * * @return void */ function ayyash_shop_labels() { $product_label_style = ayyash_get_mod( 'woocommerce_shop_archive_label_style' ); ?>
false, 'auto_size' => true, ] ); ?>
'; } } if ( ! function_exists( 'ayyash_shop_content_open' ) ) { function ayyash_shop_content_open() { /** * Shop content open */ echo '
'; } } if ( ! function_exists( 'ayyash_shop_category' ) ) { /** * Shop category * * @return void */ function ayyash_shop_category() { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_product_category' ) ) { return; } global $product; $terms = get_the_terms( $product->get_id(), 'product_cat' ); if ( ! empty( $terms ) ) { echo '
    '; foreach ( $terms as $_term ) { $term_link = get_term_link( $_term ); if ( ! $term_link || is_wp_error( $term_link ) ) { continue; } echo '
  • ' . esc_html( $_term->name ) . '
  • '; } echo '
'; } } } if ( ! function_exists( 'ayyash_shop_title' ) ) { /** * Shop title * * @return void */ function ayyash_shop_title() { if ( ! empty( get_the_title() ) ) { sprintf('

%s

', esc_url( get_the_permalink() ), esc_html( the_title() ) ); } } } if ( ! function_exists( 'ayyash_shop_price' ) ) { /** * Shop price * * @return void */ function ayyash_shop_price() { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_product_price' ) ) { return; } global $product; ?>
get_price_html() ); ?>
get_average_rating() ) ) { ?>
get_average_rating() ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( 1 === (int) get_theme_mod( 'woocommerce_shop_archive_show_product_rating_count' ) ) { echo sprintf('(%d)', esc_html( $product->get_rating_count() ) ); } ?>
'; } } if ( ! function_exists( 'ayyash_product_footer_classes' ) ) { /** * Shop footer classes * * @return string */ function ayyash_product_footer_classes() { $classes[] = 'product-footer'; $classes = apply_filters( 'ayyash_product_footer_classes', $classes ); $classes = array_unique( array_filter( $classes ) ); return implode(' ', $classes); } } if ( ! function_exists( 'ayyash_shop_footer_open' ) ) { /** * Shop footer open * * @return void */ function ayyash_shop_footer_open() { echo '
'; } } if ( ! function_exists( 'ayyash_shop_footer_cart_wishlist_btn' ) ) { /** * Check if cart or wishlist button exist in footer * * @return string */ function ayyash_shop_footer_cart_wishlist_btn( $classes ) { // Check if wishlist button is available in product footer if ( 'before_image' !== get_option( 'yith_wcwl_loop_position' ) && defined( 'YITH_WCWL' ) && 'yes' === get_option( 'yith_wcwl_show_on_loop' ) ) { $classes[] = 'footer-wishlist-btn'; } // Check if cart button available in product footer @TODO //$cart_btn_position = get_theme_mod( 'woocommerce_shop_archive_btn_position' ); //if ( 'in-footer' === $cart_btn_position ) { $classes[] = 'footer-cart-btn'; //} return $classes; } } if ( ! function_exists( 'ayyash_shop_cart_btn' ) ) { function ayyash_shop_cart_btn() { ?>
'; } } if ( ! function_exists( 'ayyash_mini_cart' ) ) : /** * If theme option have enable search it will show search after menu item. * * @param string $items The HTML list content for the menu items. * @param stdClass $args An object containing wp_nav_menu() arguments. * * @return string */ function ayyash_mini_cart() { if ( ayyash_get_mod( 'layout_header_show_mini_cart' ) ) { ?>
cart->get_cart_contents_count() ); ?>
' . WC()->cart->get_cart_contents_count() . ''; return $fragments; } } if ( ! function_exists( 'ayyash_mini_cart_fragments' ) ) { /** * Ensure cart contents update when products are added to the cart via AJAX * * @param $fragments * * @return mixed */ function ayyash_mini_cart_fragments( $fragments ) { $fragments['.ayyash-header-cart-count .badge'] = '' . esc_html( WC()->cart->get_cart_contents_count() ) . ''; return $fragments; } } if ( ! function_exists( 'ayyash_wc_change_number_related_products' ) ) { /** * WC UpSell display args. * * @param array $args Args. * * @return array */ function ayyash_wc_upsell_display_args( $args ) { if ( is_product() ) { $args['posts_per_page'] = ayyash_get_mod( 'woocommerce_single_upsells_count' ); } elseif ( is_cart() ) { $args['posts_per_page'] = ayyash_get_mod( 'woocommerce_cart_upsells_count' ); } else { $args['posts_per_page'] = 2; } return $args; } } if ( ! function_exists( 'ayyash_wc_related_products_limit' ) ) { /** * Related product limit. * * @return array */ function ayyash_wc_related_products_limit() { if ( is_product() ) { $args['posts_per_page'] = ayyash_get_mod( 'woocommerce_single_related_item_count' ); } else { $args['posts_per_page'] = 4; } return $args; } } if ( ! function_exists( 'ayyash_cart_cross_sell_total' ) ) { /** * Cross Sell Count * * @return int */ function ayyash_cart_cross_sell_total() { return absint( ayyash_get_mod( 'woocommerce_cart_cross_sell_count' ) ); } } if ( ! function_exists( 'ayyash_stock_catalog' ) ) { /** * Show product is in stock or out of stock. * * @return void */ function ayyash_stock_catalog() { global $product; if ( $product->is_in_stock() ) { /* translators: %s: Stock Quantity */ echo ' ' . sprintf( esc_html__( '%s in stock', 'ayyash' ), esc_html( $product->get_stock_quantity() ) ) . ''; } else { /* translators: %s: Stock Quantity */ echo ' ' . esc_html__( 'out of stock', 'ayyash' ) . ''; } } } if ( ! function_exists( 'ayyash_woocommerce_new_badge' ) ) { /** * Show badge new if product is new. * * @return void */ function ayyash_woocommerce_new_badge() { global $product; $postdate = get_the_time( 'Y-m-d', $product->get_id() ); // Post date. if ( $postdate ) { // @phpstan-ignore-next-line $postdate = strtotime( $postdate ); // Timestamped post date. $newness = 10; // Newness in days as defined by option. if ( ( time() - ( 60 * 60 * 24 * $newness ) ) < $postdate ) { // If the product was published within the newness time frame display the new badge. echo '
' . esc_html__( 'New', 'ayyash' ) . '
'; } } } } if ( ! function_exists( 'ayyash_sale_countdown_timer' ) ) { /** * Sale Countdown timer * * @return void */ function ayyash_sale_countdown_timer() { global $product; $sale_date = $product->get_date_on_sale_to(); if ( ! $sale_date ) { return; } echo '
'; } } if ( ! function_exists( 'ayyash_display_sold_out_loop_woocommerce' ) ) { /** * Sold_out hook added * * @return void */ function ayyash_display_sold_out_loop_woocommerce() { if ( 1 !== (int) get_theme_mod( 'woocommerce_shop_archive_show_stock' ) && is_shop() ) { return; } global $product; if ( class_exists( 'Ayyash_Pro' ) ) { $product_label_type = ayyash_get_mod('woocommerce_shop_archive_label_type'); } else { $product_label_type = ''; } if ( ! $product->is_in_stock() ) { printf( '%s', esc_attr( $product_label_type ? $product_label_type : 'fill' ), esc_html__( 'Out Of Stock', 'ayyash' ) ); } } } if ( ! function_exists( 'ayyash_filter_product_rating_html' ) ) { /** * Filter Product rating * * @param string $rating_html rating html. * * @return string */ function ayyash_filter_product_rating_html( $rating_html ) { global $ayyash_products; if ( ! $ayyash_products ) { return $rating_html; } if ( isset( $ayyash_products['display_rating'] ) && 'yes' == $ayyash_products['display_rating'] ) { return $rating_html; } return ''; } } if ( ! function_exists( 'ayyash_change_number_related_products' ) ) { /** * Related Product Column Limit * * @param array $args * * @return array */ function ayyash_change_number_related_products( $args ) { $args['columns'] = absint( ayyash_get_mod( 'woocommerce_single_related_product_column' ) ); // # of columns per row return $args; } } if ( ! function_exists( 'ayyash_wc_gallery_thumb_size' ) ) { /** * Product Gallery Thumb Image Size Resizing. * * @return array */ function ayyash_wc_gallery_thumb_size() { return array( 'width' => 100, 'height' => 100, 'crop' => 0, ); } } if ( ! function_exists( 'ayyash_variation_radio_buttons' ) ) { /** * Product Attribute Radio buttons * * @param string $html Data. * @param array $args Arguments. * * @return string */ function ayyash_variation_radio_buttons( $html, $args ) { $args = wp_parse_args( $args, [ 'options' => false, 'attribute' => false, 'product' => false, 'selected' => false, 'name' => '', 'id' => '', 'class' => '', 'show_option_none' => __( 'Choose an option', 'ayyash' ), ] ); /** * @var WC_Product_Variable $product */ $product = $args['product']; $options = $args['options']; $attribute = $args['attribute']; $name = ! $args['name'] ? 'attribute_' . sanitize_title( $attribute ) : $args['name']; if ( false === $args['selected'] && $args['attribute'] && $args['product'] instanceof WC_Product ) { $selected_key = 'attribute_' . sanitize_title( $args['attribute'] ); $selected = isset( $_REQUEST[ $selected_key ] ) ? wc_clean( wp_unslash( $_REQUEST[ $selected_key ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $args['selected'] = ! $selected ? $product->get_variation_default_attribute( $args['attribute'] ) : $selected; } if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) { //@phpstan-ignore-line $attributes = $product->get_variation_attributes(); $options = $attributes[ $attribute ]; } $radios = '
'; // Attribute label. $attrib_name = wc_attribute_label( $attribute, $product ); if ( ! empty( $options ) ) { if ( $product && taxonomy_exists( $attribute ) ) { //@phpstan-ignore-line $terms = wc_get_product_terms( $product->get_id(), $attribute, [ 'fields' => 'all' ] ); foreach ( $terms as $term ) { if ( in_array( $term->slug, $options, true ) ) { $id = $name . '-' . $term->slug; $opt_name = apply_filters( 'woocommerce_variation_option_name', $term->name ); $title = sprintf( /* translators: 1. attribute label, 2. attribute value. */ _x( '%1$s: %2$s', 'Product attribute option tooltip.', 'ayyash' ), $attrib_name, $opt_name ); $output = 'term_id, 'color', true ); $color = ! $color ? strtolower( $term->name ) : $color; $output .= 'style="background-color: ' . esc_attr( $color ) . '">'; $output .= 'swatch'; } else { $output .= '>' . esc_html( $term->name ); } $output .= ''; $radios .= 'slug, false ) . '>'; } } } else { foreach ( $options as $option ) { $id = $name . '-' . $option; $output = apply_filters( 'woocommerce_variation_option_name', $option ); $title = sprintf( /* translators: 1. attribute label, 2. attribute value. */ _x( '%1$s: %2$s', 'Product attribute option tooltip.', 'ayyash' ), $attrib_name, $output ); $output = '' . esc_html( $output ) . ''; $checked = sanitize_title( $args['selected'] ) === $args['selected'] ? checked( $args['selected'], sanitize_title( $option ), false ) : checked( $args['selected'], $option, false ); $radios .= ''; } } } $radios .= '
'; return $html . $radios; } } if ( ! function_exists( 'ayyash_variation_check' ) ) { /** * Check Product Variation. * * @param bool $active Activate. * @param WC_Product_Variation $variation Variation. * * @return bool */ function ayyash_variation_check( $active, $variation ) { if ( ! $variation->is_in_stock() && ! $variation->backorders_allowed() ) { return false; } return $active; } } if ( ! function_exists( 'ayyash_product_loop_start' ) ) { /** * WooCommerce loop start * * @return void */ function ayyash_product_loop_start() { echo sprintf( '
    ', esc_attr( ayyash_product_loop_classes() ) ); } } if ( ! function_exists( 'ayyash_product_loop_classes' ) ) { /** * Ayyash Cart Button Classes * * @return string */ function ayyash_product_loop_classes() { $classes[] = 'products ayyash-products columns-' . esc_attr( wc_get_loop_prop( 'columns' ) ); $classes = apply_filters( 'ayyash_product_loop_classes', $classes ); $classes = array_unique( array_filter( $classes ) ); return implode(' ', $classes); } } if ( ! function_exists( 'ayyash_product_classes' ) ) { /** * Ayyash Cart Button Classes * * @return string */ function ayyash_product_classes() { $classes[] = 'ayyash-product-item'; $classes[] = 'hover-grow-up'; $classes[] = 'hover-actions'; $classes[] = 'hover-button'; $classes[] = 'ayyash-cart-button'; $classes = apply_filters( 'ayyash_product_classes', $classes ); $classes = array_unique( array_filter( $classes ) ); return implode(' ', $classes); } } if ( ! function_exists( 'product_cat_item_class' ) ) { /** * Ayyash Product category item class * * @return string */ function product_cat_item_class( $classes ) { $classes[] = 'ayyash-product-item'; return $classes; } } if ( ! function_exists( 'ayyash_product_btn_classes' ) ) { /** * Ayyash Cart Button Classes * * @return string */ function ayyash_product_btn_classes() { $classes[] = 'ayyash-cart-button'; $classes = apply_filters( 'ayyash_product_btn_classes', $classes ); $classes = array_unique( array_filter( $classes ) ); return implode(' ', $classes); } } if ( ! function_exists( 'ayyash_single_product_actions' ) ) { /** * Product Actions * * @return void */ function ayyash_single_product_actions() { ?>

    '; if ( is_rtl() ) { return '' . esc_html__( ' Thank you. your order has been received.', 'ayyash' ) . '' . $icon; } else { return $icon . '' . esc_html__( ' Thank you. your order has been received.', 'ayyash' ) . ''; } } } if ( ! function_exists( 'woocommerce_download_button_label' ) ) { /** * Change Woocommerce Download Button label */ function woocommerce_download_button_label( $downloads ) { foreach ( $downloads as &$download ) { $download['download_name'] = __( 'Download', 'ayyash' ); } return $downloads; } } if ( ! function_exists( 'ayyash_before_single_product' ) ) { function ayyash_before_single_product() { echo '
    '; } } if ( ! function_exists( 'ayyash_single_product_thumbnail_after' ) ) { function ayyash_single_product_thumbnail_after() { echo '
    '; } } if ( ! function_exists( 'ayyash_after_single_product' ) ) { function ayyash_after_single_product() { echo '
    '; } } if ( ! function_exists( 'ayyash_single_product_content_after' ) ) { function ayyash_single_product_content_after() { echo '
'; } } if ( ! function_exists( 'ayyash_add_cart_link' ) ) { function ayyash_add_cart_link() { global $product; echo sprintf( ' %s', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ), esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ), isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', //phpcs:ignore esc_html( $product->add_to_cart_text() ) ); } } if ( ! function_exists( 'ayyash_cart_cross_sell_display' ) ) { /** * Remove woocommerce_cross_sell_display and display it after form * * @return void */ function ayyash_cart_cross_sell_display() { remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' ); add_action( 'ayyash_after_cart_form', 'woocommerce_cross_sell_display' ); } } // End of file ayyash-woocommerce-hook-helper.php