Woocommerce rest check permissions

Posted Leave a commentPosted in Tips / Recommendations
REST-API WOOCOMERCE

add_filter( 'woocommerce_rest_check_permissions', 'my_woocommerce_rest_check_permissions', 90, 4 ); function my_woocommerce_rest_check_permissions( $permission, $context, $object_id, $post_type ){ return true; }

редирект со страницы на страницу

RewriteCond %{QUERY_STRING} ^_route_=login/$
RewriteRule ^(.*)$ http://liga-spice.com.ua/? [R=301,L]

Set a cookie and close a popup after Contact Form 7 form is submitted.

Posted Leave a commentPosted in Tips / Recommendations
<?php
// As is this will check if the form is in a popup, if so set a cookie and close after 5 seconds.

// Copy everything below this line.
function custom_cf7_scripts() { ?>
	<script type="text/javascript">
		var wpcf7Elm = document.querySelector('.wpcf7');

		wpcf7Elm.addEventListener('wpcf7submit', function (event) {
			var $form = $(event.target),
				$popup = $form.parents('.pum');

			if (!$popup.length) {
				return;
			}
			
			$popup.trigger('pumSetCookie');

			setTimeout(function () {
				$popup.popmake('close');
			}, 5000);
		}, false);
	</script><?php
}

add_action( 'wp_footer', 'custom_cf7_scripts' );

Liqpay payment widget

Posted Leave a commentPosted in Tips / Recommendations
$liqpay = new LiqPay($public_key, $private_key);
$html = $liqpay->cnb_form(array(
'action'         => 'pay',
'amount'         => '1',
'currency'       => 'USD',
'description'    => 'description text',
'order_id'       => 'order_id_1',
'version'        => '3'
));
Payment widget options
dataRequiredStringjson string with APIs parameters is encoded by the base64_encode( json_string ) function , where base64_encode – returns a string encoded by the base64 method
signatureRequiredStringUnique signature of each request base64_encode( sha1( private_key + data + private_key) ) , where sha1 is a returned hash in the form of a binary string of 20 characters .
embedToOptionalStringThe element on the HTML page in which the widget will be displayed
modeOptionalStringWidget display mode on the site Possible values embed – built-in window popup – pop-up window on your site .
languageOptionalStringWidget display language ru , uk , en .
  <div id="liqpay_checkout"></div>
  <script>
	window.LiqPayCheckoutCallback = function() {
		LiqPayCheckout.init({
			data: "eyAidmVyc2lvbiIgOiAzLCAicHVibGljX2tleSIgOiAieW91cl9wdWJsaWNfa2V5IiwgImFjdGlv" +
			"biIgOiAicGF5IiwgImFtb3VudCIgOiAxLCAiY3VycmVuY3kiIDogIlVTRCIsICJkZXNjcmlwdGlv" +
			"biIgOiAiZGVzY3JpcHRpb24gdGV4dCIsICJvcmRlcl9pZCIgOiAib3JkZXJfaWRfMSIgfQ==",
			signature: "QvJD5u9Fg55PCx/Hdz6lzWtYwcI=",
			embedTo: "#liqpay_checkout",
			language: "ru",
			mode: "embed" // embed || popup
		}).on("liqpay.callback", function(data){
			console.log(data.status);
			console.log(data);
		}).on("liqpay.ready", function(data){
			// ready
		}).on("liqpay.close", function(data){
			// close
		});
	};
  </script>
  <script src="//static.liqpay.ua/libjs/checkout.js" async></script>
