Saturday, 28 October 2017

CORS header 'Access-Control-Allow-Origin' missing

ERROR : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.SOMEURL  (Reason: CORS header 'Access-Control-Allow-Origin' missing).


.
When the code send the request, you shall have a "200 OK" response code in your browser console, which means that the resource is accessed, but it does not grant the right to share that resource. It does this by not allowing "Access-Control-Allow-Origin".


To change that, you have to write this in the .htaccess of the requested domain file (notyourdomain.com):

Add following code to your .HTACCESS file

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

Thursday, 12 October 2017

WooCommerce CHEKCKOUT FIELDS PLAY GROUND

// Billing Fields.
add_filter( 'woocommerce_billing_fields' , 'woocommerce_billing_fields_custom' );
function woocommerce_billing_fields_custom( $fields ) {

$fields['billing_phone']['required'] = false;
$fields['billing_phone']['maxlength'] = 10;
$fields['billing_state']['class'] = array( 'form-row-first' );
$fields['billing_postcode']['maxlength'] = 4;
$fields['billing_postcode']['class'] = array( 'form-row-last' );

//Order Billing fields
$fields['billing_email']['priority'] = 33;
$fields['billing_phone']['priority'] = 37;
$fields['billing_country']['priority'] = 100;

return $fields;

}



// Shipping Fields.

add_filter( 'woocommerce_shipping_fields' , 'woocommerce_shipping_fields_custom' );

function woocommerce_shipping_fields_custom( $fields ) {

$fields['shipping_state']['class'] = array( 'form-row-first' );
$fields['shipping_postcode']['maxlength'] = 4;
$fields['shipping_postcode']['class'] = array( 'form-row-last' );

//Order Shipping fields
$fields['shipping_country']['priority'] = 100;
$fields['shipping_country']['priority'] = 100;

return $fields;
}

// ----------- CHANGE FIELDS PRIORITY EN ------



// ----------- UNSET CHECKOUT FIELDS ST ------
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {

/*
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_email']);
unset($fields['account']['account_username']);
unset($fields['account']['account_password']);
unset($fields['account']['account_password-2']);
*/

unset($fields['billing']['billing_phone']);
unset($fields['shipping']['shipping_phone']);
unset($fields['order']['order_comments']);

unset($fields['billing']['billing_email']);
unset($fields['shipping']['shipping_email']);
unset($fields['billing']['billing_state']);
unset($fields['shipping']['shipping_state']);


return $fields;
}
// ----------- UNSET CHECKOUT FIELDS EN ------

PHP Pinterest RSS Feed PARSING

class XmlToJson {
  public function Parse( $url ) {
    $fileContents = file_get_contents( $url );
    $fileContents = str_replace( array(
      "\n",
      "\r",
      "\t"
    ), '', $fileContents );
    $fileContents = trim( str_replace( '"', "'", $fileContents ) );
    $simpleXml = simplexml_load_string( $fileContents );
    $json = json_encode( $simpleXml );
    return $json;
  }
}

function viral_pinterest() {
  $xml   = new XmlToJson;
  $feed  = json_decode( $xml->Parse( "https://www.pinterest.com/codifyclub/feed.rss/" ) );
  $items = $feed->channel->item;
  foreach( $items as $item ) :
 
   // print_r($item);
   if(is_string($item->title)) echo $item->title;
    echo '<br/>';
   
    echo $item->link;
    echo '<br/>';
 
    $doc = new DOMDocument();
    @$doc->loadHTML($item->description);
    $img_tags = $doc->getElementsByTagName('img');
    foreach ($img_tags as $img_tag) {
       echo $img_path = $img_tag->getAttribute('src');
    }
   

  endforeach;
}

viral_pinterest();