Skip to content

Instantly share code, notes, and snippets.

View hslaszlo's full-sized avatar

Laszlo Sebestyen Horvath hslaszlo

View GitHub Profile
@hslaszlo
hslaszlo / functions.php
Created December 15, 2023 11:16
Adding an attributes column to WooCommerce admin products list
<?php
function add_product_column( $columns ) {
//add column
$columns['new_column'] = __( 'New column', 'woocommerce' );
return $columns;
}
add_filter( 'manage_edit-product_columns', 'add_product_column', 10, 1 );
function add_product_column_content( $column, $postid ) {
@hslaszlo
hslaszlo / functions.php
Created December 8, 2023 17:25
Add attachment to WooCommerce custom email
<?php
// Path file = yoursite.com/wp-content/file.pdf
function action_woocommerce_order_status_changed( $order_id, $old_status, $new_status, $order ) {
// Compare
if ( $new_status == 'completed' && $order->get_payment_method() == 'dobirka' ) {
// Mailer
$mailer = WC()->mailer();
@hslaszlo
hslaszlo / functions.php
Created December 8, 2023 17:23
Show Availability Stock Status in Woocommerce Email
<?php
add_filter( 'woocommerce_display_item_meta', 'show_stock_status_in_email', 10, 3 );
function show_stock_status_in_email( $html, $item, $args ) {
// gets the product object
$product = $item->get_product();
// gets stock status product
$stock_status = $product->get_stock_status();
// show it after the product name
$html .= '<p style="margin:0;"><strong>(' . $stock_status . ')</strong></p>';
return $html;
@hslaszlo
hslaszlo / functions.php
Created November 8, 2023 10:54
WooCommerce: check if product is out of stock and doesn't allow backorders
<?php
/*
// source: https://stackoverflow.com/questions/51327748/woocommerce-check-if-product-is-out-of-stock-and-doesnt-allow-backorders
*/
add_action('woocommerce_single_product_summary','show_stock_single',5);
function show_stock_single() {
global $product;
$StockQ=$product->get_stock_quantity();
if ($StockQ>=1)//Stock is Available
@hslaszlo
hslaszlo / functions.php
Created October 5, 2023 10:29
Change Out of Stock Text in WooCommerce
<?php
add_filter('woocommerce_get_availability_text', 'themeprefix_change_soldout', 10, 2 );
/**
* Change Sold Out Text to Something Else
*/
function themeprefix_change_soldout ( $text, $product) {
if ( !$product->is_in_stock() ) {
$text = '<div class="">Sold out.</div>';
}
@hslaszlo
hslaszlo / functions.php
Created October 5, 2023 09:41
overide the settings for allowing to purchase out of stock products
<?php
// The following hooked functions will allow you to make everything purchasable:
// Change all products stock statuses to 'instock'
add_filter( 'woocommerce_product_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
add_filter( 'woocommerce_product_variation_get_stock_status', 'filter_get_stock_status_callback', 10, 2 );
function filter_get_stock_status_callback( $stock_status, $product ){
return is_admin() ? $stock_status : 'instock';
}
// Enable backorders on all products
@hslaszlo
hslaszlo / wc-delete-all-products.sql
Created June 14, 2023 12:41 — forked from twmbx/wc-delete-all-products.sql
WooCommerce Delete All Products, Product Attachments and custom Product Attributes
-- Products
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@hslaszlo
hslaszlo / robots.txt
Last active June 14, 2023 12:42
robots txt spambotok ellen
User-agent: *
Disallow: /wp-admin/
Disallow: /wp-admin/admin-ajax.php
User-agent: libwww-perl
User-agent: libwwwperl
User-agent: attach
User-agent: ASPSeek
User-agent: appie
User-agent: AbachoBOT
@hslaszlo
hslaszlo / .htaccess
Created June 14, 2023 12:39
htaccess kód spambotok ellen
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>
<Files 403.shtml>
order allow,deny
@hslaszlo
hslaszlo / add-gtm-wp.php
Created January 19, 2023 14:28 — forked from jsn789/add-gtm-wp.php
Add Google Tag Manager through functions.php in WordPress
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_head(){
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=