Skip to content

Instantly share code, notes, and snippets.

View mohammadmursaleen's full-sized avatar

Mohammad Mursaleen mohammadmursaleen

View GitHub Profile
@mohammadmursaleen
mohammadmursaleen / wp_ajax_code.php
Last active September 6, 2016 05:52
WordPress Ajax code to add emails in post meta with postid in front end
<?php
/********************************************************************************/
/*** WordPress Ajax code to add emails in post meta with postid in front end ***/
/********************************************************************************/
add_action( 'wp_footer', 'my_action_javascript' );
function my_action_javascript() { ?>
<script type="text/javascript" >
@mohammadmursaleen
mohammadmursaleen / gist:9622098e43afdab6025e
Last active October 15, 2021 18:29
Adding custom fields above WOOCOMMERCE add to cart button
<?php
// To add custom data above add to cart button in woocommerce
// step 1
add_action('wp_ajax_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
add_action('wp_ajax_nopriv_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
function wdm_add_user_custom_data_options_callback()
@mohammadmursaleen
mohammadmursaleen / functions.php
Last active September 6, 2016 05:51
To make sub items of bundle product manageable in cart in WooCommerce
<?php
/**
* @author Mohammad Mursaleen
* @usage to make sub items of bundle product manageable in cart
*/
function mm_make_sub_items_manageable_in_cart(){
if( function_exists( 'WC_PB' ) )
remove_filter( 'woocommerce_cart_item_quantity', array( WC_PB()->cart , 'woo_bundles_cart_item_quantity' ), 10, 2 );
@mohammadmursaleen
mohammadmursaleen / functions.php
Created September 6, 2016 05:55
Function to allow users to manage their profiles from back-end in WooCommerce
<?php
/**
* @author Mohammad Mursaleen
* @usage Allow other user roles to access admin area to manage their profiles from dashboard - WooCommerce Quick fix
*/
add_filter( 'woocommerce_prevent_admin_access', 'objects_woocommerce_login_redirect_fix' , 20 , 1 );
function objects_woocommerce_login_redirect_fix($prevent_access){
$prevent_access = false;
<?php
/**
* @author Mohammad Mursaleen
* @usage function to get unique transient key
* @return string: transient key
*/
function objects_get_transient_identifier( $key = '' ){
return $key . '_' . objects_get_ip_address();
<?php
/**
* @author Mohammad Mursaleen
* @usage function to get unique transient key
* @return string: transient key
*/
function objects_get_transient_identifier( $key = '' ){
return $key . '_' . objects_get_ip_address();
@mohammadmursaleen
mohammadmursaleen / post_response.php
Created September 7, 2016 07:22
Send Post Request to URL and get response using PHP
<?php
/**
* @author : Mohammad Mursaleen
* @usage : Send Post Request to URL and get response using PHP
*/
$url = 'URL';
$data = array('field1' => 'value', 'field2' => 'value');
$options = array(
@mohammadmursaleen
mohammadmursaleen / google_cse_xml_parsed.php
Created September 9, 2016 12:58
PHP based Google CSE XML Parsed Reponse
<?php
$no_result = true;
// Getting XML Response
if(isset($_GET['q'])){ // Assuming we have got some search query by get method at q index
$query = $_GET['q'];
@mohammadmursaleen
mohammadmursaleen / display_variations_with_prices.php
Created September 15, 2016 11:15
WooCommerce funciton to get prices of all variations on single product page
<?php
add_action('woocommerce_before_single_product','mm_display_variations_with_prices');
function mm_display_variations_with_prices(){
global $product,$woocommerce;
$variations = $product->get_available_variations();
@mohammadmursaleen
mohammadmursaleen / redirect_media_page_to_media_file.php
Created September 22, 2016 10:19
WordPress function to redirect to attachment url from attachment page url
<?php
/**
* @author Mohammad Murslaeen
* @function to redirect to attachment url from attachment page url
*/
function mm_media_page_url_to_attachment_url(){
if( 'attachment' != get_post_type( get_the_ID() ) )
return;