Skip to content

Instantly share code, notes, and snippets.

@albionselimaj
albionselimaj / functions.php
Last active March 12, 2018 15:03
Change Google Maps language
<?php
add_action( 'wp_enqueue_scripts', function() {
$language = 'zh-CN';
wp_deregister_script( 'c27-google-maps' );
wp_enqueue_script( 'c27-google-maps', 'https://maps.googleapis.com/maps/api/js?key=' . c27()->get_setting( 'general_google_maps_api_key' ) . '&libraries=places&v=3&language=' . $language, [], null, true );
}, 100 );
@albionselimaj
albionselimaj / functions.php
Last active February 10, 2018 12:05
WooCommerce notify admin on user registration
<?php
add_action( 'woocommerce_created_customer', function( $id ) {
wp_new_user_notification( $id, null, 'admin' );
} );
@albionselimaj
albionselimaj / functions.php
Created February 10, 2018 11:55
WooCommerce registration custom fields
<?php
// Add new fields in the registration form
// @link https://www.cloudways.com/blog/add-woocommerce-registration-form-fields/
add_action( 'woocommerce_register_form_start', function() { ?>
<p class="form-row form-row-wide">
<label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?></label>
<input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
</p>
@albionselimaj
albionselimaj / functions.php
Last active February 9, 2018 12:55
WooCommerce remove checkout fields
<?php
add_filter( 'woocommerce_checkout_fields' , function( $fields ) {
// List of all checkout fields
// @link https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
unset($fields['order']['order_comments']);
unset($fields['billing']['billing_company']);
return $fields;
} );
@albionselimaj
albionselimaj / scripts.js
Last active March 1, 2018 15:31
Hide the "Message" field from listing reviews
jQuery(document).ready(function($) {
$('.single-listing #respond textarea[name="comment"]').prop('required', false).val('‌‌ ').hide();
$('.single-listing #respond textarea[name="comment"]').parent().hide();
});
@albionselimaj
albionselimaj / index.php
Created February 5, 2018 01:22
Add global listing type / global search
- Add a new listing type, and set it's "slug" to "global".
- In the Explore page, using Elementor, set this new listing type as the first option in the "Types" tab
- In my-listing/includes/integrations/wp-job-manager/wp-job-manager-queries.php around line 235,
replace this:
```
$args['meta_query'][] = [
'key' => '_case27_listing_type',
'value' => $listing_type,
'compare' => '='
];
@albionselimaj
albionselimaj / functions.php
Created February 4, 2018 21:40
Regex validation rules
<?php
add_filter('submit_job_form_validate_fields', function( $isValid, $fields, $values ) {
foreach ( $fields['job'] as $key => $field ) {
// Example regex validation
if ( $field['slug'] == 'phone' && isset( $values['job']['phone'] ) && preg_match( "/(foo)(bar)/", $values['job']['phone'] ) ) {
return new \WP_Error( 'validation-error', sprintf( __( '%s isn\'t valid', 'my-listing' ), $field['label'] ) );
}
@albionselimaj
albionselimaj / functions.php
Last active November 26, 2018 01:26
Modify page title
<?php
add_filter( 'document_title_parts', function( $title ) {
if ( get_query_var( 'explore_region' ) && ( $term = get_term_by( 'slug', sanitize_title( get_query_var( 'explore_region' ) ), 'region' ) ) ) {
$title['title'] = $term->name;
}
return $title;
}, 99);
@albionselimaj
albionselimaj / functions.php
Created January 30, 2018 16:55
Limit gallery upload to max 3 files
<?php
add_filter( 'submit_job_form_validate_fields', function( $isValid, $fields, $values ) {
$GALLERY_FILE_LIMIT = 5; // Change this to the amount of files you want to allow
$values = $values['job'];
foreach ( $fields['job'] as $key => $field ) {
if ( $field['type'] == 'file' && $field['slug'] == 'job_gallery' && isset( $values[$field['slug']] ) && count( $values[$field['slug']] ) > $GALLERY_FILE_LIMIT ) {
return new WP_Error( 'validation-error', sprintf( __( 'You can\'t upload more than %d files in %s field.', 'my-listing' ), $GALLERY_FILE_LIMIT, $field['label'] ) );
@albionselimaj
albionselimaj / functions.php
Last active January 26, 2018 13:00
Hide Listing Packages products from Shop page
add_action( 'woocommerce_product_query', function( $q ) {
$tax_query = (array) $q->get( 'product_type' );
$tax_query[] = [
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => [ 'job_package', 'job_package_subscription' ],
'operator' => 'NOT IN',
];
$q->set( 'tax_query', $tax_query );