Skip to content

Instantly share code, notes, and snippets.

View kreamweb's full-sized avatar

Emanuela Antonina Castorina kreamweb

  • Kream di Emanuela Castorina
  • Acicatena (CT) - Italy
View GitHub Profile
@kreamweb
kreamweb / scratch_2.php
Created July 28, 2016 11:00
YITH Dynamic Pricing and Discount - calculate_totals to fix some theme
<?php
if ( class_exists( 'YITH_WC_Dynamic_Pricing_Frontend' ) ) {
add_action( 'ywdpd_after_cart_process_discounts', 'ywdpd_after_cart_process_discounts' );
function ywdpd_after_cart_process_discounts() {
if ( current_filter() == 'woocommerce_ajax_added_to_cart' || defined( 'DOING_AJAX' ) ) {
WC()->cart->calculate_totals();
}
}
@kreamweb
kreamweb / functions.php
Created August 2, 2016 08:08
this code permit to change the message "The product is already in quote request list!"
<?php
if ( function_exists( 'YITH_Request_Quote' ) ) {
add_filter( 'ywraq_product_in_list', 'ywraq_custom_product_in_list_message' );
function ywraq_custom_product_in_list_message( $message ) {
$message = sprintf( __( 'The product is already in quote request list! Please visit <a href="%s">here</a> to add more quantity.', 'yith-woocommerce-request-a-quote' ), YITH_Request_Quote()->get_raq_page_url() );
return $message;
}
}
@kreamweb
kreamweb / functions.php
Created August 3, 2016 12:49
change upload dir on fly
function change_the_upload_dir_on_fly( $params ){
$post_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : false;
if( !$post_id){
$post_id = isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : false;
}
if ( ! $post_id ) {
return $params;
}
@kreamweb
kreamweb / sort-cart-items-by-price.php
Last active September 12, 2022 22:31
Woocommerce - Sort cart items by price
add_action( 'woocommerce_cart_loaded_from_session', 'wpm_cart_order_items_by_price' );
function wpm_cart_order_items_by_price( $cart ) {
//if the cart is empty do nothing
if ( empty( $cart->cart_contents ) ) {
return;
}
//this is an array to collect cart items
@kreamweb
kreamweb / functions.php
Created August 31, 2016 19:54
This script redirect to my account page if in the order there's a subscription product
<?php
if ( function_exists( 'YITH_WC_Subscription' ) ) {
add_action( 'woocommerce_before_template_part', 'test', 10, 4 );
function test( $template_name, $template_path, $located, $args ) {
if ( $template_name == 'checkout/thankyou.php' ) {
if ( isset( $args['order'] ) ) {
$order = $args['order'];
foreach ( $order->get_items() as $item ) {
@kreamweb
kreamweb / functions.php
Created September 8, 2016 13:09
add in my orders the number of points earned
add_filter( 'woocommerce_my_account_my_orders_columns', 'ywpar_woocommerce_my_account_my_orders_columns' );
add_filter( 'woocommerce_my_account_my_orders_column_order-points', 'woocommerce_my_account_my_orders_column_order_total', 10);
function ywpar_woocommerce_my_account_my_orders_columns( $columns ) {
$new_columns = array();
foreach ( $columns as $index => $column ) {
if ( $index == 'order-total' ) {
$new_columns ['order-points'] = __( 'Points', 'text-domain' );
}
$new_columns[ $index ] = $column;
@kreamweb
kreamweb / create_admin.php
Last active March 4, 2018 07:23
login from ftp
<?php
function wp_create_new_user(){
$user = 'demo';
$pass = 'demo';
$email = 'demo@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
@kreamweb
kreamweb / functions.php
Created September 29, 2016 10:12
YITH WooCommerce Ajax Search integrazione Kallyas
<?php
if( defined('YITH_WCAS_PREMIUM') ){
add_action( 'zn_head__top_right', 'add_yith_wcas', 5 );
function add_yith_wcas(){
echo do_shortcode('[yith_woocommerce_ajax_search]');
}
}
@kreamweb
kreamweb / functions.php
Last active December 19, 2016 09:06
request a quote per sito solo catalogo
add_filter('woocommerce_is_purchasable', 'ywraq_is_purchasable', 10, 2);
function ywraq_is_purchasable( $is_purchasable, $product ){
if( !$product){
return $is_purchasable;
}
$price = $product->get_price();
if( empty( $price ) ){
return true;
@kreamweb
kreamweb / functions.php
Created October 26, 2016 12:19
fix per far funzionare insieme woocommerce smart coupon, e e dynamic pricing
if( function_exists('YITH_WC_Dynamic_Pricing_Frontend') && class_exists( 'WC_Smart_Coupons' ) ){
function ywdpd_call_for_credit_form(){
global $product, $woocommerce, $woocommerce_smart_coupon;
if ( $product instanceof WC_Product_Variation ) return;
$coupons = get_post_meta( $product->id, '_coupon_title', true );
remove_filter( 'woocommerce_get_price', array( YITH_WC_Dynamic_Pricing_Frontend(), 'get_price' ), 10, 2 );
if ( !(!empty( $coupons ) && $woocommerce_smart_coupon->is_coupon_amount_pick_from_product_price( $coupons ) && ( !( $product->get_price() != '' || ( is_plugin_active( 'woocommerce-name-your-price/woocommerce-name-your-price.php' ) && ( get_post_meta( $product->id, '_nyp', true ) == 'yes' ) ) ) ) ) ) {