%1$s

%2$s

%4$s ', esc_html( $block_template->title ), __( 'This page is blank because the template is empty. You can reset or customize it in the Site Editor.' ), get_edit_post_link( $block_template->wp_id, 'site-editor' ), __( 'Edit template' ) ); } /** * Finds a block template with equal or higher specificity than a given PHP template file. * * Internally, this communicates the block content that needs to be used by the template canvas through a global variable. * * @since 5.8.0 * @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar. * * @global string $_wp_current_template_content * @global string $_wp_current_template_id * * @param string $template Path to the template. See locate_template(). * @param string $type Sanitized filename without extension. * @param string[] $templates A list of template candidates, in descending order of priority. * @return string The path to the Site Editor template canvas file, or the fallback PHP template. */ function locate_block_template( $template, $type, array $templates ) { global $_wp_current_template_content, $_wp_current_template_id; if ( ! current_theme_supports( 'block-templates' ) ) { return $template; } if ( $template ) { /* * locate_template() has found a PHP template at the path specified by $template. * That means that we have a fallback candidate if we cannot find a block template * with higher specificity. * * Thus, before looking for matching block themes, we shorten our list of candidate * templates accordingly. */ // Locate the index of $template (without the theme directory path) in $templates. $relative_template_path = str_replace( array( get_stylesheet_directory() . '/', get_template_directory() . '/' ), '', $template ); $index = array_search( $relative_template_path, $templates, true ); // If the template hierarchy algorithm has successfully located a PHP template file, // we will only consider block templates with higher or equal specificity. $templates = array_slice( $templates, 0, $index + 1 ); } $block_template = resolve_block_template( $type, $templates, $template ); if ( $block_template ) { $_wp_current_template_id = $block_template->id; if ( empty( $block_template->content ) ) { if ( is_user_logged_in() ) { $_wp_current_template_content = wp_render_empty_block_template_warning( $block_template ); } else { if ( $block_template->has_theme_file ) { // Show contents from theme template if user is not logged in. $theme_template = _get_block_template_file( 'wp_template', $block_template->slug ); $_wp_current_template_content = file_get_contents( $theme_template['path'] ); } else { $_wp_current_template_content = $block_template->content; } } } elseif ( ! empty( $block_template->content ) ) { $_wp_current_template_content = $block_template->content; } if ( isset( $_GET['_wp-find-template'] ) ) { wp_send_json_success( $block_template ); } } else { if ( $template ) { return $template; } if ( 'index' === $type ) { if ( isset( $_GET['_wp-find-template'] ) ) { wp_send_json_error( array( 'message' => __( 'No matching template found.' ) ) ); } } else { return ''; // So that the template loader keeps looking for templates. } } // Add hooks for template canvas. // Add viewport meta tag. add_action( 'wp_head', '_block_template_viewport_meta_tag', 0 ); // Render title tag with content, regardless of whether theme has title-tag support. remove_action( 'wp_head', '_wp_render_title_tag', 1 ); // Remove conditional title tag rendering... add_action( 'wp_head', '_block_template_render_title_tag', 1 ); // ...and make it unconditional. // This file will be included instead of the theme's template file. return ABSPATH . WPINC . '/template-canvas.php'; } /** * Returns the correct 'wp_template' to render for the request template type. * * @access private * @since 5.8.0 * @since 5.9.0 Added the `$fallback_template` parameter. * * @param string $template_type The current template type. * @param string[] $template_hierarchy The current template hierarchy, ordered by priority. * @param string $fallback_template A PHP fallback template to use if no matching block template is found. * @return WP_Block_Template|null template A template object, or null if none could be found. */ function resolve_block_template( $template_type, $template_hierarchy, $fallback_template ) { if ( ! $template_type ) { return null; } if ( empty( $template_hierarchy ) ) { $template_hierarchy = array( $template_type ); } $slugs = array_map( '_strip_template_file_suffix', $template_hierarchy ); // Find all potential templates 'wp_template' post matching the hierarchy. $query = array( 'slug__in' => $slugs, ); $templates = get_block_templates( $query ); // Order these templates per slug priority. // Build map of template slugs to their priority in the current hierarchy. $slug_priorities = array_flip( $slugs ); usort( $templates, static function ( $template_a, $template_b ) use ( $slug_priorities ) { return $slug_priorities[ $template_a->slug ] - $slug_priorities[ $template_b->slug ]; } ); $theme_base_path = get_stylesheet_directory() . DIRECTORY_SEPARATOR; $parent_theme_base_path = get_template_directory() . DIRECTORY_SEPARATOR; // Is the active theme a child theme, and is the PHP fallback template part of it? if ( str_starts_with( $fallback_template, $theme_base_path ) && ! str_contains( $fallback_template, $parent_theme_base_path ) ) { $fallback_template_slug = substr( $fallback_template, // Starting position of slug. strpos( $fallback_template, $theme_base_path ) + strlen( $theme_base_path ), // Remove '.php' suffix. -4 ); // Is our candidate block template's slug identical to our PHP fallback template's? if ( count( $templates ) && $fallback_template_slug === $templates[0]->slug && 'theme' === $templates[0]->source ) { // Unfortunately, we cannot trust $templates[0]->theme, since it will always // be set to the active theme's slug by _build_block_template_result_from_file(), // even if the block template is really coming from the active theme's parent. // (The reason for this is that we want it to be associated with the active theme // -- not its parent -- once we edit it and store it to the DB as a wp_template CPT.) // Instead, we use _get_block_template_file() to locate the block template file. $template_file = _get_block_template_file( 'wp_template', $fallback_template_slug ); if ( $template_file && get_template() === $template_file['theme'] ) { // The block template is part of the parent theme, so we // have to give precedence to the child theme's PHP template. array_shift( $templates ); } } } return count( $templates ) ? $templates[0] : null; } /** * Displays title tag with content, regardless of whether theme has title-tag support. * * @access private * @since 5.8.0 * * @see _wp_render_title_tag() */ function _block_template_render_title_tag() { echo '' . wp_get_document_title() . '' . "\n"; } /** * Returns the markup for the current template. * * @access private * @since 5.8.0 * * @global string $_wp_current_template_id * @global string $_wp_current_template_content * @global WP_Embed $wp_embed WordPress Embed object. * @global WP_Query $wp_query WordPress Query object. * * @return string Block template markup. */ function get_the_block_template_html() { global $_wp_current_template_id, $_wp_current_template_content, $wp_embed, $wp_query; if ( ! $_wp_current_template_content ) { if ( is_user_logged_in() ) { return '

' . esc_html__( 'No matching template found' ) . '

'; } return ''; } $content = $wp_embed->run_shortcode( $_wp_current_template_content ); $content = $wp_embed->autoembed( $content ); $content = shortcode_unautop( $content ); $content = do_shortcode( $content ); /* * Most block themes omit the `core/query` and `core/post-template` blocks in their singular content templates. * While this technically still works since singular content templates are always for only one post, it results in * the main query loop never being entered which causes bugs in core and the plugin ecosystem. * * The workaround below ensures that the loop is started even for those singular templates. The while loop will by * definition only go through a single iteration, i.e. `do_blocks()` is only called once. Additional safeguard * checks are included to ensure the main query loop has not been tampered with and really only encompasses a * single post. * * Even if the block template contained a `core/query` and `core/post-template` block referencing the main query * loop, it would not cause errors since it would use a cloned instance and go through the same loop of a single * post, within the actual main query loop. * * This special logic should be skipped if the current template does not come from the current theme, in which case * it has been injected by a plugin by hijacking the block template loader mechanism. In that case, entirely custom * logic may be applied which is unpredictable and therefore safer to omit this special handling on. */ if ( $_wp_current_template_id && str_starts_with( $_wp_current_template_id, get_stylesheet() . '//' ) && is_singular() && 1 === $wp_query->post_count && have_posts() ) { while ( have_posts() ) { the_post(); $content = do_blocks( $content ); } } else { $content = do_blocks( $content ); } $content = wptexturize( $content ); $content = convert_smilies( $content ); $content = wp_filter_content_tags( $content, 'template' ); $content = str_replace( ']]>', ']]>', $content ); // Wrap block template in .wp-site-blocks to allow for specific descendant styles // (e.g. `.wp-site-blocks > *`). return '
' . $content . '
'; } /** * Renders a 'viewport' meta tag. * * This is hooked into {@see 'wp_head'} to decouple its output from the default template canvas. * * @access private * @since 5.8.0 */ function _block_template_viewport_meta_tag() { echo '' . "\n"; } /** * Strips .php or .html suffix from template file names. * * @access private * @since 5.8.0 * * @param string $template_file Template file name. * @return string Template file name without extension. */ function _strip_template_file_suffix( $template_file ) { return preg_replace( '/\.(php|html)$/', '', $template_file ); } /** * Removes post details from block context when rendering a block template. * * @access private * @since 5.8.0 * * @param array $context Default context. * * @return array Filtered context. */ function _block_template_render_without_post_block_context( $context ) { /* * When loading a template directly and not through a page that resolves it, * the top-level post ID and type context get set to that of the template. * Templates are just the structure of a site, and they should not be available * as post context because blocks like Post Content would recurse infinitely. */ if ( isset( $context['postType'] ) && 'wp_template' === $context['postType'] ) { unset( $context['postId'] ); unset( $context['postType'] ); } return $context; } /** * Sets the current WP_Query to return auto-draft posts. * * The auto-draft status indicates a new post, so allow the the WP_Query instance to * return an auto-draft post for template resolution when editing a new post. * * @access private * @since 5.9.0 * * @param WP_Query $wp_query Current WP_Query instance, passed by reference. */ function _resolve_template_for_new_post( $wp_query ) { if ( ! $wp_query->is_main_query() ) { return; } remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' ); // Pages. $page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null; // Posts, including custom post types. $p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null; $post_id = $page_id ? $page_id : $p; $post = get_post( $post_id ); if ( $post && 'auto-draft' === $post->post_status && current_user_can( 'edit_post', $post->ID ) ) { $wp_query->set( 'post_status', 'auto-draft' ); } } /** * Register a block template. * * @since 6.7.0 * * @param string $template_name Template name in the form of `plugin_uri//template_name`. * @param array|string $args { * @type string $title Optional. Title of the template as it will be shown in the Site Editor * and other UI elements. * @type string $description Optional. Description of the template as it wiget_items( 'line_item' ) as $item ) { $product_id = $item['product_id']; if ( get_wallet_rechargeable_product()->get_id() === $product_id ) { $is_wallet_rechargeable_order = true; break; } } } return apply_filters( 'woo_wallet_is_wallet_rechargeable_order', $is_wallet_rechargeable_order, $order ); } } if ( ! function_exists( 'is_wallet_rechargeable_cart' ) ) { /** * Check if cart contains rechargeable product * * @return boolean */ function is_wallet_rechargeable_cart() { $is_wallet_rechargeable_cart = false; if ( did_action( 'wp_loaded' ) && ! is_null( wc()->cart ) && count( wc()->cart->get_cart() ) > 0 && get_wallet_rechargeable_product() ) { foreach ( wc()->cart->get_cart() as $key => $cart_item ) { if ( get_wallet_rechargeable_product()->get_id() === $cart_item['product_id'] ) { $is_wallet_rechargeable_cart = true; break; } } } return apply_filters( 'woo_wallet_is_wallet_rechargeable_cart', $is_wallet_rechargeable_cart ); } } if ( ! function_exists( 'get_woowallet_coupon_cashback_amount' ) ) { /** * Get coupon cash-back amount from cart. * * @return Float */ function get_woowallet_coupon_cashback_amount() { $coupon_cashback_amount = 0; foreach ( WC()->cart->get_applied_coupons() as $code ) { $coupon = new WC_Coupon( $code ); $_is_coupon_cashback = get_post_meta( $coupon->get_id(), '_is_coupon_cashback', true ); if ( 'yes' === $_is_coupon_cashback ) { $coupon_cashback_amount += WC()->cart->get_coupon_discount_amount( $code, WC()->cart->display_cart_ex_tax ); } } return $coupon_cashback_amount; } } if ( ! function_exists( 'get_woo_wallet_cart_fee_total' ) ) { /** * Get total fee amount from cart. * * @return float */ function get_woo_wallet_cart_fee_total() { $fee_amount = 0; $fees = wc()->cart->get_fees(); if ( $fees ) { foreach ( $fees as $fee_key => $fee ) { if ( '_via_wallet_partial_payment' !== $fee_key ) { $fee_amount += $fee->amount; } } } return $fee_amount; } } if ( ! function_exists( 'get_woowallet_cart_total' ) ) { /** * Get WooCommerce cart total. * * @return float */ function get_woowallet_cart_total() { $cart_total = 0; if ( ! is_admin() && is_array( wc()->cart->cart_contents ) && count( wc()->cart->cart_contents ) > 0 ) { $cart_total = wc()->cart->get_subtotal( 'edit' ) + wc()->cart->get_taxes_total() + wc()->cart->get_shipping_total( 'edit' ) - wc()->cart->get_discount_total() + get_woowallet_coupon_cashback_amount() + get_woo_wallet_cart_fee_total(); } return apply_filters( 'woowallet_cart_total', $cart_total ); } } if ( ! function_exists( 'is_enable_wallet_partial_payment' ) ) { /** * Check if enable partial payment. * * @return Boolean */ function is_enable_wallet_partial_payment() { $is_enable = false; $cart_total = get_woowallet_cart_total(); if ( ! is_wallet_rechargeable_cart() && is_user_logged_in() && ( ( ! is_null( wc()->session ) && wc()->session->get( 'partial_payment_amount', false ) ) || 'on' === woo_wallet()->settings_api->get_option( 'is_auto_deduct_for_partial_payment', '_wallet_settings_general' ) ) && $cart_total >= apply_filters( 'woo_wallet_partial_payment_amount', woo_wallet()->wallet->get_wallet_balance( get_current_user_id(), 'edit' ) ) ) { $is_enable = true; } return apply_filters( 'is_enable_wallet_partial_payment', $is_enable ); } } if ( ! function_exists( 'is_partial_payment_order_item' ) ) { /** * Check if order item is partial payment instance. * * @param Int $item_id item_id. * @param WC_Order_Item_Fee $item item. * @return boolean */ function is_partial_payment_order_item( $item_id, $item ) { if ( get_metadata( 'order_item', $item_id, '_legacy_fee_key', true ) && '_via_wallet_partial_payment' === get_metadata( 'order_item', $item_id, '_legacy_fee_key', true ) ) { return true; } elseif ( 'via_wallet' === strtolower( str_replace( ' ', '_', $item->get_name( 'edit' ) ) ) ) { return true; } return false; } } if ( ! function_exists( 'get_order_partial_payment_amount' ) ) { /** * Get total partial payment amount from an order. * * @param Int $order_id order_id. * @return Number */ function get_order_partial_payment_amount( $order_id ) { $via_wallet = 0; $order = wc_get_order( $order_id ); if ( $order ) { $line_items_fee = $order->get_items( 'fee' ); foreach ( $line_items_fee as $item_id => $item ) { if ( is_partial_payment_order_item( $item_id, $item ) ) { $via_wallet += $item->get_total( 'edit' ) + $item->get_total_tax( 'edit' ); } } } return apply_filters( 'woo_wallet_order_partial_payment_amount', abs( $via_wallet ), $order_id ); } } if ( ! function_exists( 'update_wallet_partial_payment_session' ) ) { /** * Refresh WooCommerce session for partial payment. * * @param float $amount set. */ function update_wallet_partial_payment_session( $amount = 0 ) { if ( ! is_null( wc()->session ) ) { wc()->session->set( 'partial_payment_amount', $amount ); } } } if ( ! function_exists( 'get_wallet_rechargeable_orders' ) ) { /** * Return wallet rechargeable order id. * * @param array $args args. * @return array */ function get_wallet_rechargeable_orders( $args = array() ) { $hpos_enabled = OrderUtil::custom_orders_table_usage_is_enabled(); if ( $hpos_enabled ) { $order_ids = wc_get_orders( array( 'limit' => -1, 'meta_query' => array( array( 'key' => '_wc_wallet_purchase_credited', 'value' => true, ), ), 'return' => 'ids', 'status' => wc_get_is_paid_statuses(), ) ); } else { $order_ids = wc_get_orders( array( 'limit' => -1, 'return' => 'ids', 'topuporders' => true, 'status' => wc_get_is_paid_statuses(), ) ); } return $order_ids; } } if ( ! function_exists( 'get_wallet_rechargeable_product' ) ) { /** * Get rechargeable product. * * @return WC_Product object */ function get_wallet_rechargeable_product() { Woo_Wallet_Install::cteate_product_if_not_exist(); return wc_get_product( apply_filters( 'woo_wallet_rechargeable_product_id', get_option( '_woo_wallet_recharge_product' ) ) ); } } if ( ! function_exists( 'set_wallet_transaction_meta' ) ) { /** * Insert meta data into transaction meta table * * @global object $wpdb * @param int $transaction_id transaction_id. * @param string $meta_key meta_key. * @param mixed $meta_value meta_value. * @param int $user_id user ID. * @return boolean */ function set_wallet_transaction_meta( $transaction_id, $meta_key, $meta_value, $user_id = '' ) { global $wpdb; $meta_key = wp_unslash( $meta_key ); $meta_value = wp_unslash( $meta_value ); $meta_value = maybe_serialize( $meta_value ); $wpdb->insert( // @codingStandardsIgnoreLine "{$wpdb->base_prefix}woo_wallet_transaction_meta", array( 'transaction_id' => $transaction_id, 'meta_key' => $meta_key, // @codingStandardsIgnoreLine 'meta_value' => $meta_value, // @codingStandardsIgnoreLine ), array( '%d', '%s', '%s', ) ); $meta_id = $wpdb->insert_id; clear_woo_wallet_cache( $user_id ); return $meta_id; } } if ( ! function_exists( 'update_wallet_transaction_meta' ) ) { /** * Update meta data into transaction meta table * * @global object $wpdb * @param int $transaction_id transaction_id. * @param string $meta_key meta_key. * @param mixed $meta_value meta_value. * @param int $user_id user ID. * @return boolean */ function update_wallet_transaction_meta( $transaction_id, $meta_key, $meta_value, $user_id = '' ) { global $wpdb; if ( is_null( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->base_prefix}woo_wallet_transaction_meta WHERE transaction_id = %s AND meta_key = %s", array( $transaction_id, $meta_key ) ) ) ) ) { // @codingStandardsIgnoreLine return set_wallet_transaction_meta( $transaction_id, $meta_key, $meta_value, $user_id ); } else { $meta_key = wp_unslash( $meta_key ); $meta_value = wp_unslash( $meta_value ); $meta_value = maybe_serialize( $meta_value ); $status = $wpdb->update( // @codingStandardsIgnoreLine "{$wpdb->base_prefix}woo_wallet_transaction_meta", array( 'meta_value' => $meta_value ), // @codingStandardsIgnoreLine array( 'transaction_id' => $transaction_id, 'meta_key' => $meta_key, // @codingStandardsIgnoreLine ), array( '%s' ), array( '%d', '%s' ) ); clear_woo_wallet_cache( $user_id ); return $status; } } } if ( ! function_exists( 'get_wallet_transaction_meta' ) ) { /** * Fetch transaction meta * * @global object $wpdb * @param int $transaction_id transaction_id. * @param string $meta_key meta_key. * @param mixed $default The fallback value to return if the data does not exist. * Default false. * @return mixed */ function get_wallet_transaction_meta( $transaction_id, $meta_key, $default = false ) { global $wpdb; $resualt = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->base_prefix}woo_wallet_transaction_meta WHERE transaction_id = %s AND meta_key = %s", $transaction_id, $meta_key ) ); // @codingStandardsIgnoreLine if ( ! is_null( $resualt ) ) { return maybe_unserialize( $resualt ); } else { return $default; } } } if ( ! function_exists( 'get_wallet_transactions' ) ) { /** * Get all wallet transactions * * @global object $wpdb * @param array $args args. * @param mixed $output output. * @return Object rows */ function get_wallet_transactions( $args = array(), $output = OBJECT ) { global $wpdb; $default_args = array( 'user_id' => get_current_user_id(), 'where' => array(), 'where_meta' => array(), 'order_by' => 'transaction_id', 'order' => 'DESC', 'join_type' => 'INNER', 'limit' => '', 'include_deleted' => false, 'fields' => 'all', // Support all | all_with_meta. 'nocache' => is_multisite() ? true : false, ); $args = apply_filters( 'woo_wallet_transactions_query_args', $args ); $args = wp_parse_args( $args, $default_args ); extract( $args ); // @codingStandardsIgnoreLine $query = array(); $query['select'] = 'SELECT transactions.*'; $query['from'] = "FROM {$wpdb->base_prefix}woo_wallet_transactions AS transactions"; // Joins. $joins = array(); if ( ! empty( $where_meta ) ) { $joins['transaction_meta'] = "{$join_type} JOIN {$wpdb->base_prefix}woo_wallet_transaction_meta AS transaction_meta ON transactions.transaction_id = transaction_meta.transaction_id"; } $query['join'] = implode( ' ', $joins ); $query['where'] = 'WHERE 1=1'; if ( $user_id ) { $query['where'] .= $wpdb->prepare( ' AND transactions.user_id = %d', $user_id ); } if ( ! $include_deleted ) { $query['where'] .= ' AND transactions.deleted = 0'; } if ( ! empty( $where_meta ) ) { foreach ( $where_meta as $value ) { if ( ! isset( $value['operator'] ) ) { $value['operator'] = '='; } $query['where'] .= $wpdb->prepare( " AND (transaction_meta.meta_key = %s AND transaction_meta.meta_value {$value['operator']} %s )", $value['key'], $value['value'] ); } } if ( ! empty( $where ) ) { foreach ( $where as $value ) { if ( ! isset( $value['operator'] ) ) { $value['operator'] = '='; } if ( 'IN' === $value['operator'] && is_array( $value['value'] ) ) { $value['value'] = esc_sql( implode( ',', $value['value'] ) ); $query['where'] .= " AND transactions.{$value['key']} {$value['operator']} ({$value['value']})"; } else { $query['where'] .= $wpdb->prepare( " AND transactions.{$value['key']} {$value['operator']} %s", $value['value'] ); } } } if ( ! empty( $after ) || ! empty( $before ) ) { $after = empty( $after ) ? '0000-00-00' : $after; $before = empty( $before ) ? current_time( 'mysql', 1 ) : $before; $query['where'] .= $wpdb->prepare( ' AND transactions.date BETWEEN %s AND %s', $after, $before ); } if ( $order_by ) { $query['order_by'] = "ORDER BY transactions.{$order_by} {$order}"; } if ( $limit ) { $query['limit'] = "LIMIT {$limit}"; } $wpdb->hide_errors(); $query = apply_filters( 'woo_wallet_transactions_query', $query ); $query = implode( ' ', $query ); $query_hash = md5( $user_id . $query ); $cached_results = is_array( get_transient( "woo_wallet_transaction_resualts_{$user_id}" ) ) ? get_transient( "woo_wallet_transaction_resualts_{$user_id}" ) : array(); if ( $nocache || ! isset( $cached_results[ $query_hash ] ) ) { // Enable big selects. $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' ); // @codingStandardsIgnoreLine $query_resualts = $wpdb->get_results( // @codingStandardsIgnoreLine // @codingStandardsIgnoreLine $query ); if ( 'all_with_meta' === $fields ) { foreach ( $query_resualts as $key => $query_resualt ) { $query_resualts[ $key ]->meta = $wpdb->get_results( $wpdb->prepare( "SELECT transaction_meta.meta_key, transaction_meta.meta_value FROM {$wpdb->base_prefix}woo_wallet_transaction_meta AS transaction_meta WHERE transaction_id = %d", $query_resualt->transaction_id ) ); // @codingStandardsIgnoreLine } } $cached_results[ $query_hash ] = $query_resualts; set_transient( "woo_wallet_transaction_resualts_{$user_id}", $cached_results, DAY_IN_SECONDS ); } $result = $cached_results[ $query_hash ]; return $result; } } if ( ! function_exists( 'get_wallet_transactions_count' ) ) { /** * Get wallet transactions count. * * @global object $wpdb * @param int|null $user_id user_id. * @param bool $include_deleted include_deleted. * @return int total count of transactions. */ function get_wallet_transactions_count( $user_id = null, $include_deleted = false ) { global $wpdb; $sql = "SELECT COUNT(*) FROM {$wpdb->base_prefix}woo_wallet_transactions"; if ( $user_id ) { $sql .= " WHERE user_id=$user_id"; } if ( ! $include_deleted ) { if ( $user_id ) { $sql .= ' AND deleted=0'; } else { $sql .= 'WHERE deleted=0'; } } return $wpdb->get_var( $sql ); // @codingStandardsIgnoreLine } } if ( ! function_exists( 'get_wallet_transaction' ) ) { /** * Get Wallet transactions. * * @param int $transaction_id transaction_id. */ function get_wallet_transaction( $transaction_id ) { global $wpdb; $transaction = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}woo_wallet_transactions WHERE transaction_id = %d", $transaction_id ) ); // @codingStandardsIgnoreLine return $transaction; } } if ( ! function_exists( 'get_wallet_transaction_type' ) ) { /** * Return transaction type by transaction id * * @since 1.2.7 * @global object $wpdb * @param int $transaction_id transaction_id. * @return type(string) | false */ function get_wallet_transaction_type( $transaction_id ) { global $wpdb; $transaction = $wpdb->get_row( $wpdb->prepare( "SELECT type FROM {$wpdb->base_prefix}woo_wallet_transactions WHERE transaction_id = %d", $transaction_id ) ); // @codingStandardsIgnoreLine if ( $transaction ) { return $transaction->type; } return false; } } if ( ! function_exists( 'update_wallet_transaction' ) ) { /** * Update wallet transactions. * * @param int $transaction_id transaction_id. * @param int $user_id user_id. * @param array $data data. * @param array $format format. */ function update_wallet_transaction( $transaction_id, $user_id, $data = array(), $format = null ) { global $wpdb; $update = false; if ( ! empty( $data ) ) { $update = $wpdb->update( "{$wpdb->base_prefix}woo_wallet_transactions", $data, array( 'transaction_id' => $transaction_id ), $format, array( '%d' ) ); // @codingStandardsIgnoreLine if ( $update ) { clear_woo_wallet_cache( $user_id ); } } return $update; } } if ( ! function_exists( 'clear_woo_wallet_cache' ) ) { /** * Clear WooCommerce Wallet user transient * * @param int $user_id user_id. */ function clear_woo_wallet_cache( $user_id = '' ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } delete_transient( "woo_wallet_transaction_resualts_{$user_id}" ); } } if ( ! function_exists( 'get_wallet_cashback_amount' ) ) { /** * Get wallet cashback amount. * * @param int $order_id order_id. * @return float */ function get_wallet_cashback_amount( $order_id = 0 ) { _deprecated_function( 'get_wallet_cashback_amount', '1.3.0', 'woo_wallet()->cashback->calculate_cashback()' ); if ( $order_id ) { return woo_wallet()->cashback->calculate_cashback( false, $order_id ); } return woo_wallet()->cashback->calculate_cashback(); } } if ( ! function_exists( 'is_full_payment_through_wallet' ) ) { /** * Check if cart eligible for full payment through wallet * * @return boolean */ function is_full_payment_through_wallet() { $is_valid_payment_through_wallet = false; $current_wallet_balance = woo_wallet()->wallet->get_wallet_balance( get_current_user_id(), 'edit' ); $total = 0; $order_id = null; if ( WC()->cart ) { $order_id = absint( get_query_var( 'order-pay' ) ); // Gets order total from "pay for order" page. if ( 0 < $order_id ) { $order = wc_get_order( $order_id ); if ( $order ) { $total = (float) $order->get_total(); } // Gets order total from cart/checkout. } elseif ( 0 < WC()->cart->total ) { $total = (float) get_woowallet_cart_total(); } } if ( ! is_admin() && $current_wallet_balance >= $total && ( ! is_wallet_rechargeable_cart() ) ) { $is_valid_payment_through_wallet = true; } if ( $order_id && is_wallet_rechargeable_order( $order ) ) { $is_valid_payment_through_wallet = false; } return apply_filters( 'is_valid_payment_through_wallet', $is_valid_payment_through_wallet ); } } if ( ! function_exists( 'get_all_wallet_users' ) ) { /** * Get all wallet users. * * @param bool $exclude_me exclude_me. */ function get_all_wallet_users( $exclude_me = true ) { $args = array( 'blog_id' => get_current_blog_id(), 'exclude' => $exclude_me ? array( get_current_user_id() ) : array(), 'orderby' => 'login', 'order' => 'ASC', ); return get_users( $args ); } } if ( ! function_exists( 'get_total_order_cashback_amount' ) ) { /** * Get total cashback amount of an order. * * @param int $order_id order_id. * @return float */ function get_total_order_cashback_amount( $order_id ) { $order = wc_get_order( $order_id ); $total_cashback_amount = 0; if ( $order ) { $transaction_ids = array(); $_general_cashback_transaction_id = $order->get_meta( '_general_cashback_transaction_id' ); $_coupon_cashback_transaction_id = $order->get_meta( '_coupon_cashback_transaction_id' ); if ( $_general_cashback_transaction_id ) { $transaction_ids[] = $_general_cashback_transaction_id; } if ( $_coupon_cashback_transaction_id ) { $transaction_ids[] = $_coupon_cashback_transaction_id; } if ( ! empty( $transaction_ids ) ) { $total_cashback_amount = array_sum( wp_list_pluck( get_wallet_transactions( array( 'user_id' => $order->get_customer_id(), 'where' => array( array( 'key' => 'transaction_id', 'value' => $transaction_ids, 'operator' => 'IN', ), ), ) ), 'amount' ) ); } } return apply_filters( 'woo_wallet_total_order_cashback_amount', $total_cashback_amount ); } } if ( ! function_exists( 'woo_wallet_persistent_cart_update' ) ) { /** * Update WooWallet persistent cart to restore cart after recharge wallet. */ function woo_wallet_persistent_cart_update() { if ( get_current_user_id() && apply_filters( 'woo_wallet_persistent_cart_enabled', true ) ) { update_user_meta( get_current_user_id(), '_woo_wallet_persistent_cart_' . get_current_blog_id(), get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart_' . get_current_blog_id(), true ) ); } } } if ( ! function_exists( 'woo_wallet_persistent_cart_destroy' ) ) { /** * Delete WooWallet persistent cart after restoring WooCommerce cart. */ function woo_wallet_persistent_cart_destroy() { if ( get_current_user_id() ) { delete_user_meta( get_current_user_id(), '_woo_wallet_persistent_cart_' . get_current_blog_id() ); } } } if ( ! function_exists( 'woo_wallet_get_saved_cart' ) ) { /** * Get saved WooWallet cart items. * * @return array */ function woo_wallet_get_saved_cart() { $saved_cart = array(); if ( apply_filters( 'woo_wallet_persistent_cart_enabled', true ) ) { $saved_cart_meta = get_user_meta( get_current_user_id(), '_woo_wallet_persistent_cart_' . get_current_blog_id(), true ); if ( isset( $saved_cart_meta['cart'] ) ) { $saved_cart = array_filter( (array) $saved_cart_meta['cart'] ); } } return $saved_cart; } } if ( ! function_exists( 'woo_wallet_wc_price_args' ) ) { /** * Get WC price args. * * @param int $user_id user_id. * @return array */ function woo_wallet_wc_price_args( $user_id = '', $args = array() ) { if ( ! $user_id ) { $user_id = get_current_user_id(); } $args = apply_filters( 'woo_wallet_wc_price_args', wp_parse_args( $args, array( 'ex_tax_label' => false, 'currency' => '', 'decimal_separator' => wc_get_price_decimal_separator(), 'thousand_separator' => wc_get_price_thousand_separator(), 'decimals' => wc_get_price_decimals(), 'price_format' => get_woocommerce_price_format(), ) ), $user_id ); return $args; } } if ( ! function_exists( 'get_wallet_user_capability' ) ) { /** * Wallet user admin capability. * * @return string */ function get_wallet_user_capability() { return apply_filters( 'woo_wallet_user_capability', 'manage_woocommerce' ); } } if ( ! function_exists( 'delete_user_wallet_transactions' ) ) { /** * Delete user wallet transactions. * * @param int $user_id user_id. * @param bool $force_delete force_delete. */ function delete_user_wallet_transactions( $user_id, $force_delete = false ) { global $wpdb; if ( ! $force_delete ) { $update = $wpdb->update( "{$wpdb->base_prefix}woo_wallet_transactions", array( 'deleted' => 1 ), array( 'user_id' => $user_id ), array( '%d' ), array( '%d' ) ); // @codingStandardsIgnoreLine if ( $update ) { clear_woo_wallet_cache( $user_id ); } } else { __( 'Your blogroll' ), 'customize_selective_refresh' => true, ); parent::__construct( 'links', __( 'Links' ), $widget_ops ); } /** * Outputs the content for the current Links widget instance. * * @since 2.8.0 * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Links widget instance. */ public function widget( $args, $instance ) { $show_description = isset( $instance['description'] ) ? $instance['description'] : false; $show_name = isset( $instance['name'] ) ? $instance['name'] : false; $show_rating = isset( $instance['rating'] ) ? $instance['rating'] : false; $show_images = isset( $instance['images'] ) ? $instance['images'] : true; $category = isset( $instance['category'] ) ? $instance['category'] : false; $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name'; $order = 'rating' === $orderby ? 'DESC' : 'ASC'; $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1; $before_widget = preg_replace( '/ id="[^"]*"/', ' id="%id"', $args['before_widget'] ); $widget_links_args = array( 'title_before' => $args['before_title'], 'title_after' => $args['after_title'], 'category_before' => $before_widget, 'category_after' => $args['after_widget'], 'show_images' => $show_images, 'show_description' => $show_description, 'show_name' => $show_name, 'show_rating' => $show_rating, 'category' => $category, 'class' => 'linkcat widget', 'orderby' => $orderby, 'order' => $order, 'limit' => $limit, ); /** * Filters the arguments for the Links widget. * * @since 2.6.0 * @since 4.4.0 Added the `$instance` parameter. * * @see wp_list_bookmarks() * * @param array $widget_links_args An array of arguments to retrieve the links list. * @param array $instance The settings for the particular instance of the widget. */ wp_list_bookmarks( apply_filters( 'widget_links_args', $widget_links_args, $instance ) ); } /** * Handles updating settings for the current Links widget instance. * * @since 2.8.0 * * @param array $new_instance New settings for this instance as input by the user via * WP_Widget::form(). * @param array $old_instance Old settings for this instance. * @return array Updated settings to save. */ public function update( $new_instance, $old_instance ) { $new_instance = (array) $new_instance; $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0, ); foreach ( $instance as $field => $val ) { if ( isset( $new_instance[ $field ] ) ) { $instance[ $field ] = 1; } } $instance['orderby'] = 'name'; if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ), true ) ) { $instance['orderby'] = $new_instance['orderby']; } $instance['category'] = (int) $new_instance['category']; $instance['limit'] = ! empty( $new_instance['limit'] ) ? (int) $new_instance['limit'] : -1; return $instance; } /** * Outputsget_review_count(); if ( $show_reviews_count && $show_product_title ) { return 1 === $reviews_count /* translators: %s: Product title. */ ? sprintf( __( 'One review for %s', 'woocommerce' ), $product->get_title() ) : sprintf( /* translators: 1: Number of reviews, 2: Product title. */ _