Skip to content

Instantly share code, notes, and snippets.

View Piyushhp94's full-sized avatar

Piyush Patel Piyushhp94

View GitHub Profile
@Piyushhp94
Piyushhp94 / functions.php
Created April 3, 2024 06:44
Addon Product add to cart based on the other product category product is there into cart.
<?php
/**
* Function check validation of add to cart notice based on product categories
*/
function sample_add_to_cart_validation( $passed, $product_id, $quantity, $variation_id = '', $variation = '' ) {
// Check if the cart is empty
if( WC()->cart->is_empty() ) {
// If cart is empty, prevent adding accessories
if( has_term( 'accessories', 'product_cat', $product_id ) ) {
wc_add_notice(__('You cannot add accessories to an empty cart.', 'your-text-domain'), 'error');
@Piyushhp94
Piyushhp94 / class-product-transfer.php
Created October 6, 2023 06:52
WooCommerce Product Transfer From One Website to Another Website
<?php
/**
* Product Transfer Class File
*
* @package WDM - WC Product Transfer
* @since 1.0
*/
if( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
@Piyushhp94
Piyushhp94 / create-zoom-meeting.php
Last active March 30, 2023 07:56
Create a Zoom Meeting using API in WordPress
<?php
/*
* Function to create a Zoom Meeting
*/
function sample_create_zoom_meeting_proccess() {
// Taking some variables
$host_user = "host_user_email" // Get email from zoom meeting
$client_id = 'client_id';
$client_secret = 'client_secret';
@Piyushhp94
Piyushhp94 / authentication-shrt.php
Last active March 24, 2023 04:51
WooCommerce Authentication and stored json data using Website URL
<?php
/**
* 'sample_authentication' Shortcode
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
function sample_authentication_shrt_render( $atts, $content = null ) {
@Piyushhp94
Piyushhp94 / class-cust-woo-email.php
Created March 2, 2023 05:40
Create Custom WooCommerce Email for Custom Action to trigger Email
<?php
/**
* Custom Email Class
*
* @package Custom WooCommerce Email
* @since 1.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
@Piyushhp94
Piyushhp94 / functions.php
Created February 20, 2023 04:55
Change WooCommerce Payment Gateway Ordering on Checkout Page
<?php
// Filter to change the WooCommerce Payment Gateway Ordering
add_filter( 'woocommerce_available_payment_gateways', 'sample_available_payments' );
/*
* Function to check available payment method then change the ordering
*/
function sample_available_payments( $available_gateways ) {
// Taking some variables
@Piyushhp94
Piyushhp94 / function.php
Last active February 20, 2023 04:56
Course completed manually for particular user using custom code
<?php
// Taking some variables
$user_id = 1;
$course_id = 156;
$course_complete_date = current_time( 'timestamp' );
// Function to complete course process
learndash_process_mark_complete( $user_id, $course_id );
// Complete course to user meta
@Piyushhp94
Piyushhp94 / functions.php
Last active March 24, 2023 07:36
Generate Zoom Access Token & Get Meeting Poll Data in WordPress
<?php
/*
* Follow Below steps:
* Create a `Server-To-Server OAuth` from here: https://marketplace.zoom.us/develop/create
* In that app defin this scopes: https://prnt.sc/VR5W952Xmo--
*/
// Get Meeting poll data on WordPress `init` action
add_action( 'init', 'sample_zoom_meeting_proccess_data' );
@Piyushhp94
Piyushhp94 / .htaccess
Created November 11, 2022 05:32
Remove .php extension from URL in php website using .htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L,NE]
@Piyushhp94
Piyushhp94 / class-sample-wc-coupon-fields.php
Created September 21, 2022 06:51
Add & Save Custom Field in WooCommerce Coupon
<?php
/**
* WooCommerce Coupon Custom Field Class File
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Sample_WC_Coupon_Custom_Fields {