Skip to content

Instantly share code, notes, and snippets.

😃
Focusing

Rey Den Nalasa raiden808

😃
Focusing
Block or report user

Report or block raiden808

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Simple WP Ajax
function cb_related_ajax()
{
$sample_ajax = $_POST['hello'];
echo $sample_ajax;
wp_die();
}
@raiden808
raiden808 / functions.php
Created Sep 24, 2018
Hide featured image on specific products
View functions.php
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 Sep 6, 2018
Find user by role and meta.
View find_by_role_and_meta.php
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 Aug 17, 2018
Add tax on cart total depending on category
View woo_functions.php
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
View export to csv using WordPress
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');
View Execute function when page is fully loaded
<script type="text/javascript">
jQuery(document).ready(function ($) {
$(window).load(function() {
alert("I'm done loading!");
});
});
</script>
View Saving JSON to WordPress custom table
<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);
View WordPress Option Page
// 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
View localize_script.php
<?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 Apr 22, 2018
Enqueue script if it has shortcode
View functions.php
<?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 );
You can’t perform that action at this time.