Skip to content

Instantly share code, notes, and snippets.

@iMojtaba
Last active December 17, 2023 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMojtaba/c5bc855c5ae02c4ca6dbfe966184d6ef to your computer and use it in GitHub Desktop.
Save iMojtaba/c5bc855c5ae02c4ca6dbfe966184d6ef to your computer and use it in GitHub Desktop.
<?php
add_action('after_setup_theme', 'mwp_fake_gateway_init', 0);
function mwp_fake_gateway_init() {
if ( !class_exists( 'WC_Payment_Gateway' ) ) return;
class WC_MWP_FAKE extends WC_Payment_Gateway {
public function __construct(){
$this->author = 'Mojtab Darvishi';
$this->id = 'mwp_fake';
$this->method_title = __('Fake Gateway', 'woocommerce');
$this->method_description = __( 'Woocommerce Fake Gateway or Test Payments', 'woocommerce');
$this->icon = apply_filters('WC_MWP_FAKE_logo', get_template_directory_uri() . '/assets/images/fake.png');
$this->has_fields = false;
$this->init_form_fields();
$this->init_settings();
$this->title = $this->settings['title'];
$this->description = $this->settings['description'];
$this->success_massage = $this->settings['success_massage'];
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function init_form_fields(){
$this->form_fields = apply_filters('WC_MWP_FAKE_Config',
array(
'base_confing' => array(
'title' => __( 'Basic Settings', 'woocommerce' ),
'type' => 'title',
'description' => '',
),
'enabled' => array(
'title' => __( 'Active/Deactive', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Activate Fake Gateway', 'woocommerce' ),
'description' => __( 'Warning! Do NOT active this gateway on your website! it is just for developers and testing', 'woocommerce' ),
'default' => 'yes',
'desc_tip' => true,
),
'title' => array(
'title' => __( 'Title', 'woocommerce' ),
'type' => 'text',
'description' => __( 'Description', 'woocommerce' ),
'default' => __( 'Fake Gateway', 'woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description Gateway', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'default' => ''
),
'success_massage' => array(
'title' => __( 'Payment Success Message', 'woocommerce' ),
'type' => 'textarea',
'default' => __( 'Payment has been completed', 'woocommerce' ),
)
)
);
}
public function process_payment( $order_id ) {
$order = wc_get_order( $order_id );
// Reduce stock levels
$order->reduce_order_stock();
// Remove cart
WC()->cart->empty_cart();
// Make payment comlete
$order->payment_complete();
// Return thankyou redirect
return array(
'result' => 'success',
'redirect' => $this->get_return_url( $order )
);
}
}
function woocommerce_add_gateway_mwp_fake($methods) {
$methods[] = 'WC_MWP_FAKE';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'woocommerce_add_gateway_mwp_fake' );
}
@KingMatrix1989
Copy link

KingMatrix1989 commented Oct 22, 2016

سلام. با چه نسخه ای از ووکامرس کار میکنه؟
میشه فقط برای یک عضو خاص فعال باشه؟

@KingMatrix1989
Copy link

خیلی عالی. واقعا دنبالش بودم. پلاگینش کن حتما.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment