Re-write this script in .php supported by WordPress

code API

BANNED - Failed to resolve a dispute
Joined
Oct 20, 2018
Messages
6,377
Reaction score
3,517
Hey guys, this blade file is incompatible with my WordPress PHP. I need help converting it to a PHP file that is compatible with WordPress:

PHP:
@php global $product, $post; @endphp

@php
  $quantites_required      = false;
  $previous_post           = $post;
@endphp

<div class="purchase">

  <div class="prices">

<form class="cart grouped_form"
      action="@php esc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); @endphp"
      method="post"
      enctype='multipart/form-data'
      x-data="{product: '2370'}" >
  <div>
    @foreach ( $grouped_products as $key => $grouped_product_child )
      @php
        $post_object        = get_post( $grouped_product_child->get_id() );
        $quantites_required = $quantites_required || ( $grouped_product_child->is_purchasable() && ! $grouped_product_child->has_options() );
        $post               = $post_object;
        setup_postdata( $post );
      @endphp

      <div class="form-groups grouped-product-item" data-product="@php echo $grouped_product_child->get_id(); @endphp">
        @if (! $grouped_product_child->is_purchasable() || $grouped_product_child->has_options() || ! $grouped_product_child->is_in_stock())
          @php woocommerce_template_loop_add_to_cart(); @endphp
        @else ( $grouped_product_child->is_sold_individually() )
          <input type="checkbox" id="@php echo $grouped_product_child->get_id() @endphp" name="quantity[@php echo $grouped_product_child->get_id() @endphp]" value="1"
                 on:click="product = @php echo $grouped_product_child->get_id() @endphp" @if ($key == 0) checked @endif>
        @endif
        <label for="@php echo $grouped_product_child->get_id() @endphp"
               @click="$dispatch('productchange', {product: '@php echo $grouped_product_child->get_id() @endphp'})"
        >
          <span class="detail">
            <div class="cost">
              <h3><span>₹</span>
              @php echo \WC_Subscriptions_Product::get_price_string($grouped_product_child); @endphp
              </h3>
            </div>

          <div class="extra">
            @if(App\Product::inclusiveOfAllClasses($grouped_product_child->get_id()))
              <div class="class">
              <span>Inclusive of All Classes</span>
            </div>
            @endif
            @if( App\Product::savePercentage($grouped_product_child->get_id()) )
              <div class="save">
              Save {{ App\Product::savePercentage($grouped_product_child->get_id()) }}%
            </div>
            @endif
          </div>
          </span>
        </label>
      </div>

    @endforeach
  </div>

<input type="hidden" name="add-to-cart" value="@php echo esc_attr( $product->get_id() ); @endphp" />

  <div x-data="{product: '1'}"
       @productchange.window="product = $event.detail.product"
       x-init=" product = $store.application.product"
       x-subscribe>
  @foreach ( $grouped_products as $key => $grouped_product_child )
    <div x-show.transition.in="product == {{ $grouped_product_child->get_id() }}">
      @if($quantites_required)
        @if(\App\CartValidation::isCurrentProductInCart(intval($grouped_product_child->get_id())))
          <div class="pricing-information">
            <a href="javascript:void(0)" class="crush-button crush-button-gradient cart-open">
              View Cart
            </a>
            <div class="help-text">
              <img src="@asset('images/caution.svg')" alt="Caution">
              <h6>Product already added to the cart.</h6>
            </div>
          </div>
        @else
          <button type="submit" class="hide-on-mobile actual-submit">Subscribe Now</button>
        @endif
      @endif
    </div>
  @endforeach
  </div>

</form>
  </div>
</div>
 
Never mind.
I just pasted it into my custom ChatGPT assistant, haha. Problem solved! Amazing with GPT4 can do.
 
Back
Top