Skip to content

Commit

Permalink
v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
navneet-cedcoss committed May 27, 2024
1 parent 3e1ccce commit c9ed631
Show file tree
Hide file tree
Showing 15 changed files with 994 additions and 523 deletions.
107 changes: 107 additions & 0 deletions admin/class-points-rewards-for-woocommerce-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,10 @@ public function wps_wpr_assign_vendor_commission_points( $order_id, $old_status,

return;
}

// assigning payment method points.
$this->wps_wpr_rewards_payment_method_points( $order_id, $old_status, $new_status );

if ( 'completed' === $new_status || 'processing' === $new_status ) {

if ( function_exists( 'mvx_get_order' ) ) {
Expand Down Expand Up @@ -1957,4 +1961,107 @@ public function wps_wpr_restrict_user_from_points_table() {
}
wp_die();
}

/**
* This function is used to give points according to the user selected payment method while placing the order.
*
* @param int $order_id order id.
* @param string $old_status old status.
* @param string $new_status new status.
* @return void
*/
public function wps_wpr_rewards_payment_method_points( $order_id, $old_status, $new_status ) {

$wps_wpr_other_settings = get_option( 'wps_wpr_other_settings', array() );
$wps_wpr_other_settings = ! empty( $wps_wpr_other_settings ) && is_array( $wps_wpr_other_settings ) ? $wps_wpr_other_settings : array();
$wps_wpr_enable_payment_rewards_settings = ! empty( $wps_wpr_other_settings['wps_wpr_enable_payment_rewards_settings'] ) ? $wps_wpr_other_settings['wps_wpr_enable_payment_rewards_settings'] : 0;
$wps_wpr_choose_payment_method = ! empty( $wps_wpr_other_settings['wps_wpr_choose_payment_method'] ) ? $wps_wpr_other_settings['wps_wpr_choose_payment_method'] : '';
$wps_wpr_payment_method_rewards_points = ! empty( $wps_wpr_other_settings['wps_wpr_payment_method_rewards_points'] ) ? $wps_wpr_other_settings['wps_wpr_payment_method_rewards_points'] : 0;
if ( 1 === $wps_wpr_enable_payment_rewards_settings ) {

$order = wc_get_order( $order_id );
$user_id = $order->get_user_id();
// if guest user than return from here.
if ( empty( $user_id ) ) {

return;
}

if ( $order->get_payment_method() === $wps_wpr_choose_payment_method ) {
// assign points when order is completed.
if ( 'completed' === $new_status ) {

$wps_wpr_payment_rewards_done = get_post_meta( $order_id, 'wps_wpr_payment_rewards_done', true );
if ( empty( $wps_wpr_payment_rewards_done ) ) {

$get_points = get_user_meta( $user_id, 'wps_wpr_points', true );
$get_points = ! empty( $get_points ) ? $get_points : 0;
$payment_rewards_details = get_user_meta( $user_id, 'points_details', true );
$payment_rewards_details = ! empty( $payment_rewards_details ) && is_array( $payment_rewards_details ) ? $payment_rewards_details : array();
$updated_points = (int) $get_points + $wps_wpr_payment_method_rewards_points;

if ( isset( $payment_rewards_details['payment_methods_points'] ) && ! empty( $payment_rewards_details['payment_methods_points'] ) ) {

$arr = array(
'date' => date_i18n( 'Y-m-d h:i:sa' ),
'payment_methods_points' => $wps_wpr_payment_method_rewards_points,
);
$payment_rewards_details['payment_methods_points'][] = $arr;
} else {

$arr = array(
'date' => date_i18n( 'Y-m-d h:i:sa' ),
'payment_methods_points' => $wps_wpr_payment_method_rewards_points,
);
$payment_rewards_details['payment_methods_points'][] = $arr;
}

update_user_meta( $user_id, 'wps_wpr_points', $updated_points );
update_user_meta( $user_id, 'points_details', $payment_rewards_details );
update_post_meta( $order_id, 'wps_wpr_payment_rewards_done', 'done' );
update_post_meta( $order_id, 'wps_wpr_payment_method_rewards_points', $wps_wpr_payment_method_rewards_points );
}
}

// refund points when order is cancelled or refunded.
if ( 'completed' === $old_status && ( 'refunded' === $new_status || 'cancelled' === $new_status ) ) {

$wps_wpr_payment_points_refunded = get_post_meta( $order_id, 'wps_wpr_payment_points_refunded', true );
if ( empty( $wps_wpr_payment_points_refunded ) ) {

$wps_wpr_payment_method_rewards_points = get_post_meta( $order_id, 'wps_wpr_payment_method_rewards_points', true );
if ( $wps_wpr_payment_method_rewards_points > 0 ) {

$user_points = get_user_meta( $user_id, 'wps_wpr_points', true );
$user_points = ! empty( $user_points ) ? $user_points : 0;
$payment_refund_details = get_user_meta( $user_id, 'points_details', true );
$payment_refund_details = ! empty( $payment_refund_details ) && is_array( $payment_refund_details ) ? $payment_refund_details : array();
$updated_points = (int) $user_points - $wps_wpr_payment_method_rewards_points;

if ( isset( $payment_refund_details['refund_payment_points_details'] ) && ! empty( $payment_refund_details['refund_payment_points_details'] ) ) {

$arr = array(
'date' => date_i18n( 'Y-m-d h:i:sa' ),
'refund_payment_points_details' => $wps_wpr_payment_method_rewards_points,
);
$payment_refund_details['refund_payment_points_details'][] = $arr;
} else {

$arr = array(
'date' => date_i18n( 'Y-m-d h:i:sa' ),
'refund_payment_points_details' => $wps_wpr_payment_method_rewards_points,
);
$payment_refund_details['refund_payment_points_details'][] = $arr;
}

update_user_meta( $user_id, 'wps_wpr_points', $updated_points );
update_user_meta( $user_id, 'points_details', $payment_refund_details );
update_post_meta( $order_id, 'wps_wpr_payment_points_refunded', 'done' );
}
}
}
}
}
}

}
4 changes: 2 additions & 2 deletions admin/class-points-rewards-for-woocommerce-dummy-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2406,9 +2406,9 @@ public function wps_wpr_enqueue_dummy_file() {
if ( wp_verify_nonce( ! empty( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : '', 'par_main_setting' ) ) {
if ( ! empty( $_GET['page'] ) && 'wps-rwpr-setting' == $_GET['page'] ) {

wp_register_style( 'wps_wpr_dummy_css_file', WPS_RWPR_DIR_URL . 'admin/partials/dummyfile/dummycss/wps-points-and-rewards-dummy.css', array(), '2.3.0' );
wp_register_style( 'wps_wpr_dummy_css_file', WPS_RWPR_DIR_URL . 'admin/partials/dummyfile/dummycss/wps-points-and-rewards-dummy.css', array(), '2.3.1' );
wp_enqueue_style( 'wps_wpr_dummy_css_file' );
wp_register_script( 'wps_wpr_dummy_js_file', WPS_RWPR_DIR_URL . 'admin/partials/dummyfile/dummyjs/wps-points-and-rewards-dummy.js', array(), '2.3.0', true );
wp_register_script( 'wps_wpr_dummy_js_file', WPS_RWPR_DIR_URL . 'admin/partials/dummyfile/dummyjs/wps-points-and-rewards-dummy.js', array(), '2.3.1', true );
wp_enqueue_script( 'wps_wpr_dummy_js_file' );
wp_localize_script(
'wps_wpr_dummy_js_file',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,64 @@ public function wps_wpr_display_shortcode() {
);
return apply_filters( 'wps_wpr_show_shortcoe_text', $shortcode_array );
}

/**
* This functions is used to get all pages for redirect user using referral link.
*
* @return pages
*/
public function wps_wpr_list_payment_method() {

$wps_wpr_payment_ids = array();
if ( null !== WC() && null !== WC()->payment_gateways->get_available_payment_gateways() ) {
foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {

if ( 'yes' === $gateway->enabled ) {
if ( 'cod' === $gateway->id || 'bacs' === $gateway->id || 'cheque' === $gateway->id ) {

$wps_wpr_payment_ids[] = array(
'id' => $gateway->id,
'name' => $gateway->title,
);
}
}
}
}
return apply_filters( 'wps_wpr_add_extra_payment_method', $wps_wpr_payment_ids );
}

/**
* This function is used to create select dropdown.
*
* @param array $value value.
* @param array $general_settings general settings.
* @return void
*/
public function wps_wpr_generate_select_dropdown( $value, $general_settings ) {
$selectedvalue = isset( $general_settings[ $value['id'] ] ) ? ( $general_settings[ $value['id'] ] ) : '';
?>
<label for="<?php echo ( array_key_exists( 'id', $value ) ) ? esc_html( $value['id'] ) : ''; ?>">
<select name="<?php echo ( array_key_exists( 'id', $value ) ) ? esc_html( $value['id'] ) : ''; ?>" id="<?php echo ( array_key_exists( 'id', $value ) ) ? esc_html( $value['id'] ) : ''; ?>"
<?php if ( array_key_exists( 'select', $value ) ) : ?>
<?php endif; ?>
class="<?php echo ( array_key_exists( 'class', $value ) ) ? esc_html( $value['class'] ) : ''; ?>"
<?php
if ( array_key_exists( 'custom_attribute', $value ) ) {
foreach ( $value['custom_attribute'] as $attribute_name => $attribute_val ) {
echo wp_kses_post( $attribute_name . '=' . $attribute_val );
}
}
if ( is_array( $value['options'] ) && ! empty( $value['options'] ) ) {
foreach ( $value['options'] as $option ) {
?>
><option value="<?php echo esc_html( $option['id'] ); ?>" <?php echo selected( $selectedvalue, $option['id'] ); ?> ><?php echo esc_html( $option['name'] ); ?></option>
<?php
}
}
?>
</select>
</label>
<?php
}

}
62 changes: 62 additions & 0 deletions admin/partials/templates/class-points-log-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,68 @@ public function get_users_points( $current_page, $per_page ) {
</div>
<?php
}
if ( array_key_exists( 'payment_methods_points', $point_log ) ) {
?>
<div class="wps_wpr_slide_toggle">
<p class="wps_wpr_view_log_notice wps_wpr_common_slider" ><?php esc_html_e( 'Earn points through payment method', 'points-and-rewards-for-woocommerce' ); ?>
<a class ="wps_wpr_open_toggle" href="javascript:;"></a>
</p>
<table class = "form-table mwp_wpr_settings wps_wpr_points_view wps_wpr_common_table">
<thead>
<tr valign="top">
<th scope="row" class="wps_wpr_head_titledesc">
<span class="wps_wpr_nobr"><?php echo esc_html__( 'Date & Time', 'points-and-rewards-for-woocommerce' ); ?></span>
</th>
<th scope="row" class="wps_wpr_head_titledesc">
<span class="wps_wpr_nobr"><?php echo esc_html__( 'Point Status', 'points-and-rewards-for-woocommerce' ); ?></span>
</th>
</tr>
</thead>
<?php
foreach ( $point_log['payment_methods_points'] as $key => $value ) {
?>
<tr valign="top">
<td class="forminp forminp-text"><?php echo esc_html( $value['date'] ); ?></td>
<td class="forminp forminp-text"><?php echo '+' . esc_html( $value['payment_methods_points'] ); ?> </td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
if ( array_key_exists( 'refund_payment_points_details', $point_log ) ) {
?>
<div class="wps_wpr_slide_toggle">
<p class="wps_wpr_view_log_notice wps_wpr_common_slider" ><?php esc_html_e( 'Points earned via payment method refunded', 'points-and-rewards-for-woocommerce' ); ?>
<a class ="wps_wpr_open_toggle" href="javascript:;"></a>
</p>
<table class = "form-table mwp_wpr_settings wps_wpr_points_view wps_wpr_common_table">
<thead>
<tr valign="top">
<th scope="row" class="wps_wpr_head_titledesc">
<span class="wps_wpr_nobr"><?php echo esc_html__( 'Date & Time', 'points-and-rewards-for-woocommerce' ); ?></span>
</th>
<th scope="row" class="wps_wpr_head_titledesc">
<span class="wps_wpr_nobr"><?php echo esc_html__( 'Point Status', 'points-and-rewards-for-woocommerce' ); ?></span>
</th>
</tr>
</thead>
<?php
foreach ( $point_log['refund_payment_points_details'] as $key => $value ) {
?>
<tr valign="top">
<td class="forminp forminp-text"><?php echo esc_html( $value['date'] ); ?></td>
<td class="forminp forminp-text"><?php echo '-' . esc_html( $value['refund_payment_points_details'] ); ?> </td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
if ( array_key_exists( 'api_membership_logs', $point_log ) ) {
?>
<div class="wps_wpr_slide_toggle">
Expand Down
43 changes: 39 additions & 4 deletions admin/partials/templates/wps-other-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@
array(
'type' => 'sectionend',
),
array(
'title' => __( 'Rewards Points via Payment Method', 'points-and-rewards-for-woocommerce' ),
'type' => 'title',
),
array(
'title' => __( 'Enable Payment Reward Settings', 'points-and-rewards-for-woocommerce' ),
'type' => 'checkbox',
'id' => 'wps_wpr_enable_payment_rewards_settings',
'class' => 'input-text',
'desc_tip' => __( 'By enabling this setting, users have the ability to earn points based on their chosen payment method.', 'points-and-rewards-for-woocommerce' ),
'default' => 0,
'desc' => __( 'Activate this setting to reward users according to their order payment method.', 'points-and-rewards-for-woocommerce' ),
),
array(
'title' => __( 'Select Payment Method', 'points-and-rewards-for-woocommerce' ),
'type' => 'select',
'id' => 'wps_wpr_choose_payment_method',
'class' => 'wc-enhanced-select',
'desc_tip' => __( 'Choose the payment method on which users will earn points accordingly.', 'points-and-rewards-for-woocommerce' ),
'options' => $settings_obj->wps_wpr_list_payment_method(),
),
array(
'title' => __( 'Enter Points', 'points-and-rewards-for-woocommerce' ),
'type' => 'number',
'default' => 1,
'id' => 'wps_wpr_payment_method_rewards_points',
'custom_attributes' => array( 'min' => '"1"' ),
'class' => 'input-text wps_wpr_new_woo_ver_style_text',
'desc_tip' => __( 'Points will be rewarded to the user when the order status is marked as completed.', 'points-and-rewards-for-woocommerce' ),
'desc' => __( 'Enter the points that will be rewarded to the user according to their chosen payment method.', 'points-and-rewards-for-woocommerce' ),
),
array(
'type' => 'sectionend',
),
);

$wps_wpr_other_settings = apply_filters( 'wps_wpr_others_settings', $wps_wpr_other_settings );
Expand All @@ -161,11 +195,9 @@

unset( $_POST['wps_wpr_save_othersetting'] );
$other_settings = array();
/* Check if input is not empty, if empty then assign them default value*/
$postdata = $settings_obj->check_is_settings_is_not_empty( $wps_wpr_other_settings, $_POST );
$postdata = $settings_obj->check_is_settings_is_not_empty( $wps_wpr_other_settings, $_POST );
foreach ( $postdata as $key => $value ) {
$value = stripcslashes( $value );
$value = sanitize_text_field( $value );

$other_settings[ $key ] = $value;
}
/* Save settings data into the database*/
Expand Down Expand Up @@ -231,6 +263,9 @@
}
}
}
if ( 'select' == $value['type'] ) {
$settings_obj->wps_wpr_generate_select_dropdown( $value, $other_settings );
}
do_action( 'wps_wpr_additional_other_settings', $value, $other_settings );
?>
</div>
Expand Down
4 changes: 3 additions & 1 deletion includes/class-points-rewards-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct() {
$this->version = REWARDEEM_WOOCOMMERCE_POINTS_REWARDS_VERSION;
} else {

$this->version = '2.3.0';
$this->version = '2.3.1';
}

$this->plugin_name = 'points-and-rewards-for-woocommerce';
Expand Down Expand Up @@ -230,6 +230,8 @@ private function define_admin_hooks() {
$this->loader->add_filter( 'mvx_vendor_payment_mode', $plugin_admin, 'wsfw_admin_mvx_list_mxfdxfodules' );
$this->loader->add_filter( 'mvx_parent_order_to_vendor_order_statuses_to_sync', $plugin_admin, 'wsfw_mvx_parent_order_to_vendor_order_statuses_to_sync', 10, 1 );
$this->loader->add_filter( 'woocommerce_order_status_changed', $plugin_admin, 'wps_wpr_assign_vendor_commission_points', 10, 3 );

// restrict user from points table.
$this->loader->add_action( 'wp_ajax_restrict_user_from_points_table', $plugin_admin, 'wps_wpr_restrict_user_from_points_table' );
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wpswings-onboarding-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function enqueue_styles() {
*/
if ( $this->is_valid_page_screen() ) {

wp_enqueue_style( 'makewebbetter-onboarding-style', WPS_RWPR_DIR_URL . 'admin/css/wpswings-onboarding-admin.css', array(), '2.3.0', 'all' );
wp_enqueue_style( 'makewebbetter-onboarding-style', WPS_RWPR_DIR_URL . 'admin/css/wpswings-onboarding-admin.css', array(), '2.3.1', 'all' );
wp_enqueue_style( 'select2' );
}
}
Expand All @@ -182,7 +182,7 @@ public function enqueue_scripts() {

if ( $this->is_valid_page_screen() ) {

wp_enqueue_script( 'makewebbetter-onboarding-scripts', WPS_RWPR_DIR_URL . 'admin/js/wpswings-onboarding-admin.js', array( 'jquery', 'select2' ), '2.3.0', true );
wp_enqueue_script( 'makewebbetter-onboarding-scripts', WPS_RWPR_DIR_URL . 'admin/js/wpswings-onboarding-admin.js', array( 'jquery', 'select2' ), '2.3.1', true );

global $pagenow;
$current_slug = ! empty( explode( '/', plugin_basename( __FILE__ ) ) ) ? explode( '/', plugin_basename( __FILE__ ) )[0] : '';
Expand Down
Binary file modified languages/points-and-rewards-for-woocommerce-en_US.mo
Binary file not shown.
Loading

0 comments on commit c9ed631

Please sign in to comment.