Support » Plugin: TeraWallet - For WooCommerce » Display cashback in percent

  • Resolved sifat1991

    (@sifat1991)


    When i offer cashback on specific product it is not showing in percentage like 10% cash back. Its is showing the amount cash back. I havent choosen percentage cash back on product. Please help

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Can you please respond?? I need help badly

    Plugin Author Subrata Mal

    (@subratamal)

    Hi @sifat1991

    By default percentage cashback amount will be converted to the amount according to the product price and displayed as actual cashback amount. If you want to override this you have to use our filter woo_wallet_product_cashback_amount.

    Thank you.

    Can you please give me the code and where to add it? It will be very helpful bhai.

    I want to show 10% cash back

    Plugin Author Subrata Mal

    (@subratamal)

    @sifat1991

    Please use below code in theme function.php file.

    add_action('wp_loaded', 'wp_loaded_callback');
    
    if (!function_exists('wp_loaded_callback')) {
    
        function wp_loaded_callback() {
            remove_action('woocommerce_shop_loop_item_title', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);
            remove_action('woocommerce_before_single_product_summary', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);
            add_action('woocommerce_shop_loop_item_title', 'display_cashback_wallet_cashback', 15);
            add_action('woocommerce_before_single_product_summary', 'display_cashback_wallet_cashback', 15);
        }
    
    }
    
    if (!function_exists('display_cashback_wallet_cashback')) {
    
        function display_cashback_wallet_cashback() {
            $product = wc_get_product(get_the_ID());
            if ($product && 'on' === woo_wallet()->settings_api->get_option('is_enable_cashback_reward_program', '_wallet_settings_credit') && $product->get_price('edit') && apply_filters('is_display_cashback_on_product', true) && apply_filters('is_product_cashback_enable', true, $product->get_id())) {
                $global_cashbak_type = woo_wallet()->settings_api->get_option('cashback_type', '_wallet_settings_credit', 'percent');
                $global_cashbak_amount = floatval(woo_wallet()->settings_api->get_option('cashback_amount', '_wallet_settings_credit', 0));
                if ('product' === woo_wallet()->settings_api->get_option('cashback_rule', '_wallet_settings_credit', 'cart')) {
                    $product_wise_cashback_type = get_post_meta($product->get_id(), '_cashback_type', true);
                    $product_wise_cashback_amount = get_post_meta($product->get_id(), '_cashback_amount', true) ? get_post_meta($product->get_id(), '_cashback_amount', true) : 0;
                    $cashback_amount = 0;
                    $cashback_type = 'percent';
                    if ($product_wise_cashback_type && $product_wise_cashback_amount) {
                        if ('percent' === $product_wise_cashback_type) {
                            $cashback_amount = $product_wise_cashback_amount;
                        } else {
                            $cashback_amount = $product_wise_cashback_amount;
                            $cashback_type = 'fixed';
                        }
                    } else {
                        if ('percent' === $global_cashbak_type) {
                            $cashback_amount = $global_cashbak_amount;
                        } else {
                            $cashback_amount = $global_cashbak_amount;
                            $cashback_type = 'fixed';
                        }
                    }
                    if ($cashback_amount) {
                        if ('percent' === $cashback_type) {
                            echo '<span class="on-woo-wallet-cashback">' . $cashback_amount . '% ' . __('Cashback', 'woo-wallet') . '</span>';
                        } else {
                            echo '<span class="on-woo-wallet-cashback">' . wc_price($cashback_amount) . __(' Cashback', 'woo-wallet') . '</span>';
                        }
                    }
                } else if ('product_cat' === woo_wallet()->settings_api->get_option('cashback_rule', '_wallet_settings_credit', 'cart')) {
                    $term_ids = $product->get_category_ids('edit');
                    $category_wise_cashback_amounts = array();
                    $cashback_amount = 0;
                    $cashback_type = 'percent';
                    if (!empty($term_ids)) {
                        foreach ($term_ids as $term_id) {
                            $category_wise_cashback_type = get_woocommerce_term_meta($term_id, '_woo_cashback_type', true);
                            $category_wise_cashback_amount = get_woocommerce_term_meta($term_id, '_woo_cashback_amount', true);
                            if ($category_wise_cashback_type && $category_wise_cashback_amount) {
                                if ('percent' === $category_wise_cashback_type) {
                                    $cashback_subtotal = $product->get_price() * ($category_wise_cashback_amount / 100);
                                    $category_wise_cashback_amounts[] = array('cashback_subtotal' => $cashback_subtotal, 'amount' => $category_wise_cashback_amount, 'type' => $category_wise_cashback_type);
                                } else {
                                    $category_wise_cashback_amounts[] = array('cashback_subtotal' => $category_wise_cashback_amount, 'amount' => $category_wise_cashback_amount, 'type' => $category_wise_cashback_type);
                                }
                            }
                        }
                    }
                    if (!empty($category_wise_cashback_amounts)) {
                        $category_wise_cashback = ('on' === woo_wallet()->settings_api->get_option('allow_min_cashback', '_wallet_settings_credit', 'on')) ? min($category_wise_cashback_amounts) : max($category_wise_cashback_amounts);
                        $cashback_amount = $category_wise_cashback['amount'];
                        $cashback_type = $category_wise_cashback['type'];
                    } else {
                        if ('percent' === $global_cashbak_type) {
                            $cashback_amount = $global_cashbak_amount;
                        } else {
                            $cashback_amount = $global_cashbak_amount;
                            $cashback_type = 'fixed';
                        }
                    }
                    if ($cashback_amount) {
                        if ('percent' === $cashback_type) {
                            echo '<span class="on-woo-wallet-cashback">' . $cashback_amount . '% ' . __('Cashback', 'woo-wallet') . '</span>';
                        } else {
                            echo '<span class="on-woo-wallet-cashback">' . wc_price($cashback_amount) . __(' Cashback', 'woo-wallet') . '</span>';
                        }
                    }
                }
            }
        }
    
    }

    Thank you so much

    remove_action('woocommerce_shop_loop_item_title', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);
    remove_action('woocommerce_before_single_product_summary', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);

    these two line causing an error,

    Error message: Uncaught Error: Class 'Woo_Wallet_Frontend' not found

    • This reply was modified 2 months, 2 weeks ago by Themeix.
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.