Code Snippets

Woocommerce get order and items in order

 

SOAP example

 

WordPress check if user has role

 

Force WordPress media library to use HTTPS

 

Change a searchbar return key iOS objective C

 

MySQL Timestamp in PHP

 

Check if current user has role in WordPress

 

Woocommerce change quantity of product in cart

 

Javascript formatted valuta with a comma as decimal seperator

 

Get posts meta compare WordPress

 

Get price of product in Woocommerce

if( $product->is_type( 'variable' ) ){
				$available_variations = $product->get_available_variations();
				}
				else {
				
				}
				$regularprice = $available_variations[0]['display_regular_price'];
					
				if (!empty( $regularprice)	){
					
				}
				else {
					$regularprice = $product->regular_price;
				}
					$from = $regularprice;
			        $to = $product->price;
			   if ( $product->price > 0 ) {
			      if ( $from <> $to ) {
			       
			        echo '
'.( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) .'
van '. ( ( is_numeric( $from ) ) ? woocommerce_price( $from ) : $from ) .'
' ; } else { $to = $product->price; echo '
' . ( ( is_numeric( $to ) ) ? woocommerce_price( $to ) : $to ) . '
'; } } else { //NO PRICE }

Nonce in an AJAX request WordPress



var data = {
		action: 'my_action',
		security: '',
		my_string: 'Hello World!'
	};
	$.post(ajaxurl, data, function(response) {
		alert("Response: " + response);
	});




/*AND IN AJAX.php FILE*/
	check_ajax_referer( 'my-special-string', 'security' );