Parameters for forming data :
The main ones
ParametersRequiredTypeDescription
versionRequiredNumberAPI version. The current value is 3
public_keyRequiredStringThe public key is the store identifier. You can get the key in the store settings
actionRequiredStringType of operation. Possible values pay – payment , hold – blocking funds on the sender’s account , subscribe – regular payment , paydonate – donation , auth – pre- authorization of the card
amountRequiredNumberPayment amount. For example 5 , 7.34
currencyRequiredStringPayment currency. Possible values USD , EUR , UAH
descriptionRequiredStringPurpose of payment .
order_idRequiredStringUnique purchase ID in your store. The maximum length is 255 characters .
expired_dateOptionalStringThe time by which the client can pay the bill in UTC . Transmitted in 2016-04-24 00:00:00 format
languageOptionalStringClient language ru , uk , en
paytypesOptionalStringThe parameter that transmits the payment methods that will be displayed at the checkout. Possible values ​​apay – payment using Apple Pay , gpay – payment using Google Pay , card – payment by card , liqpay – through the liqpay account , privat24 – through the privat24 account , masterpass – through the masterpass account , moment_part – installment , cash – cash , invoice – bill to e-mail , qr – QR code scanning. If the parameter is not passed, then the store settings, Checkout tab are applied .
result_urlOptionalStringThe URL in your store to which the buyer will be redirected after completing the purchase. The maximum length is 510 characters .
server_urlOptionalStringAPI URL in your store for notifications about the change of payment status server -> server ). The maximum length is 510 characters . More details
verifycodeOptionalStringA possible value of Y . Dynamic verification code, generated and returned in Callback . Similarly, the generated code will be transferred in the verification transaction for display in the client’s card statement. Works for action = auth .
Payment splitting options
split_rulesOptionalStringPayment with splitting the amount to several recipients. This parameter specifies a JSON array with payment splitting rules. When using the split_rules parameter, there is one debit from the client and several credits to the recipients. The acquiring fee is charged to each store in the split_rules array . Example JSON string :
 

Payment with splitting the amount to several recipients. This parameter specifies a JSON array with payment splitting rules. When using the split_rules parameter, there is one debit from the client and several credits to the recipients. The acquiring fee is charged to each store in the split_rules array . Example JSON string 

[
  {
    "public_key": "i000000001",
    "amount": 1,
    "commission_payer": "sender",
    "server_url": "https://server1/callback"
  },
  {
    "public_key": "i000000002",
    "amount": 2,
    "commission_payer": "receiver",
    "server_url": "https://server2/callback"
  }
]
Sender settings
sender_address NEWOptionalStringSender’s address
sender_cityOptionalStringSender’s city
sender_country_codeOptionalStringCountry code of the sender. Digital ISO 3166-1 code
sender_first_nameOptionalStringName of the sender
sender_last_nameOptionalStringSender’s last name
sender_postal_codeOptionalStringPostal code of the sender
Secure payment options
letter_of_creditOptionalStringTo enable the acceptance of payments by letter of credit, pass the parameter with the value 1
letter_of_credit_dateOptionalStringLetter of credit expiration date in the following format : 2015-03-31 00:00:00 UTC .
Regular payment options
subscribeOptionalStringRegular payment. Possible values 1
subscribe_date_startOptionalStringDate of first payment. The time must be specified in the following format : 2015-03-31 00:00:00 UTC . If an expired date is specified, the subscription will be activated from the current date of receipt of the request
subscribe_periodicityOptionalStringPeriodicity of withdrawal of funds. Possible values :
month – once a month year – once a year
Options for payment in 1 click
customerOptionalStringThe unique identifier of the client on the merchant’s website. When transferring the parameter, LiqPay remembers the client’s payment details and his identifier – further payment can be made in 1 click. The maximum length is 100 characters . ( When using the parameter for <b>Masterpass 1 click</b>, the valid phone number of the payer is transferred in this field )
recurringbytokenOptionalStringAllows you to generate the payer’s card_token , which you will receive in the callback request to server_url . card_token allows you to make payments without entering the details of the payer’s card, using the token payment API – that is, in 1 click. To receive a card_token , you must pass the following values ​​in the request : 1
customer_user_idOptionalStringUser ID in the merchant system, transmitted at each user payment (must not match customer , used for payment using the <b>Masterpass 1 click</b> wallet )
Other parameters
daeOptionalStringLong entry Detail Addenda .
The dae parameter is a JSON string to which the base64 function has been applied . JSON can contain the following parameters :
 
{
  "airLine": "Avia", // абревіатура авіакомпанії, max 4 символів.
  "ticketNumber": "ACSFD12354SA", // номер квитка, max 15 символів. 
  "passengerName": "John Doe", // ім'я пасажира, max 29 символів.
  "flightNumber": "742", // номер рейсу, max 5 цифр.
  "originCity": "DP", // код міста/аеропорту вильоту, max 5 символів.
  "destinationCity": "NY", // код міста/аеропорту призначення, max 5 символів.
  "departureDate": "100514" // дата вильоту в форматі YYMMDD, max 6 цифр.
}

