Skip to content

Instantly share code, notes, and snippets.

View racmanuel's full-sized avatar
💡
Making new things!

Manuel Ramirez Coronel racmanuel

💡
Making new things!
View GitHub Profile
@racmanuel
racmanuel / archive-product-vendors.php
Last active May 4, 2021 21:47
Custom Loop for Woocommerce Shop only show the products of the author of the store of WCVendors
<?php
/**
* Custom Loop for Woocommerce Shop only show the products of the author of the store of WCVendors
*
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
@racmanuel
racmanuel / archive-product.php
Last active May 4, 2021 21:50
Show different archive-product.php if is a WC Vendor or is a Normal User
<?php
/**
* Show different archive-product.php if is a WC Vendor or is a Normal User
* Put this file in you folder theme or child theme in woocommerce folder
*
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
@racmanuel
racmanuel / functions.php
Last active May 20, 2021 23:25
Shortcode to add a especific product to cart to any place without reload page - Woocommerce
<?php
/* Create a Shorcode for custom_ajax_add_to_cart_button to add a Woocommerce Subscription button add to cart to any place*/
if (!function_exists('custom_ajax_add_to_cart_button') && class_exists('WooCommerce')) {
function custom_ajax_add_to_cart_button($atts)
{
// Shortcode attributes
$atts = shortcode_atts(array(
'id' => '0', // Product ID
'qty' => '1', // Product quantity
'text' => '', // Text of the button
@racmanuel
racmanuel / functions.php
Last active May 20, 2021 23:28
Add a custom tab into the Products Data metabox in Woocommerce - Products
<?php
/** This filter function will add a custom tab to the Products Data metabox */
function add_my_custom_product_data_tab($product_data_tabs)
{
$product_data_tabs['marketplace'] = array(
'label' => __('Name of you custom tab', 'my_custom_text_domain'),
'target' => 'my_custom_product_data',
);
return $product_data_tabs;
}
@racmanuel
racmanuel / functions.php
Last active September 20, 2021 13:16
Add a Button on product pages if is in a category - Wocommerce
<?php
/** Add "Have one to sell?" Button on product pages */
function wc_button_have_one_to_sell()
{
if (has_term('marketplace', 'product_cat')) {
?>
<!-- Here your HTML -->
<div class="card" id="card-have-one-to-sell">
<h4 class="card-heading">
<i class="card-icon icon-cash-dollar"></i>
@racmanuel
racmanuel / functions.php
Last active May 14, 2021 18:49
Get multiple specifics URL in Wordpress and Enqueue a Style
<?php
$urls = array(
'vendor-dashboard',
'vendor-dashboard/product',
'vendor-dashboard/order',
'vendor-dashboard/settings',
'vendor-dashboard/rating',
'vendor-dashboard/wcv_refund_request',
);
@racmanuel
racmanuel / functions.php
Created May 14, 2021 18:51
Get a specific URL and Enqueue a Style in WordPress
<?php
$url = $_SERVER["REQUEST_URI"];
$iscategorymarketplace = strpos($url, 'marketplace');
if ($iscategorymarketplace == true) {
//url contains 'marketplace'
wp_enqueue_style('marketplace_cat', get_stylesheet_directory_uri() . '/assets/css/marketplace-category.css', array(), '1.0', 'all');
}
?>
@racmanuel
racmanuel / functions.php
Last active May 20, 2021 23:00
Show or Hide a Select with jQuery and on load hold the field hide
<?php
/** Function to Show or Hide a field */
function wcv_show_custom_field_time_warranty()
{
?>
<script>
jQuery(function ($) {
if ($('#wcv_custom_product_warranty').val() == 'No') { //'.val()'
$("#wcv_custom_product_time_warranty").hide();
$("label[for='wcv_custom_product_time_warranty']").hide();
@racmanuel
racmanuel / functions.php
Created May 20, 2021 23:06
Create a new tab in the single product page - Woocommerce
<?php
/*Create a new tab in the single product page for the clients view the information*/
function woo_new_product_tab($tabs)
{
// Adds the new tab
$tabs['aditional_information'] = array(
'title' => __('Aditional Information', 'woocommerce'),
'priority' => 10,
'callback' => 'HERE YOUR FUNCTION TO ADD THE DATA FIELDS',
);
@racmanuel
racmanuel / functions.php
Created May 20, 2021 23:14
Enqueue custom styles and scripts in various especific URL in WordPress Theme
<?php
function enqueue_scripts_and_styles(){
//Enqueue custom styles and scripts in various especific URL in WordPress Theme
$urls = array(
'dashboard',
'dashboard/product',
'dashboard/order',
'dashboard/settings',
'dashboard/rating',
'dashboard/refund_request',