Ecommerce Shopify WordPress Discussion

Using WooCommerce Points and Rewards as Payment Method

so I've been building a points system in my WordPress website, and everything up until this point seems to be working fine, except for the final and most important step. I wanted the accumulated points to be used to purchase specific products, such as Dokan Subscription or Product Promotion...etc. I've been trying to create a custom Payment Gateway that would use the points as a means of payment, but for some reason, it doesn't show in the checkout page. It does show in the WooCommerce settings and it's enabled. _price_in_points meta is another field I added to the Product where I can set the price for it in points instead of the monetary value. What seems to be the issue? Why it doesn't show during the checkout ? <?php if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { return; } function initialize_points_gateway() { class WC_Gateway_Points extends WC_Payment_Gateway { public function __construct() { $this->id = 'points'; $this->method_title = __( 'Points', 'woocommerce' ); $this->method_description = __( 'Allows payments with user\'s points.', 'woocommerce' ); $this->init_form_fields(); $this->init_settings(); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); } public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable Points Payment', 'woocommerce' ), 'default' => 'no' ), 'title' => array( 'title' => __( 'Title', 'woocommerce' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'Points Payment', 'woocommerce' ), 'desc_tip' => true, ), 'product_ids' => array( 'title' => __( 'Product IDs', 'woocommerce' ), 'type' => 'text', 'description' => __( 'Comma separated list of product IDs that can be bought with points. Leave blank to allow all.', 'woocommerce' ), 'default' => '', 'desc_tip' => true, ), ); } public function process_payment( $order_id ) { global $woocommerce; $user = wp_get_current_user(); $order = wc_get_order( $order_id ); // Check if WC_Points_Rewards_Manager class exists if (!class_exists('WC_Points_Rewards_Manager')) { wc_add_notice( 'Points system is currently unavailable', 'error' ); return; } $points_needed = get_post_meta( $order->get_id(), '_price_in_points', true ); // Check if _price_in_points meta key is set if (!$points_needed) { wc_add_notice( 'Unable to determine the number of points needed for this order', 'error' ); return; } $user_points = WC_Points_Rewards_Manager::get_users_points( $user->ID ); if ( $user_points < $points_needed ) { wc_add_notice( 'Not enough points', 'error' ); return array('result' => 'failure'); } WC_Points_Rewards_Manager::decrease_points( $user->ID, $points_needed, 'points_payment', $order->get_id() ); $order->update_status('completed'); $woocommerce->cart->empty_cart(); return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ) ); } } function add_points_gateway_class( $methods ) { $methods[] = 'WC_Gateway_Points'; return $methods; } add_filter( 'woocommerce_payment_gateways', 'add_points_gateway_class' ); } add_action( 'plugins_loaded', 'initialize_points_gateway' );
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.