Skip to content

Instantly share code, notes, and snippets.

function cb_related_ajax()
{
$sample_ajax = $_POST['hello'];
echo $sample_ajax;
wp_die();
}
@raiden808
raiden808 / functions.php
Created September 24, 2018 01:42
Hide featured image on specific products
add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 3);
//hides featured image progmatically
function remove_featured_image($html, $attachment_id, $post_id) {
$featured_image = get_post_thumbnail_id($post_id);
$filtered_products = array(271479);
if(in_array($post_id, $filtered_products)){
@raiden808
raiden808 / find_by_role_and_meta.php
Created September 6, 2018 08:45
Find user by role and meta.
function find_hero_ability($ability){
$args = array(
'role' => 'hero',
'meta_query' => array(
array(
'key' => 'ability',
'value' => $ability,
'compare' => 'LIKE'
)
)
@raiden808
raiden808 / woo_functions.php
Last active August 17, 2018 11:58
Add tax on cart total depending on category
function woocommerce_custom_tax() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$flowers_in_cart = false;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
//check if there's a product under flowers category
function export_to_csv(){
//will trigger when export_test isset as get variable
if(isset($_GET['export_test'])){
$file_name = 'csv_file'."_".date("Y-m-d").'.csv';
header('Content-Type: application/csv');
header("Content-Disposition: attachment; filename=".$file_name."");
header('Pragma: no-cache');
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(window).load(function() {
alert("I'm done loading!");
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(".btn_schedule").click(function() {
var selected_id = 1;
var schedule = {"Monday":{"morning":"8:00 am","afternoon":"1:00 pm"},
"Tuesday":{"morning":"8:00 am","afternoon":"1:00 pm"}};
var myJSON = JSON.stringify(schedule);
save_clinic_schedule(selected_id,myJSON);
// create custom plugin settings menu
add_action('admin_menu', 'rda_create_menu');
function rda_create_menu() {
//create new top-level menu
add_menu_page('RDA Plugin Settings', 'RDA Settings', 'administrator', __FILE__, 'rda_settings_page'
,'dashicons-carrot');
//call register settings function
<?php
function enqueu_this_scipt(){
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
$translation = array(
'greetings'=> 'Hellow world!'
);
wp_localize_script( 'script-name', 'my_handler', $translation );
@raiden808
raiden808 / functions.php
Last active April 22, 2018 22:00
Enqueue script if it has shortcode
<?php
function enqueu_this_scipt(){
global $post;
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'awesome_shortcode') ) {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );