Skip to content

Instantly share code, notes, and snippets.

@vovadocent
vovadocent / woo_product_page_template.php
Created February 10, 2017 09:30
woo product page template
<?php
add_filter('template_include', 'portfolio_page_template', 99);
function portfolio_page_template($template) {
global $post;
if (!is_archive() && $post->post_type == 'product') {
$tpl = get_field('template_name', $post->ID);
if ($tpl) {
$new_template = locate_template(array($tpl));
return $new_template;
@vovadocent
vovadocent / woo_custom_shipping_method.php
Last active December 13, 2023 16:34
Woo Custom Shipping Method
<?php
/**
* Plugin Name: Woo Custom Shipping Method
* Description: Custom Shipping Method for WooCommerce
* Version: 1.0.0
*/
if (!defined('WPINC')) {
die;
}
@vovadocent
vovadocent / woo_custom_payment_gateway.php
Last active February 10, 2022 03:03
Woo Custom Payment Gateway
<?php
/**
* Plugin Name: WooCommerce Custom Payment Gateway
* Version: 1.0.0
**/
class WC_Other_Payment_Gateway extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'other_payment';
@vovadocent
vovadocent / cart_delivery_fee.php
Last active February 22, 2017 13:30
Cart Delivery Fee
<?php
add_action('wp_ajax_myCartDeliveryFee', 'myCartDeliveryFee');
add_action('wp_ajax_nopriv_myCartDeliveryFee', 'myCartDeliveryFee');
function myCartDeliveryFee() {
$fee = isset($_POST['delivery_fee']) && !empty($_POST['delivery_fee']) ? filter_input(INPUT_POST, 'delivery_fee') : 0;
session_start();
$_SESSION['cart_fee_val'] = floatval(str_replace('$', '', $fee));
}
@vovadocent
vovadocent / wp_query_order_by_taxonomy_name.php
Last active March 10, 2017 10:21
WP query order by taxonomy name
<?php
function getTermOrderedIds($post_type, $taxonomy) {
global $wpdb;
$sql = "SELECT p.ID FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (tr.object_id = p.ID)
JOIN $wpdb->term_taxonomy tt ON (tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy = '$taxonomy')
JOIN $wpdb->terms t ON (t.term_id = tt.term_id)
WHERE p.post_status = 'publish' AND post_type = '$post_type' ORDER BY t.name ASC";
$res = $wpdb->get_results($sql);
if ($res) {
@vovadocent
vovadocent / woo_commerce_usefull.php
Last active June 11, 2021 09:07
Woo Commerce Hooks and Tricks
<?php
////// Rename or remove order statuses //////
function wc_renaming_order_status($order_statuses) {
$order_statuses = array(
'wc-pending' => _x('Pending', 'Order status', 'woocommerce'),
'wc-processing' => _x('New Order', 'Order status', 'woocommerce'),
'wc-cancelled' => _x('Cancelled', 'Order status', 'woocommerce'),
'wc-completed' => _x('Approved', 'Order status', 'woocommerce'),
'wc-on-hold' => _x('On Hold', 'Order status', 'woocommerce'),
@vovadocent
vovadocent / send_email_by_wc_mailer.php
Created March 27, 2017 16:51
Send Email By Woocommerce Mailer
<?php
// set subject
$subject = 'WC Send Mail Test';
// load the mailer
$mailer = WC()->mailer();
$mailer->send( get_option( 'admin_email' ), $subject, $mailer->wrap_message( $subject, 'a test message' ), '', '' );
@vovadocent
vovadocent / wc_order_admin_list_custom_field_filter.php
Created March 28, 2017 13:13
Woocommerce order admin list custom field filter
<?php
//// wc order admin list custom field filter ////
function woo_orders_list_custom_filter($query) {
$post_type = !empty($_GET['post_type']) ? filter_input(INPUT_GET, 'post_type') : false;
$lctn = !empty($_GET['lctn']) ? filter_input(INPUT_GET, 'lctn') : false;
if (is_admin() && ($post_type == 'shop_order' && $query->is_main_query() && $lctn > 0)) {
$meta = $query->get('meta_query');
$meta[] = array('key' => 'delivery_name', 'value' => $lctn, 'compare' => '=');
$query->set('meta_query', $meta);
@vovadocent
vovadocent / woo_export_add_custom_fields.php
Created March 30, 2017 12:13
Woo export CSV - add custom fields
<?php
////// woo export add custom fields //////
// add custom column headers
function wc_csv_export_modify_column_headers( $column_headers ) {
$new_headers = array(
'delivery_name' => 'Location',
'odel_date' => 'Date',
);
return array_merge( $column_headers, $new_headers );
}