Skip to content

Instantly share code, notes, and snippets.

@bagerathan
bagerathan / change-string.php
Last active August 22, 2021 15:18
[Change any string in WooCommerce] #woo
add_filter( 'gettext', 'maxpapi_translate_woocommerce_strings', 999, 3 );
function maxpapi_translate_woocommerce_strings( $translated, $untranslated, $domain ) {
if ( ! is_admin() && 'woocommerce' === $domain ) {
switch ( $translated ) {
case 'Weight':
$translated = 'Shipping Weight';
break;
case 'Dimensions':
$translated = 'Shipping Dimensions';
break;
@bagerathan
bagerathan / disable-gateway-for-country.php
Last active August 21, 2021 04:56
[Disable gateway for certain country] #woo
add_filter( 'woocommerce_available_payment_gateways', 'rudr_gateway_by_country' );
function rudr_gateway_by_country( $gateways ) {
if( is_admin() ) {
return $gateways;
}
if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page
@bagerathan
bagerathan / remove-gutenburg-blocks.php
Last active August 21, 2021 04:55
[remove core blocks] #wp #gutenburg
add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
function misha_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
@bagerathan
bagerathan / resources.md
Last active August 23, 2021 07:07
[Internet Resources] Ready to use scripts, cms, tools etc..
@bagerathan
bagerathan / edit-checkout-form.php
Created August 21, 2021 13:37
[Edit checkout form] #woo
//source: https://www.cloudways.com/blog/how-to-edit-delete-fields-and-email-in-woocommerce-custom-checkout-fields/
//remove first name and last name.
function woocommerce_remove_additional_information_checkout($fields){
unset( $fields["billing_first_name"] );
unset( $fields["billing_last_name"] );
return $fields;
}
add_filter( 'woocommerce_billing_fields', 'woocommerce_remove_additional_information_checkout' );
@bagerathan
bagerathan / wp-config.php
Created August 21, 2021 14:24
[wp-config customisations] #wp
//difine default theme
define( 'WP_DEFAULT_THEME', 'default-theme-folder-name' );
//diable autoupdate
define( 'AUTOMATIC_UPDATER_DISABLED', true );
//only disable core updates
define( 'WP_AUTO_UPDATE_CORE', false )
//enable trash for media
@bagerathan
bagerathan / additional-fields-for-media.php
Created August 21, 2021 14:45
[Additional fields for media files] #wp
/**
* Add Photographer Name and URL fields to media uploader
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/
function be_attachment_field_credit( $form_fields, $post ) {
$form_fields['be-photographer-name'] = array(
@bagerathan
bagerathan / disable-create-new-post.php
Created August 22, 2021 03:59
[Disable create new post] #wp
register_post_type( 'custom_post_type_name', array(
'capability_type' => 'post',
'capabilities' => array(
'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for multisite set ups )
),
'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts
));
@bagerathan
bagerathan / update-cart.html
Created August 22, 2021 04:02
[Update cart without button] #woo
<!-- Update woocommerce cart after quantity change without clicking the button -->
<style>
.woocommerce button[name="update_cart"],
.woocommerce input[name="update_cart"] {
display: none;
}
</style>
<script>
@bagerathan
bagerathan / featured-image-in-quick-edit.php
Created August 22, 2021 04:36
[Featured image in quickedit] #wp