How to Hide Posts or Pages from the WordPress Admin

Posted Leave a commentPosted in Tips / Recommendations
function true_hide_pages_from_admin( $query ) {
	global $pagenow;
	if( is_admin() && 'edit.php' == $pagenow && 'page' == get_query_var('post_type') ){
		// в качестве 'page' в условии можно указать любой произвольный тип постов
		$query->set( 'post__not_in', array(300,271) ); 
		// через запятую прописываем ID страниц, которые хотим скрыть
	}
	return $query;
}
 
add_action( 'pre_get_posts' ,'true_hide_pages_from_admin' );
function true_hide_posts_from_admin( $query ) {
	global $pagenow;
	if( is_admin() && 'edit.php' == $pagenow ){
		$query->set( 'post__not_in', array(9,54) ); 
		// через запятую указываем ID постов или страниц, которые хотим скрыть
	}
	return $query;
}
 
add_action( 'pre_get_posts' ,'true_hide_posts_from_admin' );
function true_hide_all( $query ) {
	$query->set( 'post__not_in', array(300,271) ); 
	return $query;
}
 
add_action( 'pre_get_posts' ,'true_hide_all' ); 

Change photo in url

Posted Leave a commentPosted in Tips / Recommendations
<meta name="viewport" content="width=device-width, initial-scale=1">
   <meta property="og:image" content="https://onmywaystudio.net/wp-content/uploads/2018/05/cropped-download-1-1.png;" />
<meta property="og:image:secure_url" content="https://onmywaystudio.net/wp-content/uploads/2018/05/cropped-download-1-1.png"; />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="400" />
<meta property="og:image:height" content="300" />
<meta property="og:image:alt" content="" />

Adding consent to the WooCommerce Privacy Policy

Posted Leave a commentPosted in Tips / Recommendations
// Добавление чекбокса
add_action( 'woocommerce_review_order_before_submit', 'truemisha_privacy_checkbox', 25 );
 
function truemisha_privacy_checkbox() {
 
	woocommerce_form_field( 'privacy_policy_checkbox', array(
		'type'          => 'checkbox',
		'class'         => array( 'form-row' ),
		'label_class'   => array( 'woocommerce-form__label-for-checkbox' ),
		'input_class'   => array( 'woocommerce-form__input-checkbox' ),
		'required'      => true,
		'label'         => 'Принимаю <a href="' . get_privacy_policy_url() . '">Политику конфиденциальности</a>',
	));
 
}
 
// Валидация
add_action( 'woocommerce_checkout_process', 'truemisha_privacy_checkbox_error', 25 );
 
function truemisha_privacy_checkbox_error() {
 
	if ( empty( $_POST[ 'privacy_policy_checkbox' ] ) ) {
		wc_add_notice( 'Ваш нужно принять политику конфиденциальности.', 'error' );
	}
 
}
// Добавление чекбокса
add_action( 'woocommerce_register_form', 'truemisha_registration_privacy_checkbox', 25 );
 
function truemisha_registration_privacy_checkbox() {
 
	woocommerce_form_field(
		'privacy_policy_reg',
		array(
			'type'          => 'checkbox',
			'class'         => array( 'form-row' ),
			'label_class'   => array( 'woocommerce-form__label-for-checkbox' ),
			'input_class'   => array( 'woocommerce-form__input-checkbox' ),
			'required'      => true,
			'label'         => 'Принимаю <a href="' . get_privacy_policy_url() . '">Политику конфиденциальности</a>',
		)
	);
 
}
 
// Валидация
add_filter( 'woocommerce_registration_errors', 'truemisha_registration_privacy_checkbox_error', 25 );
 
function truemisha_registration_privacy_checkbox_error( $errors ) {
 
	if( is_checkout() ) {
		return $errors;
	}
 
	if ( empty( $_POST[ 'privacy_policy_reg' ] ) ) {
		$errors->add( 'privacy_policy_reg_error', 'Ваш нужно принять политику конфиденциальности.' );
	}
 
	return $errors;
 
}