Skip to content

Instantly share code, notes, and snippets.

View rwkyyy's full-sized avatar
🏠
Working from home

RwkY rwkyyy

🏠
Working from home
View GitHub Profile
@rwkyyy
rwkyyy / function.php
Created April 26, 2024 15:07
Translate each given string in any language, while importing, with WP All Import (via Google Translate) - path should be wp-content/uploads/wpallimport/functions.php
function translate_field_with_google($text, $target_language = 'ro') {
//usage
// [translate_field_with_google({title[1]}, "ro")] where title[1] is the string, and "ro" is the lang.
if (!empty($text)) {
$api_key = 'YOUR_GOOGLE_TRANSLATE_KEY_HERE';
$url = 'https://translation.googleapis.com/language/translate/v2?key=' . $api_key;
$data = array('q' => $text, 'target' => $target_language);
$options = array(
'http' => array(
@rwkyyy
rwkyyy / functions.php
Created February 26, 2024 19:09
ascunde alte metode când e transport gratuit + lasă sameday (și ridicare locală)
function hide_shipping_when_free_is_available( $rates, $package ) {
$new_rates = array();
$free_shipping_available = false;
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$new_rates[ $rate_id ] = $rate;
$free_shipping_available = true;
}
}
@rwkyyy
rwkyyy / file.csv
Created January 10, 2024 11:42
WooCommerce VAT TAX configuration for EU countries
Cod țară Cod județ Cod poștal Localitate Cotă % Nume taxă Prioritate Compusă Livrare Clasă de impozitare
AT 20.0000 TVA 1 0 1
BE 21.0000 TVA 1 0 1
BG 20.0000 TVA 1 0 1
CY 19.0000 TVA 1 0 1
CZ 21.0000 TVA 1 0 1
DE 19.0000 TVA 1 0 1
DK 25.0000 TVA 1 0 1
EE 20.0000 TVA 1 0 1
ES 21.0000 TVA 1 0 1
@rwkyyy
rwkyyy / functions.php
Last active November 25, 2023 15:54
allow sensei LMS users to re-purchase courses (re-take them)
// fix repurchase courses
function custom_remove_sensei_course_restriction() {
remove_action( 'woocommerce_add_to_cart', ['Sensei_WC', 'do_not_add_course_to_cart_if_user_taking_course'], 10 );
}
add_action( 'init', 'custom_remove_sensei_course_restriction', 30 );
@rwkyyy
rwkyyy / functions.php
Created November 24, 2023 18:48
Convert variation to single product (overwrite parent) - via WP CLI - WooCommerce
if (defined('WP_CLI') && WP_CLI) {
function convert_to_simple_products() {
$args = [
'status' => 'publish',
'limit' => -1,
'type' => 'variable',
];
$products = wc_get_products($args);
@rwkyyy
rwkyyy / functions.php
Created November 24, 2023 11:08
Command to clean empty images (undefined) from products gallery (WooCommerce) after they have been removed from media library
// needs to be run via cli with:
// wp cleanup-all-galleries
if (defined('WP_CLI') && WP_CLI) {
class Cleanup_All_Product_Galleries_Command {
public function __invoke($args, $assoc_args) {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
);
@rwkyyy
rwkyyy / functions.php
Last active November 23, 2023 12:15
Remove cash on delivery if any product in cart is on backorder - WooCommerce
function remove_cod_if_backorder( $available_gateways ) {
if ( !is_array( $available_gateways ) ) return;
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
if ( $product && $product->is_on_backorder( $cart_item['quantity'] ) ) {
unset( $available_gateways['cod'] );
break;
}
@rwkyyy
rwkyyy / functions.php
Created October 11, 2023 11:36
remove woocommerce tabs and add them into separate individual sections
<?php
// Asuming you have a default setup
// we remove the default tabs
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
// alternative (depending on setup):
// add_filter( 'woocommerce_product_tabs', 'my_remove_all_product_tabs', 98 );
// function my_remove_all_product_tabs( $tabs ) {
@rwkyyy
rwkyyy / functions.php
Created December 13, 2022 14:05
order notes existance indicator in listing - woocommerce
function rwk_order_notes_column( $columns ) {
$ordered_columns = array();
foreach ( $columns as $key => $column ) {
$ordered_columns[ $key ] = $column;
if ( 'order_date' == $key ) {
$ordered_columns['order_notes'] = __( 'Order notes', 'woocommerce' );
}
}
@rwkyyy
rwkyyy / functions.php
Created June 17, 2022 10:01
DEAD SIMPLE cookie notice (WordPress function)
add_action('wp_footer', 'add_cookie_notice_function');
function add_cookie_notice_function(){
$url = get_privacy_policy_url();
$link = '';
if (get_privacy_policy_url() != ''){
$link = '<a style="font-size: small; text-align: right" rel="nofollow" href="' . $url . '">Detalii</a>';
}
echo '<p id="cookie-notice">Lorem ipsum sil dolor. <br><button onclick="acceptCookie();">OK</button> ' . $link. ' </p>';
echo '<script>function acceptCookie(){document.cookie="cookieaccepted=1; expires=Thu, 18 Dec 2030 12:00:00 UTC; path=/",document.getElementById("cookie-notice").style.visibility="hidden"}document.cookie.indexOf("cookieaccepted")<0&&(document.getElementById("cookie-notice").style.visibility="visible");</script>';