Skip to content

Instantly share code, notes, and snippets.

View themepaint's full-sized avatar

Shariful Islam themepaint

View GitHub Profile
@themepaint
themepaint / Woocommerce cart text change
Created January 28, 2018 04:16
Woocommerce cart change by putting the code in functions.php
//archive page or main page
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_product_add_to_cart_text_themepaint' ); // 2.1 +
function woo_custom_product_add_to_cart_text_themepaint() {
return __( 'Buy it on ebay', 'woocommerce' );
}
@themepaint
themepaint / Woocommerce product type detection and cart text change
Created October 7, 2016 20:27
Woocommerce product type detection and cart text change
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_single_add_to_cart_text' );
function custom_single_add_to_cart_text() {
global $product;
if( $product->is_type( 'variable' ) ){
return __( 'HD Download', 'woocommerce' );
}else{
@themepaint
themepaint / Register Custom Taxonomy Woocommerce Products
Created April 22, 2016 11:59
Register Custom Taxonomy Woocommerce Products
// Register Custom Taxonomy
function ess_custom_taxonomy_Item() {
$labels = array(
'name' => 'Brands',
'singular_name' => 'Brand',
'menu_name' => 'Brands',
'all_items' => 'All Brands',
'parent_item' => 'Parent Brand',
'parent_item_colon' => 'Parent Brand:',
@themepaint
themepaint / Create Custome Field in Woocommerce Product Page
Created April 18, 2016 09:05
Create Custome Field in Woocommerce Product Page
<?php
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
@themepaint
themepaint / Change Default shipping methode.
Last active March 30, 2016 16:57
Change Default shipping methode.
/**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
@themepaint
themepaint / Remove WooCommerce purchase button on a category
Created March 28, 2016 09:07
Remove WooCommerce purchase button on a category
function themepaint_custome_add_to_cart(){
if ( ! is_product() ) return;
$product = get_product();
if ( has_term('posters','product_cat',$product ) || themepaint_is_child_of_turm( 'posters','product_cat',$product )) {
/**
* Product Add to cart.
*
* @see woocommerce_template_single_add_to_cart()
@themepaint
themepaint / remove add to cart button from a certain category Woocommerce
Last active April 9, 2022 22:22
remove add to cart button from a certain category Woocommerce
function themepaint_custom_cart_buttons(){
$product = get_product();
if ( has_term( 'posters', 'product_cat') ){
// removing the purchase buttons
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
@themepaint
themepaint / price variation show lowest price in woocommerce
Created March 25, 2016 22:11
price variation show lowest price in woocommerce
function wc_ninja_custom_variable_price( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
@themepaint
themepaint / WooCommerce – Check if product is already in cart
Created February 21, 2016 18:28
WooCommerce – Check if product is already in cart
<?php
/**
* Change the add to cart text on single product pages
*/
add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
function woo_custom_cart_button_text() {
foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
@themepaint
themepaint / Display “ Out of Stock ” on catalog view Woocommerce
Created February 9, 2016 08:14
Display “ Out of Stock ” on catalog view Woocommerce
function wcs_stock_text_shop_page() {
//returns an array with 2 items availability and class for CSS
global $product;
$availability = $product->get_availability();
//check if availability in the array = string 'Out of Stock'
//if so display on page.//if you want to display the 'in stock' messages as well just leave out this, == 'Out of stock'
if ( $availability['availability'] == 'Out of stock') {
echo apply_filters( 'woocommerce_stock_html', '<span class="' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
}