Home / eCommerce / ALP – Fix missing custom order status options
Duplicate Snippet

Embed Snippet on Your Site

ALP – Fix missing custom order status options

Fixing the bug in Advanced Loyalty Program v 1.9.2 of missing custom order status options.

Code Preview
php
<?php
  add_filter( 'lpfw_filter_get_settings_sections', function( $response ) {
      $data = $response->get_data();
      // Build options dynamically from all registered WooCommerce order statuses
      $status_options = array();
      foreach ( wc_get_order_statuses() as $slug => $label ) {
          $status_options[] = array(
              'key'   => str_replace( 'wc-', '', $slug ), // strip 'wc-' prefix WC adds
              'label' => $label,
          );
      }
      // Find the points_earning section and swap in the dynamic options
      foreach ( $data as $section_idx => $section ) {
          if ( isset( $section['id'] ) && 'points_earning' === $section['id'] && ! empty( $section['fields'] ) ) {
              foreach ( $section['fields'] as $field_idx => $field ) {
                  if ( isset( $field['id'] ) && 'lpfw_earn_points_order_status' === $field['id'] ) {
                      $data[ $section_idx ]['fields'][ $field_idx ]['options'] = $status_options;
                      break 2;
                  }
              }
          }
      }
      $response->set_data( $data );
      return $response;
  } );

Comments

Add a Comment