Skip to content

Instantly share code, notes, and snippets.

View kartikparmar's full-sized avatar

Kartik Parmar kartikparmar

  • Mumbai
View GitHub Profile
@kartikparmar
kartikparmar / functions.php
Created June 13, 2020 16:52
Change Proceed to Checkout button
<?php
function woocommerce_button_proceed_to_checkout(){
?>
<a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="checkout-button button alt wc-forward">
<?php esc_html_e( 'Proceed to Make Payment', 'woocommerce' ); ?>
</a>
<?php
}
@kartikparmar
kartikparmar / functions.php
Created June 13, 2020 16:25
Do not allow product to be purchased if particular is present in the cart.
<?php
function wc_purchasable_or_not( $product_id, $status = true ) {
// key : ID of Product where you want to hide Add to Cart.
// value : Array of Product IDs which are present in the cart then hide Add to Cart button for Product ID set in key
$product_check = array(
'2701' => array( '2848', '2563', '1253' ),
'2245' => array( '2848', '2563', '1253' ),
@kartikparmar
kartikparmar / functions.php
Created June 12, 2020 11:23
Changing pickup fields label
<?php
function orddd_change_pickup_date_label_callback(){
return __( 'New Pickup Date Label', 'order-pickup-date' );
}
add_filter( 'orddd_change_pickup_date_label', 'orddd_change_pickup_date_label_callback' );
function orddd_change_pickup_time_label_callback(){
return __( 'New Pickup Time Slot Label', 'order-pickup-date' );
@kartikparmar
kartikparmar / functions.php
Created June 6, 2020 10:58
Change Date Comparison for Advance Booking Period. Using this filter you can prepare date based on to time of the booking.
<?php
/**
* Change Date Comparison for Advance Booking Period.
* Using this filter you can prepare date based on to time of the booking.
*
* @param string $time Date and Time String
* @param string $date Date
* @param string $from From Time
* @param string $to To Time
@kartikparmar
kartikparmar / functions.php
Created May 11, 2020 14:38
Additional Information in Google Event Summary and Description
<?php
/**
* Additonal Information in Google Event Summary
*
* @param string $summary Inforation of the Google Event Summary.
* @param obj $data Prepared App data for Gcal Calculation.
*/
function bkap_google_event_summary_callback( $summary, $data ){
@kartikparmar
kartikparmar / functions.php
Created February 10, 2020 06:38
Hide products of particular categories being displayed on the Shop page only for guest users
/**
* Exclude products from a particular category on the shop page
*/
function ts_pre_get_posts_query( $q ) {
if ( ! is_user_logged_in() ) { // Hide below mentioned categories for guest user
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
@kartikparmar
kartikparmar / functions.php
Created January 28, 2020 06:40
Hide categories from shop page only for guest users.
<?php
/**
* Show products only of selected category.
*/
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
$hide_category = array();
@kartikparmar
kartikparmar / functions.php
Created December 12, 2019 07:14
Hide WooCommerce Category and its sub-categories from Shop page
<?php
/**
* Show products only of selected category.
*/
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
$hide_category = array( 126 ); // Ids of the category you don't want to display on the shop page
@kartikparmar
kartikparmar / functions.php
Created November 27, 2019 05:42
Adding free product to cart when a product is added to cart has category A or B or C
<?php
/**
* Automatically adding the product to the cart.
*/
function aaptc_add_product_to_cart( $item_key, $product_id ) {
$product_category_id = array( 16, 17, 18 ); // Category ids of A, B and C
$product_cats_ids = wc_get_product_term_ids( $product_id, 'product_cat' );
$product_category_id_check = false;
@kartikparmar
kartikparmar / functions.php
Created September 11, 2019 05:33
Removing products from a particular category on the shop page.
<?php
function hpcs_hide_products_category_shop( $query ) {
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'chairs' ), // Category slug here