Plugin Directory

Changeset 3046034


Ignore:
Timestamp:
03/06/2024 02:59:53 AM (2 years ago)
Author:
thanhtd
Message:

Update

Location:
subre-product-subscription-for-woo/trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • subre-product-subscription-for-woo/trunk/CHANGELOG.txt

    r3031985 r3046034  
     1/**1.0.5 - 2024.03.06**/
     2- Updated: price html at cart/checkout blocks
     3
    14/**1.0.4 - 2024.02.06**/
    25– Fixed: Data type in create_renewal_order function
  • subre-product-subscription-for-woo/trunk/frontend/cart.php

    r2984097 r3046034  
    33    exit;
    44}
     5
     6use Automattic\WooCommerce\Blocks\Package;
     7use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
     8use Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema;
    59
    610class SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_Frontend_Cart {
     
    2024        add_action( 'woocommerce_after_calculate_totals', array( $this, 'remove_calculation_price_filter' ) );
    2125        add_action( 'woocommerce_cart_calculate_fees', [ $this, 'add_signup_fee' ] );
     26        add_action( 'init', [ $this, 'extend_store_endpoint' ] );
    2227    }
    2328
     
    151156        }
    152157    }
     158
     159    protected function register_endpoint_data( $args ) {
     160        if ( function_exists( 'woocommerce_store_api_register_endpoint_data' ) ) {
     161            woocommerce_store_api_register_endpoint_data( $args );
     162        } else {
     163            Package::container()->get( ExtendSchema::class )->register_endpoint_data( $args );
     164        }
     165    }
     166
     167    public function extend_store_endpoint() {
     168        $namespace = 'subreSubscription';
     169        $this->register_endpoint_data(
     170            array(
     171                'endpoint'      => CartItemSchema::IDENTIFIER,
     172                'namespace'     => $namespace,
     173                'data_callback' => array( $this, 'extend_cart_item_data' ),
     174//              'schema_callback' => array( $this, 'extend_cart_item_schema' ),
     175                'schema_type'   => ARRAY_A,
     176            )
     177        );
     178    }
     179
     180    public function extend_cart_item_data( $cart_item ) {
     181        $product = $cart_item['data'];
     182
     183//      $item_data['origin_price']    = $origin_price;
     184        $item_data = [];
     185
     186        if ( SUBRE_SUBSCRIPTION_PRODUCT_HELPER::is_subscription( $product ) ) {
     187            $money_formatter = function_exists( 'woocommerce_store_api_get_formatter' ) ? woocommerce_store_api_get_formatter( 'money' ) : Package::container()->get( ExtendSchema::class )->get_formatter( 'money' );
     188
     189            $origin_price = $cart_item['subre_origin_price'] ?? '';
     190            $quantity     = $cart_item['quantity'];
     191
     192            $price = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_item_price( $product, array( 'qty' => $quantity, 'price' => $origin_price, ) );
     193
     194            $item_data['quantity']           = $quantity;
     195            $item_data['cart_item_price']    = $product->get_price();
     196            $item_data['subscription_price'] = $money_formatter->format( $price );
     197            $instance                        = \SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_instance();
     198
     199            $sign_up_fee = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_product_sign_up_fee( $product );
     200            if ( $sign_up_fee ) {
     201                $item_data['sign_up_fee'] = $money_formatter->format( $quantity * $sign_up_fee );
     202            }
     203
     204            $trial_period             = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_subscription_trial_period( $product );
     205            $trial_period_unit        = $product->get_meta( '_subre_product_trial_period_unit', true );
     206            $subscription_period      = $product->get_meta( '_subre_product_period', true );
     207            $subscription_period_unit = $product->get_meta( '_subre_product_period_unit', true );
     208            $expire_after             = $product->get_meta( '_subre_product_expire_after', true );
     209//          $expire_after_unit        = $product->get_meta( '_subre_product_expire_after_unit', true );
     210            $expire_after_unit = 'cycle';
     211
     212            if ( $trial_period && $sign_up_fee ) {
     213                $price_html_with_trial_and_sign_up_fee = $instance->get_params( 'price_html_with_trial_and_sign_up_fee' );
     214                $item_data['subscription_period']      = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $subscription_period, $subscription_period_unit );
     215                $item_data['trial_period']             = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $trial_period, $trial_period_unit, true );
     216//              $item_data['sign_up_fee']              = $quantity * $sign_up_fee;
     217
     218                if ( $price_html_with_trial_and_sign_up_fee ) {
     219//                  $display = str_replace( array(
     220//                      '{subscription_price}',
     221//                      '{subscription_period}',
     222//                      '{sign_up_fee}',
     223//                      '{trial_period}'
     224//                  ), array(
     225//                      $price,
     226//                      self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     227//                      wc_price( $quantity * $sign_up_fee ),
     228//                      self::get_formatted_period( $trial_period, $trial_period_unit, true ),
     229//                  ), $price_html_with_trial_and_sign_up_fee );
     230                    $item_data['display'] = $price_html_with_trial_and_sign_up_fee;
     231
     232                }
     233            } else {
     234                if ( $trial_period ) {
     235                    $price_html_with_trial = $instance->get_params( 'price_html_with_trial' );
     236                    if ( $price_html_with_trial ) {
     237//                      $display = str_replace( array(
     238//                          '{subscription_price}',
     239//                          '{subscription_period}',
     240//                          '{trial_period}'
     241//                      ), array(
     242//                          $price,
     243//                          self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     244//                          self::get_formatted_period( $trial_period, $trial_period_unit, true ),
     245//                      ), $price_html_with_trial );
     246
     247                        $item_data['display']             = $price_html_with_trial;
     248                        $item_data['subscription_period'] = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $subscription_period, $subscription_period_unit );
     249                        $item_data['trial_period']        = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $trial_period, $trial_period_unit, true );
     250
     251                    }
     252                } elseif ( $sign_up_fee ) {
     253                    $price_html_with_sign_up_fee = $instance->get_params( 'price_html_with_sign_up_fee' );
     254                    if ( $price_html_with_sign_up_fee ) {
     255//                      $display = str_replace( array(
     256//                          '{subscription_price}',
     257//                          '{subscription_period}',
     258//                          '{sign_up_fee}'
     259//                      ), array(
     260//                          $price,
     261//                          self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     262//                          wc_price( $quantity * $sign_up_fee ),
     263//                      ), $price_html_with_sign_up_fee );
     264
     265                        $item_data['display'] = $price_html_with_sign_up_fee;
     266//                      $item_data['sign_up_fee']         = $quantity * $sign_up_fee;
     267                        $item_data['subscription_period'] = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $subscription_period, $subscription_period_unit );
     268
     269                    }
     270                } else {
     271                    $price_html = $instance->get_params( 'price_html' );
     272                    if ( $price_html ) {
     273//                      $display = str_replace( array(
     274//                          '{subscription_price}',
     275//                          '{subscription_period}',
     276//                      ), array(
     277//                          $price,
     278//                          self::get_formatted_period( $subscription_period, $subscription_period_unit ),
     279//                      ), $price_html );
     280
     281                        $item_data['display']             = $price_html;
     282                        $item_data['subscription_period'] = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_formatted_period( $subscription_period, $subscription_period_unit );
     283
     284                    }
     285                }
     286            }
     287
     288            if ( $expire_after ) {
     289                $expiry_date_info = $instance->get_params( 'expiry_date_info' );
     290                if ( $expiry_date_info ) {
     291                    if ( 'cycle' === $expire_after_unit ) {
     292                        $expire_after      = $expire_after * $subscription_period;
     293                        $expire_after_unit = $subscription_period_unit;
     294                    }
     295                    switch ( $expire_after_unit ) {
     296                        case 'year':
     297                            $expire_period = sprintf( _n( '%s year', '%s years', $expire_after, 'subre-product-subscription-for-woocommerce' ), $expire_after );
     298                            break;
     299                        case 'month':
     300                            $expire_period = sprintf( _n( '%s month', '%s months', $expire_after, 'subre-product-subscription-for-woocommerce' ), $expire_after );
     301                            break;
     302                        case 'week':
     303                            $expire_period = sprintf( _n( '%s week', '%s weeks', $expire_after, 'subre-product-subscription-for-woocommerce' ), $expire_after );
     304                            break;
     305                        case 'day':
     306                        default:
     307                            $expire_period = sprintf( _n( '%s day', '%s days', $expire_after, 'subre-product-subscription-for-woocommerce' ), $expire_after );
     308                            break;
     309                    }
     310                    $expiry_date = time() + $expire_after * SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_unit_in_seconds( $expire_after_unit );
     311                    if ( $trial_period ) {
     312                        $expiry_date += $trial_period * SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_unit_in_seconds( $trial_period_unit );
     313                    }
     314
     315                    $item_data['expiry'] = str_replace(
     316                        array( '{expiry_period}', '{expiry_date}', ),
     317                        array( $expire_period, wc_format_datetime( \SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_datetime( $expiry_date ) ), ),
     318                        $expiry_date_info );
     319                }
     320            }
     321
     322            $subscription_period      = $product->get_meta( '_subre_product_period', true );
     323            $subscription_period_unit = $product->get_meta( '_subre_product_period_unit', true );
     324            $subscription_cycle       = $subscription_period * SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_unit_in_seconds( $subscription_period_unit );
     325            $item_data['first_renew'] = sprintf( esc_html__( 'First renewal: %s', 'subre-product-subscription-for-woocommerce' ), wc_format_datetime( SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DATA::get_datetime( time() + $subscription_cycle ) ) );
     326        }
     327
     328        return $item_data;
     329    }
    153330}
  • subre-product-subscription-for-woo/trunk/frontend/checkout.php

    r2984097 r3046034  
    1919        add_filter( 'woocommerce_checkout_registration_enabled', array( $this, 'enable_and_require_registration' ) );
    2020        add_filter( 'woocommerce_checkout_registration_required', array( $this, 'enable_and_require_registration' ) );
     21        add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
     22
     23    }
     24
     25    public function enqueue_scripts() {
     26        if ( is_cart() || is_checkout() ) {
     27            wp_enqueue_script( 'subre-blocks', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_JS . 'wc-blocks/index.js', '', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION );
     28        }
     29
    2130    }
    2231
     
    2635        }
    2736        ?>
    28         <tr>
    29             <th><?php esc_html_e( 'Subscription', 'subre-product-subscription-for-woo' ) ?></th>
    30             <td></td>
    31         </tr>
     37        <tr>
     38            <th><?php esc_html_e( 'Subscription', 'subre-product-subscription-for-woo' ) ?></th>
     39            <td></td>
     40        </tr>
    3241        <?php
    3342        foreach ( WC()->cart->cart_contents as $cart_item_key => $cart_item ) {
  • subre-product-subscription-for-woo/trunk/includes/subscription-order.php

    r3031985 r3046034  
    255255        if ( $trial_period ) {
    256256            /*If trial, do not copy line product item total from order*/
    257             $total = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_item_price( $product, $product_line->get_quantity() );
     257            $total = SUBRE_SUBSCRIPTION_PRODUCT_HELPER::get_item_price( $product,['qty'=> $product_line->get_quantity()] );
     258
    258259            $clone->set_total( $total );
    259260        } else {
  • subre-product-subscription-for-woo/trunk/includes/subscription-product-helper.php

    r2991521 r3046034  
    217217    }
    218218
     219//  /**
     220//   * @param $item
     221//   * @param int $quantity
     222//   *
     223//   * @return float|string
     224//   */
     225//  public static function get_item_price( $item, $quantity = 1 ) {
     226//      return wc_get_price_to_display( $item, array( 'qty' => $quantity ) );
     227//  }
     228
     229
    219230    /**
    220231     * @param $item
    221      * @param int $quantity
     232     * @param array $args
    222233     *
    223234     * @return float|string
    224235     */
    225     public static function get_item_price( $item, $quantity = 1 ) {
    226         return wc_get_price_to_display( $item, array( 'qty' => $quantity ) );
     236    public static function get_item_price( $item, $args = [] ) {
     237        $args = wp_parse_args(
     238            $args,
     239            array(
     240                'qty'   => 1,
     241                'price' => '',
     242            )
     243        );
     244
     245        return wc_prices_include_tax()
     246            ? wc_get_price_including_tax( $item, $args )
     247            : wc_get_price_excluding_tax( $item, $args );
    227248    }
    228249
  • subre-product-subscription-for-woo/trunk/readme.txt

    r3031985 r3046034  
    153153
    1541541. Unzip the download package
    155 1. Upload `subre-product-subscription-for-woo` to the `/wp-content/plugins/` directory
     1551. Upload `woo-alidropship` to the `/wp-content/plugins/` directory
    1561561. Activate the plugin through the 'Plugins' menu in WordPress
    157157
     
    167167
    168168== Changelog ==
     169/**1.0.5 - 2024.03.06**/
     170- Updated: price html at cart/checkout blocks
    169171
    170172/**1.0.4 - 2024.02.06**/
  • subre-product-subscription-for-woo/trunk/subre-product-subscription-for-woo.php

    r3031985 r3046034  
    44 * Plugin URI: https://villatheme.com/extensions/subre-woocommerce-product-subscription/
    55 * Description: Convert WooCommerce simple products(physical or downloadable/virtual) to subscription products and allow recurring payments
    6  * Version: 1.0.4
     6 * Version: 1.0.5
    77 * Author: VillaTheme(villatheme.com)
    88 * Author URI: http://villatheme.com
     
    1717}
    1818
    19 define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.4' );
     19define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_VERSION', '1.0.5' );
    2020define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DIR', plugin_dir_path( __FILE__ ) );
    2121define( 'SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_INCLUDES', SUBRE_PRODUCT_SUBSCRIPTION_FOR_WOO_DIR . 'includes' . DIRECTORY_SEPARATOR );
Note: See TracChangeset for help on using the changeset viewer.