There is such a code found on the Internet.

There is a payment.php template and on the basis of it are the checkout and checkout / order-pay pages.

It is necessary that block a is hidden on one page and block b appears, and on the second vice versa.

It works on checkout, but not on checkout / order-pay.

Thank you in advance.

$(function(){ var p = location.pathname; if(p.indexOf('order-pay') != -1) { $('li.payment_method_cheque').hide(); $('div#wcpgsk-dialog-validation-errors').hide(); } }); $(function(){ var url = window.location.href; if (url.indexOf('checkout') > -1) { $('li.payment_method_kassa').hide(); $('div#wcpgsk-dialog-validation-errors').hide(); } }); 
  • This is all because checkout / order-pay is suitable for the condition url.indexOf ('checkout')> -1 - Grundy

3 answers 3

If the page address ends exactly as checkout or checkout / order-pay, then this option will work. If not, you need to fix regular expressions.

 $ (document) .ready (function () {

     var pathname = window.location.pathname;

     if (/(.*)checkout$/.test(pathname)) {

         // open hiding blocks on the page with the address "checkout"

         $ ('li.payment_method_cheque'). hide ();
         $ ('div # wcpgsk-dialog-validation-errors'). hide ();

     } else if (/(.*)checkout\/order-pay\/\d+\?(.*)/.test(pathname)) {

         // open hiding blocks on the page with the address "checkout / order-pay"

         $ ('li.payment_method_cheque'). hide ();
         $ ('div # wcpgsk-dialog-validation-errors'). hide ();

     }

 });
  • where checkout / order-pay further I go to arbitrary data in the form of an order number key, etc. example below. https: //***.ru/checkout/order-pay/102173? pay_for_order = true & key = wc_order_57b4b4f76b147 - Aleksey Averin
  • corrected regular season - Almaz V.

Since the condition url.indexOf ('checkout')> -1 will be satisfied for both pages, you should combine two conditions and add an additional check, for example:

 $(function() { var p = "/checkout/order-pay/102173/?pay_for_order=true&key=wc_order_57b4b4f76b147", isOrderPay = p.indexOf('order-pay') != -1, isCheckout = p.indexOf('checkout') != -1; $('li.payment_method_cheque').toggle(!isOrderPay); // скрыть если на OrderPay $('li.payment_method_kassa').toggle(!isCheckout || isOrderPay); // скрыть если на Checkout и не на OrderPay $('div#wcpgsk-dialog-validation-errors').toggle(!isCheckout && !isOrderPay); // скрыть если на Checkout или на OrderPay }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li class="payment_method_cheque">cheque</li> <li class="payment_method_kassa">kassa</li> </ul> 

  • @AlekseyAverin, and where on this page to look for the code? - Grundy
  • @AlekseyAverin, updated the answer - everything works - only kassa remains - Grundy

Here is the solution.

 $(function(){ var p = location.pathname; if(p.indexOf('checkout/order-pay') > -1) { jQuery('li.payment_method_cheque').hide(); jQuery('div#wcpgsk-dialog-validation-errors').hide(); jQuery('.payment_method_cheque').hide(); } }); $(function(){ var url = window.location.href; if (url.indexOf('checkout') > -1) { jQuery('li.payment_method_kassa').hide(); jQuery('div#wcpgsk-dialog-validation-errors').hide(); } });