Plugin Directory

Changeset 2517898


Ignore:
Timestamp:
04/19/2021 09:46:34 PM (5 years ago)
Author:
rspective
Message:

Committing changes for 2.1.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • voucherify/trunk/src/functions.php

    r2504530 r2517898  
    4242    $block_vouchers = is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX
    4343                                        && ! ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === "woocommerce_refund_line_items" ) );
     44
    4445    return apply_filters( 'voucherify_validation_service_block_validation', $block_vouchers );
    4546}
     
    6162     * Collects information about order and prepares portion of context data
    6263     * to be consumed by API.
    63     *
    64     * @param WC_Order $order
     64    *
     65    * @param WC_Order $order
    6566     *
    6667     * @return array order data in form of array accepted by API's context.
     
    6869    function vcrf_get_order_data( WC_Order $order = null ) {
    6970        $is_pending = ! empty( $order ) && $order->get_status() === 'pending';
    70         if ( ! vcrf_is_rest_request() && ! $is_pending
    71              && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) {
     71        if ( ! $is_pending && vcrf_is_wc_object_available() ) {
    7272            $cart_decorator = new Voucherify_Cart_Decorator( WC()->cart );
    7373
     
    167167     */
    168168    function vcrf_get_customer_data() {
    169         if ( ! vcrf_is_rest_request() && ( ! is_admin() || ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) ) ) {
     169        if ( vcrf_is_wc_object_available() ) {
    170170            $customer_decorator = new Voucherify_Customer_Decorator( WC()->customer );
    171171
     
    206206    }
    207207}
     208
     209if ( ! function_exists('vcrf_is_wc_object_available') ) {
     210    /**
     211     * Checks if the default WC() object is available
     212     *
     213     * @return bool
     214     */
     215    function vcrf_is_wc_object_available() {
     216        if ( defined( 'VCRF_FETCH_PROMOTIONS' ) && VCRF_FETCH_PROMOTIONS ) {
     217            return true;
     218        }
     219
     220        if ( vcrf_is_rest_request() || is_admin() || isset( $GLOBALS['wp']->query_vars['wc-api'] ) ) {
     221            return false;
     222        }
     223
     224        return true;
     225    }
     226}
Note: See TracChangeset for help on using the changeset viewer.