Skip to content

Instantly share code, notes, and snippets.

View encoderit-arman's full-sized avatar

Arman H encoderit-arman

View GitHub Profile
function namespace_force_individual_cart_items( $cart_item_data, $product_id ) {
$unique_cart_item_key = md5( microtime() . rand() );
$cart_item_data['unique_key'] = $unique_cart_item_key;
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'namespace_force_individual_cart_items', 10, 2 );
jQuer -
jQuery('body').trigger('update_checkout');
/* to update info on your checkout page, you need to trigger the update_checkout function
so add this in your javascript file for your theme or plugin
*/
/* what this does is update the order review table but what it doesn't do is update shipping costs;
the calculate_shipping function of your shipping class will not be called again;
/** --------------Short version **/
/* WP_HTML_Compression */
function HTML_Compression($str){
$str = preg_replace('/<!--.*?-->/', '', $str);
$str = str_replace(' />', '/>', $str);
$str = preg_replace("((<pre.*?>|<code>).*?(</pre>|</code>)(*SKIP)(*FAIL)"."|\r|\n|\t)is", "", $str);
$str = preg_replace("((<pre.*?>|<code>).*?(</pre>|</code>)(*SKIP)(*FAIL)"."|\s+)is", " ", $str);
return $str;
}
function HTML_Compression_finish($html){
// inline js
<img src="https://secure.gravatar.com/avatar?d=wavatar" onload="javascript: alert('success')" onerror="javascript: alert('failure')" />
// external js
<img src="https://secure.gravatar.com/avatar?d=wavatar"/>
window.addEventListener("load", event => {
var image = document.querySelector('img');
//Saving
add_action('save_post', 'custom_save_function');
//Trashing
add_action('wp_trash_post', 'custom_trash_function');
//Restoring
add_action('untrash_post', 'custom_restore_function');
//Deleting
if (isset($_POST["data"])) {
// Get file extension
$file_extension = pathinfo($_FILES["data"]["name"], PATHINFO_EXTENSION);
// Validate file input to check if is not empty
if (!file_exists($_FILES["data"]["tmp_name"])) {
$response = array(
"type" => "error",
"message" => "File input should not be empty."
);
@encoderit-arman
encoderit-arman / Save image from any host wordpress
Last active March 2, 2022 11:07
Save image from remote url with wordpress, Save image from csv with wordpress
$post_id = wp_insert_post($array);//create new post and save its id
$img = media_sideload_image( $url, $post_id);//download image to wpsite from url
$img = explode("'",$img)[1];// extract http.... from <img src'http...'>
$attId = attachment_url_to_postid($img);//get id of downloaded image
set_post_thumbnail( $post_id, $attId );//set the given image as featured image for the post
@encoderit-arman
encoderit-arman / Php pagination
Created March 7, 2022 09:52
php pagination , wordpress pagination
<?php
$total_pages = $product_data->max_num_pages;
$current_page = (isset($_GET['page'])) ? $_GET['page'] : 1;
if ($current_page == 1) {
$prev_page = false;
} else {
$prev_page = $current_page - 1;
}
if ($current_page == $total_pages) {
https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/country-sync.html
https://intl-tel-input.com/
function extend_admin_search( $query ) {
// Extend search for document post type
$post_type = 'document';
// Custom fields to search for
$custom_fields = array(
"_file_name",
);
if( ! is_admin() )