Skip to content

Instantly share code, notes, and snippets.

View Roshanb54's full-sized avatar
🏠
Working From Home

Roshan Banstola Roshanb54

🏠
Working From Home
View GitHub Profile
Step 1: Add Data in a Custom Session, on ‘Add to Cart’ Button Click
<?php
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()
{
//Custom data - Sent Via AJAX post method
$product_id = $_POST['id']; //This is product ID
$user_custom_data_values = $_POST['user_data']; //This is User custom value sent via AJAX
<?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()
{
//Custom data - Sent Via AJAX post method
$product_id = $_POST['id']; //This is product ID
$custom_data_1 = $_POST['custom_data_1']; //This is User custom value sent via AJAX
add_action( 'woocommerce_register_form_start', 'prefix_add_name_woo_account_registration' );
function prefix_add_name_woo_account_registration() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
<?php
/*
* Paginate Advanced Custom Field repeater
*/
if( get_query_var('page') ) {
$page = get_query_var( 'page' );
} else {
$page = 1;
}
// Variables
add_filter( 'rest_prepare_(post_type)', 'function_name', 10, 3 );
function function_name( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail_full = wp_get_attachment_image_src( $thumbnail_id, 'full' );
$thumbnail_thumb = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail' );
$thumbnail_medium = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
$thumbnail_large = wp_get_attachment_image_src( $thumbnail_id, 'large' );
if( ! empty($thumbnail_id) ) {
@Roshanb54
Roshanb54 / WP Customizer - Dropdown-pages
Created November 17, 2017 11:14 — forked from ajskelton/WP Customizer - Dropdown-pages
Add a Dropdown-pages field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_dropdownpages_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_dropdown_pages',
) );
$wp_customize->add_control( 'themeslug_dropdownpages_setting_id', array(
'type' => 'dropdown-pages',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Dropdown Pages' ),
'description' => __( 'This is a custom dropdown pages option.' ),
<?php
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename;
else $file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
<?php
add_shortcode( 'front_end_post_form', 'front_end_post_form' );
function front_end_post_form( $atts ) {
ob_start();?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#succes').hide();
});
@Roshanb54
Roshanb54 / file.php
Created June 27, 2017 08:30 — forked from qutek/file.php
[Wordpress] Display data with native wordpress table
<?php
/*
Plugin Name: Custom table example
Description: example plugin to demonstrate wordpress capatabilities
Plugin URI: http://mac-blog.org.ua/
Author URI: http://mac-blog.org.ua/
Author: Marchenko Alexandr
License: Public Domain
Version: 1.1
*/
@Roshanb54
Roshanb54 / wordpress-base-custom-data.php
Created June 27, 2017 07:40 — forked from paulund/wordpress-base-custom-data.php
A PHP class to handle CRUD functionality in WordPress default tables.
<?php
/**
* Abstract class which has helper functions to get data from the database
*/
abstract class Base_Custom_Data
{
/**
* The current table name
*
* @var boolean