This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** --------------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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { | |
if ($cart_item['product_id'] == $product_id) { | |
WC()->cart->remove_cart_item($cart_item_key); | |
break; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function display_product_review($product_id) { | |
$product = wc_get_product( $product_id ); | |
$comments = get_approved_comments( $product->id ); | |
$product_link = '/product/' . $product->post->post_name . "/#tab-reviews/"; | |
if ( !empty ($comments) ) { | |
echo $comments[0]->comment_content . '<br><a href="'. $product_link . '">Read more reviews...</a>'; | |
} else { |