Skip to content

Instantly share code, notes, and snippets.

View sajidzaman's full-sized avatar
🎯
Focusing

Sajid Badi-uz-zaman sajidzaman

🎯
Focusing
View GitHub Profile
@sajidzaman
sajidzaman / functions.php
Created August 16, 2013 15:20
Woocommerce, remove data tabs
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
@sajidzaman
sajidzaman / functions.php
Created August 16, 2013 19:08
Woocommerce get_price_html() override
add_filter( 'woocommerce_get_price_html', 'my_price_html', 100, 2 );
function my_price_html( $price, $product ){
return 'Was:' . str_replace( '<ins>', ' Now:<ins>', $price );
}
@sajidzaman
sajidzaman / functions.php
Created August 19, 2013 19:53
If you want to update billing information as well on update cart button.
remove_action('init', 'woocommerce_update_cart_action'); //Remove cart update action so that billing address will be updated
add_action('init','woocommerce_update_billing'); //Hook own function to update billing address on cart update
function woocommerce_update_billing(){
global $woocommerce;
if(! empty( $_POST['update_cart'] ) && $woocommerce->verify_nonce('cart')) {
$customer_id = get_current_user_id();
$billing_data['billing_first_name' ] = $_POST['billing_first_name' ];
$billing_data['billing_last_name' ] = $_POST['billing_last_name' ];
$billing_data['billing_phone' ] = $_POST['billing_phone' ];
$billing_data['billing_email' ] = $_POST['billing_email' ];
@sajidzaman
sajidzaman / parsejson.js
Last active December 22, 2015 07:49
Parsing JSON data through jquery
/********************************** example **************************************/
var base_url = 'http://people.cs.uct.ac.za/~swatermeyer/VulaMobi/';
function example()
{
var response = "";
var form_data = {
username: username,
password: password
@sajidzaman
sajidzaman / appendinghash.js
Created September 5, 2013 15:29
Appending the URL with hash through Javascript or jquery
window.location.hash = '#edit';
@sajidzaman
sajidzaman / custom post edit message.php
Created September 11, 2013 12:59
Add a Custom message with the post insertion redirect in wordpress.
add_filter('wp_insert_post_data', 'ccl', 99);
function ccl($data) {
if ($data['post_type'] !== 'revision' && $data['post_status'] == 'publish') {
$data['post_status'] = 'draft';
add_filter('redirect_post_location', 'my_redirect_post_location_filter', 99);
}
return $data;
}
Then add a message variable in the redirect filter function.
@sajidzaman
sajidzaman / createslug.php
Created September 13, 2013 19:12
Create a slug in php from any string. A Function for creating the slug in php.
private function _createSlug($text)
{
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = strtolower($text);
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return '';
@sajidzaman
sajidzaman / uploadbuttonhide.txt
Last active December 23, 2015 04:39
hiding the upload button.
<style>
.file_button_container,
.file_button_container input {
background: transparent url(http://i.stack.imgur.com/BT5AB.png) left top no-repeat;
height: 47px;
width: 263px;
}
.file_button_container {
background: transparent url(http://i.stack.imgur.com/BT5AB.png) left top no-repeat;
@sajidzaman
sajidzaman / wordpressconfig.php
Created September 25, 2013 17:11
After server migration of the Wordpress site. add the following code in wp-config.php
<?php
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
define('WP_DEBUG', false);
define('WP_HOME', $protocol . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', $protocol . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
?>
@sajidzaman
sajidzaman / meta_key_post_id.php
Last active December 24, 2015 00:58
Get the post id from the meta key
<?php
if (!function_exists('get_post_id_by_meta_key')) {
/**
* Get post id from meta key and value
* @param string $key
* @return int|bool
* @author Sajid Zaman <sajidzaman@live.com>
*/
function get_post_id_by_meta_key($key) {
global $wpdb;